[jboss-svn-commits] JBL Code SVN: r25585 - labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 11 04:56:05 EDT 2009


Author: beve
Date: 2009-03-11 04:56:05 -0400 (Wed, 11 Mar 2009)
New Revision: 25585

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2461 "XMLHelper uses a single instance of SchemaFactory which is not thread safe."


Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	2009-03-11 08:32:58 UTC (rev 25584)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/util/XMLHelper.java	2009-03-11 08:56:05 UTC (rev 25585)
@@ -33,6 +33,7 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -59,10 +60,6 @@
      * The XML output factory.
      */
     private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance() ;
-    /**
-     * The schema factory.
-     */
-    private static final SchemaFactory SCHEMA_FACTORY = SchemaFactory.newInstance( "http://www.w3.org/2001/XMLSchema" );
 
     /**
      * Get the XML stream reader.
@@ -172,10 +169,29 @@
         throws SAXException
     {
         final InputStream resourceIS = ClassUtil.getResourceAsStream(resource, XMLHelper.class) ;
-        return SCHEMA_FACTORY.newSchema(new StreamSource(resourceIS)) ;
+        return newSchemaFactory().newSchema(new StreamSource(resourceIS)) ;
     }
     
     /**
+     * Get the schema for the specified resources.
+     * @param resources The schema resources to parse.
+     * @return The resource schema for validation. 
+     * @throws SAXException For errors during parsing.
+     */
+    public static Schema getSchema(final String[] resources)
+        throws SAXException
+    {
+        final int numResources = (resources == null ? 0 : resources.length) ;
+        final Source[] sources = new Source[numResources] ;
+        for(int count = 0 ; count < numResources ; count++)
+        {
+            final InputStream resourceIS = ClassUtil.getResourceAsStream(resources[count], XMLHelper.class) ;
+            sources[count] = new StreamSource(resourceIS) ;
+        }
+        return newSchemaFactory().newSchema(sources) ;
+    }
+    
+    /**
      * Validate the specified xml against the schema.
      * @param schema The resource schema for validation.
      * @param xml The XML to validate.
@@ -190,11 +206,16 @@
             return true ;
         }
         catch (final IOException ioe) {} // fall through
-        catch (final SAXException saxe) {} // fall through
+        catch (final SAXException saxe)  {} // fall through
         
         return false ;
     }
 
+    private static SchemaFactory newSchemaFactory()
+    {
+        return SchemaFactory.newInstance( "http://www.w3.org/2001/XMLSchema" );
+    }
+
     /**
      * Create the XML input factory.
      * @return The XML input factory.




More information about the jboss-svn-commits mailing list