You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ms...@apache.org on 2007/09/04 03:52:32 UTC

svn commit: r572489 [2/2] - in /ode/branches/bart: axis2-war/src/main/webapp/WEB-INF/ axis2-war/src/main/webapp/WEB-INF/conf/ bpel-compiler/src/ bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/ bpel-compiler/src/test/java/org/apache/ode/bpel/c...

Modified: ode/branches/bart/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java
URL: http://svn.apache.org/viewvc/ode/branches/bart/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java?rev=572489&r1=572488&r2=572489&view=diff
==============================================================================
--- ode/branches/bart/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java (original)
+++ ode/branches/bart/utils/src/main/java/org/apache/ode/utils/xsd/XSUtils.java Mon Sep  3 18:52:29 2007
@@ -42,178 +42,174 @@
  */
 public class XSUtils {
 
-  private static final Log __log = LogFactory.getLog(XSUtils.class);
+    private static final Log __log = LogFactory.getLog(XSUtils.class);
 
-  private static final XsdMessages __msgs = MessageBundle.getMessages(XsdMessages.class);
+    private static final XsdMessages __msgs = MessageBundle.getMessages(XsdMessages.class);
 
-  /**
-   * Recursively "capture" XSD documents starting at the given URI and
-   * using an {@link XMLEntityResolver} to obtain document streams. The
-   * result is a mapping from the XSD URI to a byte array containing the
-   * "captured" document stream.
-   *  
-   * @param initialUri URI of the schema
-   * @param resolver {@link XMLEntityResolver} used to obtain XSD document streams 
-   *
-   * @return mapping between schema URI and the "captured" schema text (in byte form)
-   */
-  public static Map<URI, byte[]> captureSchema(String initialUri, XMLEntityResolver resolver)
-      throws XsdException {
-    DOMInputImpl input = new DOMInputImpl();
-    input.setSystemId(initialUri);
-    return captureSchema(input, resolver);
-  }
-
-  /**
-   * Capture the schemas supplied by the reader.  <code>systemURI</code> is
-   * required to resolve any relative uris encountered during the parse.
-   *
-   * @param systemURI Used to resolve relative uris.
-   * @param schemaData the top level schema.
-   * @param resolver entity resolver
-   *
-   * @return
-   */
-  public static Map<URI, byte[]> captureSchema(URI systemURI, String schemaData,
-      XMLEntityResolver resolver) throws XsdException {
-    
-    if (__log.isDebugEnabled()) 
-      __log.debug("captureSchema(URI,Text,...): systemURI=" + systemURI);
-    
-    DOMInputImpl input = new DOMInputImpl();
-    input.setSystemId(systemURI.toString());
-    input.setStringData(schemaData);
-
-    Map<URI, byte[]> ret = captureSchema(input, resolver);
-    // Let's not forget the root schema.
-    try {
-      // TODO don't assume UTF-8 - but which encoding is required?
-      // either we need another parameter or the entire idea of
-      // passing in a String needs to be revised.
-      ret.put(systemURI, schemaData.getBytes("UTF-8"));
-    } catch (UnsupportedEncodingException uenc) {
-      throw new RuntimeException(uenc);
-    }
-    return ret;
-  }
+    /**
+     * Recursively "capture" XSD documents starting at the given URI and
+     * using an {@link XMLEntityResolver} to obtain document streams. The
+     * result is a mapping from the XSD URI to a byte array containing the
+     * "captured" document stream.
+     *
+     * @param initialUri URI of the schema
+     * @param resolver {@link XMLEntityResolver} used to obtain XSD document streams
+     *
+     * @return mapping between schema URI and the "captured" schema text (in byte form)
+     */
+    public static Map<URI, byte[]> captureSchema(String initialUri, XMLEntityResolver resolver)
+            throws XsdException {
+        DOMInputImpl input = new DOMInputImpl();
+        input.setSystemId(initialUri);
+        Map<URI, byte[]> ret = captureSchema(input, resolver);
 
-  private static Map<URI, byte[]> captureSchema(LSInput input, XMLEntityResolver resolver)
-      throws XsdException {
-    
-    if (__log.isDebugEnabled()) 
-      __log.debug("captureSchema(LSInput,...): input.systemId=" + input.getSystemId());
-    
-    Map<URI, byte[]> captured = new HashMap<URI, byte[]>();
+        return ret;
+    }
 
-    if (resolver == null) {
-      resolver = new DefaultXMLEntityResolver();
+    /**
+     * Capture the schemas supplied by the reader.  <code>systemURI</code> is
+     * required to resolve any relative uris encountered during the parse.
+     *
+     * @param systemURI Used to resolve relative uris.
+     * @param schemaData the top level schema.
+     * @param resolver entity resolver
+     *
+     * @return
+     */
+    public static Map<URI, byte[]> captureSchema(URI systemURI, String schemaData,
+                                                 XMLEntityResolver resolver) throws XsdException {
+        if (__log.isDebugEnabled())
+            __log.debug("captureSchema(URI,Text,...): systemURI=" + systemURI);
+
+        DOMInputImpl input = new DOMInputImpl();
+        input.setSystemId(systemURI.toString());
+        input.setStringData(schemaData);
+
+        Map<URI, byte[]> ret = captureSchema(input, resolver);
+        // Let's not forget the root schema.
+        try {
+            // TODO don't assume UTF-8 - but which encoding is required?
+            // either we need another parameter or the entire idea of
+            // passing in a String needs to be revised.
+            ret.put(systemURI, schemaData.getBytes("UTF-8"));
+        } catch (UnsupportedEncodingException uenc) {
+            throw new RuntimeException(uenc);
+        }
+        return ret;
     }
 
-    CapturingXMLEntityResolver cr = new CapturingXMLEntityResolver(captured, resolver);
+    private static Map<URI, byte[]> captureSchema(LSInput input, XMLEntityResolver resolver)
+            throws XsdException {
+        if (__log.isDebugEnabled())
+            __log.debug("captureSchema(LSInput,...): input.systemId=" + input.getSystemId());
 
-    XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
-    schemaLoader.setEntityResolver(cr);
+        Map<URI, byte[]> captured = new HashMap<URI, byte[]>();
 
-    LoggingXmlErrorHandler eh = new LoggingXmlErrorHandler(__log);
-    schemaLoader.setErrorHandler(eh);
+        if (resolver == null) {
+            resolver = new DefaultXMLEntityResolver();
+        }
 
-    XSModel model = schemaLoader.load(input);
-
-    // The following mess is due to XMLSchemaLoaders funkyness in error
-    // reporting: sometimes it throws an exception, sometime it returns
-    // null, sometimes it just prints bs to the screen.
-    if (model == null) {
-      /*
-       * Someone inside Xerces will have eaten this exception, for no good
-       * reason.
-       */
-      List<XMLParseException> errors = eh.getErrors();
-      if (errors.size() != 0) {
-        if (__log.isDebugEnabled()) 
-          __log.debug("captureSchema: XMLParseException(s) in " + input);
-        
-        XsdException ex = null;
-        for (XMLParseException xpe : errors) {
-          ex = new XsdException(ex, xpe.getMessage(), xpe.getLineNumber(), xpe.getColumnNumber(),
-              xpe.getLiteralSystemId());
-        }
-        assert ex != null;
-        throw ex;
-      }
-      
-      if (__log.isDebugEnabled())
-        __log.debug("captureSchema: NULL model (unknown error) for " + input.getSystemId());
-      
-      throw new XsdException(null, __msgs.msgXsdUnknownError(input.getSystemId()), 0, 0, input.getSystemId());
-    }
+        CapturingXMLEntityResolver cr = new CapturingXMLEntityResolver(captured, resolver);
 
-    return captured;
-  }
+        XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
+        schemaLoader.setEntityResolver(cr);
 
-  /**
-   * Implementation of {@link LoggingXmlErrorHandler} that outputs messages to
-   * a log.
-   */
-  static class LoggingXmlErrorHandler implements XMLErrorHandler {
+        LoggingXmlErrorHandler eh = new LoggingXmlErrorHandler(__log);
+        schemaLoader.setErrorHandler(eh);
 
-    private Log _log;
+        XSModel model = schemaLoader.load(input);
+
+        // The following mess is due to XMLSchemaLoaders funkyness in error
+        // reporting: sometimes it throws an exception, sometime it returns
+        // null, sometimes it just prints bs to the screen.
+        if (model == null) {
+            /*
+            * Someone inside Xerces will have eaten this exception, for no good
+            * reason.
+            */
+            List<XMLParseException> errors = eh.getErrors();
+            if (errors.size() != 0) {
+                __log.error("captureSchema: XMLParseException(s) in " + input);
+
+                XsdException ex = null;
+                for (XMLParseException xpe : errors) {
+                    ex = new XsdException(ex, xpe.getMessage(), xpe.getLineNumber(), xpe.getColumnNumber(),
+                            xpe.getLiteralSystemId());
+                }
+                throw ex;
+            }
 
-    private ArrayList<XMLParseException> _errors = new ArrayList<XMLParseException>();
+            if (__log.isDebugEnabled())
+                __log.debug("captureSchema: NULL model (unknown error) for " + input.getSystemId());
+        }
 
-    /**
-     * Create a new instance that will output to the specified {@link Log}
-     * instance.
-     * @param log the target log, which much be non-<code>null</code>
-     */
-    public LoggingXmlErrorHandler(Log log) {
-      assert log != null;
-      _log = log;
+        return captured;
     }
 
-    public List<XMLParseException> getErrors() {
-      return _errors;
-    }
-    
     /**
-     * @see XMLErrorHandler#warning(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
+     * Implementation of {@link LoggingXmlErrorHandler} that outputs messages to
+     * a log.
      */
-    public void warning(String domain, String key, XMLParseException ex) throws XNIException {
-      if (_log.isDebugEnabled())
-        _log.debug("XSDErrorHandler.warning: domain=" + domain + ", key=" + key,ex);
-      
-      if (ex != null) {
-        _errors.add(ex);
-        throw ex;
-      }
-    }
+    static class LoggingXmlErrorHandler implements XMLErrorHandler {
 
-    /**
-     * @see org.apache.xerces.xni.parser.XMLErrorHandler#error(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
-     */
-    public void error(String domain, String key, XMLParseException ex) throws XNIException {
-      if (_log.isDebugEnabled())
-        _log.debug("XSDErrorHandler.error: domain=" + domain + ", key=" + key,ex);
-
-      if (ex != null) {
-        _errors.add(ex);
-        throw ex;
-      }
+        private Log _log;
 
-      // Should not reach here, but just in case...
-      throw new XNIException("Unknown XSD error state; domain=" + domain + ", key=" +key);
-    }
+        private ArrayList<XMLParseException> _errors = new ArrayList<XMLParseException>();
+
+        /**
+         * Create a new instance that will output to the specified {@link Log}
+         * instance.
+         * @param log the target log, which much be non-<code>null</code>
+         */
+        public LoggingXmlErrorHandler(Log log) {
+            assert log != null;
+            _log = log;
+        }
+
+        public List<XMLParseException> getErrors() {
+            return _errors;
+        }
+
+        /**
+         * @see XMLErrorHandler#warning(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
+         */
+        public void warning(String domain, String key, XMLParseException ex) throws XNIException {
+            if (_log.isDebugEnabled())
+                _log.debug("XSDErrorHandler.warning: domain=" + domain + ", key=" + key,ex);
+
+            if (ex != null) {
+                _errors.add(ex);
+                throw ex;
+            }
+        }
+
+        /**
+         * @see org.apache.xerces.xni.parser.XMLErrorHandler#error(java.lang.String, java.lang.String, org.apache.xerces.xni.parser.XMLParseException)
+         */
+        public void error(String domain, String key, XMLParseException ex) throws XNIException {
+            if (_log.isDebugEnabled())
+                _log.debug("XSDErrorHandler.error: domain=" + domain + ", key=" + key,ex);
+
+            if (ex != null) {
+                _errors.add(ex);
+                throw ex;
+            }
+
+            // Should not reach here, but just in case...
+            throw new XNIException("Unknown XSD error state; domain=" + domain + ", key=" +key);
+        }
 
-    public void fatalError(String domain, String key, XMLParseException ex) throws XNIException {
-      if (_log.isDebugEnabled())
-        _log.debug("XSDErrorHandler.fatal: domain=" + domain + ", key=" + key,ex);
-
-      if (ex != null) {
-        _errors.add(ex);
-        throw ex;
-      }
-
-      // Should not reach here, but just in case...
-      throw new XNIException("Unknown XSD error state; domain=" + domain + ", key=" +key);
-    } 
-  }
+        public void fatalError(String domain, String key, XMLParseException ex) throws XNIException {
+            if (_log.isDebugEnabled())
+                _log.debug("XSDErrorHandler.fatal: domain=" + domain + ", key=" + key,ex);
+
+            if (ex != null) {
+                _errors.add(ex);
+                throw ex;
+            }
+
+            // Should not reach here, but just in case...
+            throw new XNIException("Unknown XSD error state; domain=" + domain + ", key=" +key);
+        }
+    }
 }

Modified: ode/branches/bart/utils/src/test/java/org/apache/ode/utils/TestResources.java
URL: http://svn.apache.org/viewvc/ode/branches/bart/utils/src/test/java/org/apache/ode/utils/TestResources.java?rev=572489&r1=572488&r2=572489&view=diff
==============================================================================
--- ode/branches/bart/utils/src/test/java/org/apache/ode/utils/TestResources.java (original)
+++ ode/branches/bart/utils/src/test/java/org/apache/ode/utils/TestResources.java Mon Sep  3 18:52:29 2007
@@ -28,7 +28,7 @@
 
     public static URL getResource(String s) {
         URL url = TestResources.class.getResource(s);
-        if (url == null) url = ClassLoader.getSystemClassLoader().getResource(s);
+        if (url == null) url = TestResources.class.getResource("/" + s);
         return url;
     }