aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r896771 - in /incubator/aries/trunk/jpa/jpa-container/src: main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
Date Thu, 07 Jan 2010 07:44:08 GMT
Author: timothyjward
Date: Thu Jan  7 07:44:06 2010
New Revision: 896771

URL: http://svn.apache.org/viewvc?rev=896771&view=rev
Log:
ARIES-80: Create a parser for persistence descriptors

Modified:
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
    incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java?rev=896771&r1=896770&r2=896771&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
Thu Jan  7 07:44:06 2010
@@ -55,52 +55,49 @@
    * @param args
    * @throws PersistenceDescriptorParserException 
    */
-  public static Collection<ParsedPersistenceUnit> parse(Bundle b, Collection<PersistenceDescriptor>
descriptors) throws PersistenceDescriptorParserException {
+  public static Collection<ParsedPersistenceUnit> parse(Bundle b, PersistenceDescriptor
descriptor) throws PersistenceDescriptorParserException {
     Collection<ParsedPersistenceUnit> persistenceUnits = new ArrayList<ParsedPersistenceUnit>();
     //Parse each xml file in turn
-    for(PersistenceDescriptor descriptor : descriptors) {
-      SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-      BufferedInputStream is = null;
-      try {
-        //Buffer the InputStream so we can mark it
-        is = new BufferedInputStream(descriptor.getInputStream(), 8192);
-        is.mark(8192);
-        SAXParser parser = parserFactory.newSAXParser();
-        try{
-          parser.parse(new UnclosableInputStream(is), new SchemaLocatingHandler());
-        } catch (EarlyParserReturn epr) {
-          //This is not really an exception, but a way to work out which
-          //version of the persistence schema to use in validation
-          Schema s = epr.getSchema();
+    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+    BufferedInputStream is = null;
+    try {
+      //Buffer the InputStream so we can mark it
+      is = new BufferedInputStream(descriptor.getInputStream(), 8192);
+      is.mark(8192);
+      SAXParser parser = parserFactory.newSAXParser();
+      try{
+        parser.parse(new UnclosableInputStream(is), new SchemaLocatingHandler());
+      } catch (EarlyParserReturn epr) {
+        //This is not really an exception, but a way to work out which
+        //version of the persistence schema to use in validation
+        Schema s = epr.getSchema();
+        
+        if(s != null) {
+          parserFactory.setSchema(s);
+          parserFactory.setNamespaceAware(true);
+          parser = parserFactory.newSAXParser();
+         
+          //Get back to the beginning of the stream
+          is.reset();
           
-          if(s != null) {
-            parserFactory.setSchema(s);
-            parserFactory.setNamespaceAware(true);
-            parser = parserFactory.newSAXParser();
-           
-            //Get back to the beginning of the stream
-            is.reset();
-            
-            JPAHandler handler = new JPAHandler(b, epr.getVersion());
-            parser.parse(is, handler);
-            persistenceUnits.addAll(handler.getPersistenceUnits());
-          } else {
-            //TODO Should we try without validation?
-          }
-            
+          JPAHandler handler = new JPAHandler(b, epr.getVersion());
+          parser.parse(is, handler);
+          persistenceUnits.addAll(handler.getPersistenceUnits());
+        } else {
+          //TODO Should we try without validation?
         }
-      } catch (Exception e) {
-        //TODO Log this error in parsing
-        System.out.println("Error parsing " + descriptor.getLocation() + " in bundle " +
b.getSymbolicName() + "_" + b.getVersion());
+      }
+    } catch (Exception e) {
+      //TODO Log this error in parsing
+      System.out.println("Error parsing " + descriptor.getLocation() + " in bundle " + b.getSymbolicName()
+ "_" + b.getVersion());
+      e.printStackTrace();
+      throw new PersistenceDescriptorParserException(e);
+    } finally {
+      if(is != null) try {
+        is.close();
+      } catch (IOException e) {
+        //TODO Log this
         e.printStackTrace();
-        throw new PersistenceDescriptorParserException(e);
-      } finally {
-        if(is != null) try {
-          is.close();
-        } catch (IOException e) {
-          //TODO Log this
-          e.printStackTrace();
-        }
       }
     }
     return persistenceUnits;

Modified: incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java?rev=896771&r1=896770&r2=896771&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
Thu Jan  7 07:44:06 2010
@@ -56,12 +56,9 @@
       is = new FileInputStream(location);
       PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
       
-      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
-      descriptors.add(descriptor);
-      
       Bundle b = Skeleton.newMock(Bundle.class);
       
-      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptor);
       assertEquals("An incorrect number of persistence units has been returned.", 4, parsedUnits.size());
       
       List<ParsedPersistenceUnit> units = getList(parsedUnits);
@@ -208,13 +205,10 @@
       String location = "src/test/resources/file2/META-INF/persistence.xml";
       is = new FileInputStream(location);
       PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
-      
-      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
-      descriptors.add(descriptor);
-      
+
       Bundle b = Skeleton.newMock(Bundle.class);
       
-      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptor);
       assertEquals("An incorrect number of persistence units has been returned.", 0, parsedUnits.size());
     } finally {
       if(is != null)
@@ -232,12 +226,9 @@
       is = new FileInputStream(location);
       PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
       
-      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
-      descriptors.add(descriptor);
-      
       Bundle b = Skeleton.newMock(Bundle.class);
       
-      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptor);
 
       fail("Parsing should not succeed");
     } finally {



Mime
View raw message