You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/12/17 20:42:39 UTC

svn commit: r891860 - in /cxf/branches/2.2.x-fixes: ./ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java

Author: dkulp
Date: Thu Dec 17 19:42:38 2009
New Revision: 891860

URL: http://svn.apache.org/viewvc?rev=891860&view=rev
Log:
Merged revisions 891859 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r891859 | dkulp | 2009-12-17 14:39:49 -0500 (Thu, 17 Dec 2009) | 2 lines
  
  [CXF-2296] Add some extra checks around the parser creation/schema
  creation for the aegis files and INFO any issues, but continue.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 17 19:42:38 2009
@@ -1 +1 @@
-/cxf/trunk:891375-891393,891452,891817,891827
+/cxf/trunk:891375-891393,891452,891817,891827,891859

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java?rev=891860&r1=891859&r2=891860&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java (original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java Thu Dec 17 19:42:38 2009
@@ -36,7 +36,6 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -106,32 +105,28 @@
         stopClasses.add(Throwable.class);
     }
 
-    private static DocumentBuilderFactory aegisDocumentBuilderFactory;
-    private static Schema aegisSchema;
+    private static final DocumentBuilderFactory AEGIS_DOCUMENT_BUILDER_FACTORY;
     // cache of classes to documents
     private Map<String, Document> documents = new HashMap<String, Document>();
     static {
+        AEGIS_DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
+        AEGIS_DOCUMENT_BUILDER_FACTORY.setNamespaceAware(true);
+        
         String path = "/META-INF/cxf/aegis.xsd";
         InputStream is = XMLTypeCreator.class.getResourceAsStream(path);
         if (is != null) {
+            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
             try {
-                aegisDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
-                aegisDocumentBuilderFactory.setNamespaceAware(true);
-                
-                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-                aegisSchema = schemaFactory.newSchema(new StreamSource(is));
-                is.close();
-                
-                aegisDocumentBuilderFactory.setSchema(aegisSchema);
-            } catch (UnsupportedOperationException e) {
-                //Parsers that don't support schema validation
-                LOG.log(Level.INFO, "Parser doesn't support setSchema.  Not validating.", e);
-            } catch (IOException ie) {
-                LOG.log(Level.SEVERE, "Error reading Aegis schema", ie);
-            } catch (FactoryConfigurationError e) {
-                LOG.log(Level.SEVERE, "Error reading Aegis schema", e);
-            } catch (SAXException e) {
-                LOG.log(Level.SEVERE, "Error reading Aegis schema", e);
+                Schema aegisSchema = schemaFactory.newSchema(new StreamSource(is));
+                AEGIS_DOCUMENT_BUILDER_FACTORY.setSchema(aegisSchema);
+            } catch (Throwable e) {
+                LOG.log(Level.INFO, "Could not set aegis schema.  Not validating.", e);
+            } finally {
+                try {
+                    is.close();
+                } catch (IOException ex) {
+                    //ignore
+                }
             }
         }
     }
@@ -141,7 +136,7 @@
     private Document readAegisFile(InputStream is, final String path) throws IOException {
         DocumentBuilder documentBuilder;
         try {
-            documentBuilder = aegisDocumentBuilderFactory.newDocumentBuilder();
+            documentBuilder = AEGIS_DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
         } catch (ParserConfigurationException e) {
             LOG.log(Level.SEVERE, "Unable to create a document builder, e");
             throw new RuntimeException("Unable to create a document builder, e");