You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2006/10/20 00:15:03 UTC

svn commit: r465910 - in /incubator/ode/trunk: bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/ bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/ utils/src/main/java/org/apache/ode/utils/xsd/

Author: mriou
Date: Thu Oct 19 15:14:58 2006
New Revision: 465910

URL: http://svn.apache.org/viewvc?view=rev&rev=465910
Log:
ODE-70 Made the resolver a bit smarter so that already processed schemas defined in the WSDL are known to it. Note that this is only used at compile time anyway as the runtime doesn't use types (and the compiler only loads them to see whether we're referencing simple types or complex types).

Modified:
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java
    incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/DocumentRegistry.java
    incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/SchemaModelImpl.java

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java?view=diff&rev=465910&r1=465909&r2=465910
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java Thu Oct 19 15:14:58 2006
@@ -27,11 +27,14 @@
 import org.apache.ode.utils.xsd.XSUtils;
 import org.apache.ode.utils.xsd.XsdException;
 import org.apache.ode.utils.fs.FileUtils;
+import org.apache.ode.utils.DOMUtils;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
 
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.*;
+import java.io.StringReader;
+import java.io.IOException;
 
 import javax.wsdl.*;
 import javax.wsdl.extensions.ExtensibilityElement;
@@ -39,6 +42,9 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.w3c.dom.Document;
 
 
 /**
@@ -56,7 +62,7 @@
 
     private SchemaModel _model;
 
-    private XMLEntityResolver _resolver;
+    private WsdlFinderXMLEntityResolver _resolver;
     private CompilerContext _ctx;
 
 
@@ -204,6 +210,14 @@
                         // Add new schemas to our list.
                         _schemas.putAll(capture);
 
+                        try {
+                            Document doc = DOMUtils.parse(new InputSource(new StringReader(schema)));
+                            String schemaTargetNS = doc.getDocumentElement().getAttribute("targetNamespace");
+                            if (schemaTargetNS != null && schemaTargetNS.length() > 0)
+                                _resolver.addInternalResource(schemaTargetNS, schema);
+                        } catch (Exception e) {
+                            throw new RuntimeException("Couldn't parse schema in " + def.getTargetNamespace(), e);
+                        }
                     } catch (XsdException xsde) {
                         __log.debug("captureSchemas: capture failed for " + docuri,xsde);
 

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java?view=diff&rev=465910&r1=465909&r2=465910
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java Thu Oct 19 15:14:58 2006
@@ -19,8 +19,12 @@
 package org.apache.ode.bpel.compiler;
 
 import java.io.IOException;
+import java.io.StringReader;
+import java.io.InputStreamReader;
+import java.io.ByteArrayInputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.HashMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -45,6 +49,7 @@
     private boolean _failIfNotFound = true;
 
     private WsdlFinder _wsdlFinder;
+    private HashMap<String,String> _internalResources = new HashMap<String, String>();
 
     public WsdlFinderXMLEntityResolver(WsdlFinder finder) {
         _wsdlFinder = finder;
@@ -73,10 +78,15 @@
             __log.debug("resolveEntity: Expecting to find " + resourceIdentifier.getNamespace()
                     + " at " + location);
 
+        if (_internalResources.get(location.toString()) != null) {
+            src.setByteStream(new ByteArrayInputStream(_internalResources.get(location.toString()).getBytes()));
+            return src;
+        }
+
         try {
             src.setByteStream(_wsdlFinder.openResource(location));
         } catch (IOException ioex) {
-            __log.debug("resolveEntity: IOExcepption opening " + location,ioex);
+            __log.debug("resolveEntity: IOException opening " + location,ioex);
 
             if (_failIfNotFound) {
                 __log.debug("resolveEntity: failIfNotFound set, rethrowing...");
@@ -88,6 +98,10 @@
         }
 
         return src;
+    }
+
+    public void addInternalResource(String ns, String source) {
+        _internalResources.put(ns, source);
     }
 
 }

Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/DocumentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/DocumentRegistry.java?view=diff&rev=465910&r1=465909&r2=465910
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/DocumentRegistry.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/deploy/DocumentRegistry.java Thu Oct 19 15:14:58 2006
@@ -89,22 +89,6 @@
         return _definitions.toArray(new Definition4BPEL[_definitions.size()]);
     }
 
-
-    /**
-     * Get the schema model (XML Schema).
-     *
-     * @return schema model
-     */
-    public SchemaModel getSchemaModel() {
-        if (_model == null) {
-            _model = SchemaModelImpl.newModel(_schemas);
-        }
-
-        assert _model != null;
-
-        return _model;
-    }
-
     /**
      * Adds a WSDL definition for use in resolving MessageType, PortType,
      * Operation and BPEL properties and property aliases
@@ -121,59 +105,9 @@
 
         _definitions.add(def);
 
-        captureSchemas(def);
-    }
-
-    @SuppressWarnings("unchecked")
-    private void captureSchemas(Definition def) throws CompilationException {
-        assert def != null;
-
-        if (__log.isDebugEnabled())
-            __log.debug("Processing XSD schemas in " + def.getDocumentBaseURI());
-
-        Types types = def.getTypes();
-
-        if (types != null) {
-            for (ExtensibilityElement ee : ((List<ExtensibilityElement>) def.getTypes().getExtensibilityElements())) {
-                if (ee instanceof XMLSchemaType) {
-                    String schema = ((XMLSchemaType) ee).getXMLSchema();
-                    Map<URI, byte[]> capture;
-                    URI docuri;
-                    try {
-                        docuri = new URI(def.getDocumentBaseURI());
-                    } catch (URISyntaxException e) {
-                        // This is really quite unexpected..
-                        __log.fatal("Internal Error: WSDL Base URI is invalid.", e);
-                        throw new RuntimeException(e);
-                    }
-
-                    try {
-                        capture = XSUtils.captureSchema(docuri, schema, _resolver);
-
-                        // Add new schemas to our list.
-                        _schemas.putAll(capture);
-                    } catch (XsdException xsde) {
-                        System.out.println("+++++++++++++++++++++++++++++++++");
-                        xsde.printStackTrace();
-                        System.out.println("+++++++++++++++++++++++++++++++++");
-                        __log.debug("captureSchemas: capture failed for " + docuri, xsde);
-
-                        LinkedList<XsdException> exceptions = new LinkedList<XsdException>();
-                        while (xsde != null) {
-                            exceptions.addFirst(xsde);
-                            xsde = xsde.getPrevious();
-                        }
-
-                        if (exceptions.size() > 0) {
-                            throw new BpelEngineException(
-                                    __msgs.errSchemaError(exceptions.get(0).getDetailMessage()));
-                        }
-                    }
-                    // invalidate model
-                    _model = null;
-                }
-            }
-        }
+        // For now the schemas are never used at runtime. Check the compiler if this needs to be
+        // put back in.
+//        captureSchemas(def);
     }
 
 }

Modified: incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/SchemaModelImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/SchemaModelImpl.java?view=diff&rev=465910&r1=465909&r2=465910
==============================================================================
--- incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/SchemaModelImpl.java (original)
+++ incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/SchemaModelImpl.java Thu Oct 19 15:14:58 2006
@@ -23,11 +23,17 @@
 import com.sun.org.apache.xerces.internal.xs.LSInputList;
 import com.sun.org.apache.xerces.internal.xs.XSModel;
 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
+import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
+import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
+import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
+import com.sun.org.apache.xerces.internal.xni.XNIException;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.net.URI;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.HashMap;
 
 import javax.xml.namespace.QName;
 
@@ -37,119 +43,141 @@
  * Xerces based schema model.
  */
 public class SchemaModelImpl implements SchemaModel {
-  private XSModel _model;
+    private XSModel _model;
 
-  private SchemaModelImpl(XSModel model) {
-    if (model == null) {
-      throw new NullPointerException("Null model.");
-    }
-
-    _model = model;
-  }
-
-  /**
-   * Generate a schema model from a collection of schemas.
-   * @param schemas collection of schemas (indexed by systemId)
-   *
-   * @return a {@link SchemaModel}
-   */
-  public static final SchemaModel newModel(Map<URI, byte[]> schemas) {
-    XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
-
-    final String[] uris = new String[schemas.size()];
-    final byte[][] content = new byte[schemas.size()][];
-
-    int idx = 0;
-    for (Iterator<Map.Entry<URI,byte[]>> i = schemas.entrySet().iterator();i.hasNext();) {
-      Map.Entry<URI, byte[]> me = i.next();
-      uris[idx] = me.getKey().toASCIIString();
-      content[idx] = me.getValue();
-      ++idx;
-    }
-
-    LSInputList list = new LSInputList() {
-      public LSInput item(int index) {
-        DOMInputImpl input = new DOMInputImpl();
-        input.setSystemId(uris[index]);
-        input.setByteStream(new ByteArrayInputStream(content[index]));
-        return input;
-      }
-
-      public int getLength() {
-        return uris.length;
-      }
-    };
-
-    return new SchemaModelImpl(schemaLoader.loadInputList(list));
-  }
-
-  /**
-   * @see org.apache.ode.utils.xsd.SchemaModel#isCompatible(javax.xml.namespace.QName,
-   *      javax.xml.namespace.QName)
-   */
-  public boolean isCompatible(QName type1, QName type2) {
-    XSTypeDefinition typeDef1;
-    XSTypeDefinition typeDef2;
-
-    if (knowsElementType(type1)) {
-      typeDef1 = _model.getElementDeclaration(type1.getLocalPart(),
-                                              type1.getNamespaceURI())
-                       .getTypeDefinition();
-    } else if (knowsSchemaType(type1)) {
-      typeDef1 = _model.getTypeDefinition(type1.getLocalPart(),
-                                          type1.getNamespaceURI());
-    } else {
-      throw new IllegalArgumentException("unknown schema type: " + type1);
-    }
-
-    if (knowsElementType(type2)) {
-      typeDef2 = _model.getElementDeclaration(type2.getLocalPart(),
-                                              type2.getNamespaceURI())
-                       .getTypeDefinition();
-    } else if (knowsSchemaType(type2)) {
-      typeDef2 = _model.getTypeDefinition(type2.getLocalPart(),
-                                          type2.getNamespaceURI());
-    } else {
-      throw new IllegalArgumentException("unknown schema type: " + type2);
-    }
-
-    return typeDef1.derivedFromType(typeDef2, (short)0)
-           || typeDef2.derivedFromType(typeDef1, (short)0);
-  }
-
-  /**
-   * @see org.apache.ode.utils.xsd.SchemaModel#isSimpleType(javax.xml.namespace.QName)
-   */
-  public boolean isSimpleType(QName type) {
-    if (type == null)
-      throw new NullPointerException("Null type argument!");
-
-    XSTypeDefinition typeDef = _model.getTypeDefinition(type.getLocalPart(),
-                                                        type.getNamespaceURI());
-
-    return (typeDef != null)
-           && (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE);
-  }
-
-  /**
-   * @see org.apache.ode.utils.xsd.SchemaModel#knowsElementType(javax.xml.namespace.QName)
-   */
-  public boolean knowsElementType(QName elementType) {
-    if (elementType == null)
-      throw new NullPointerException("Null type argument!");
-
-    return _model.getElementDeclaration(elementType.getLocalPart(),
-                                        elementType.getNamespaceURI()) != null;
-  }
-
-  /**
-   * @see org.apache.ode.utils.xsd.SchemaModel#knowsSchemaType(javax.xml.namespace.QName)
-   */
-  public boolean knowsSchemaType(QName schemaType) {
-    if (schemaType == null)
-      throw new NullPointerException("Null type argument!");
-
-    return _model.getTypeDefinition(schemaType.getLocalPart(),
-                                    schemaType.getNamespaceURI()) != null;
-  }
+    private SchemaModelImpl(XSModel model) {
+        if (model == null) {
+            throw new NullPointerException("Null model.");
+        }
+
+        _model = model;
+    }
+
+    /**
+     * Generate a schema model from a collection of schemas.
+     * @param schemas collection of schemas (indexed by systemId)
+     *
+     * @return a {@link SchemaModel}
+     */
+    public static final SchemaModel newModel(Map<URI, byte[]> schemas) {
+        XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
+        InternalSchemaResolver resolver = new InternalSchemaResolver();
+//        schemaLoader.setEntityResolver(resolver);
+
+        final String[] uris = new String[schemas.size()];
+        final byte[][] content = new byte[schemas.size()][];
+
+        int idx = 0;
+        for (Iterator<Map.Entry<URI,byte[]>> i = schemas.entrySet().iterator();i.hasNext();) {
+            Map.Entry<URI, byte[]> me = i.next();
+            uris[idx] = me.getKey().toASCIIString();
+            content[idx] = me.getValue();
+            resolver.put(me.getKey(), me.getValue());
+            ++idx;
+        }
+
+        LSInputList list = new LSInputList() {
+            public LSInput item(int index) {
+                DOMInputImpl input = new DOMInputImpl();
+                input.setSystemId(uris[index]);
+                input.setByteStream(new ByteArrayInputStream(content[index]));
+                return input;
+            }
+
+            public int getLength() {
+                return uris.length;
+            }
+        };
+
+        return new SchemaModelImpl(schemaLoader.loadInputList(list));
+    }
+
+    /**
+     * @see org.apache.ode.utils.xsd.SchemaModel#isCompatible(javax.xml.namespace.QName,
+     *      javax.xml.namespace.QName)
+     */
+    public boolean isCompatible(QName type1, QName type2) {
+        XSTypeDefinition typeDef1;
+        XSTypeDefinition typeDef2;
+
+        if (knowsElementType(type1)) {
+            typeDef1 = _model.getElementDeclaration(type1.getLocalPart(),
+                    type1.getNamespaceURI())
+                    .getTypeDefinition();
+        } else if (knowsSchemaType(type1)) {
+            typeDef1 = _model.getTypeDefinition(type1.getLocalPart(),
+                    type1.getNamespaceURI());
+        } else {
+            throw new IllegalArgumentException("unknown schema type: " + type1);
+        }
+
+        if (knowsElementType(type2)) {
+            typeDef2 = _model.getElementDeclaration(type2.getLocalPart(),
+                    type2.getNamespaceURI())
+                    .getTypeDefinition();
+        } else if (knowsSchemaType(type2)) {
+            typeDef2 = _model.getTypeDefinition(type2.getLocalPart(),
+                    type2.getNamespaceURI());
+        } else {
+            throw new IllegalArgumentException("unknown schema type: " + type2);
+        }
+
+        return typeDef1.derivedFromType(typeDef2, (short)0)
+                || typeDef2.derivedFromType(typeDef1, (short)0);
+    }
+
+    /**
+     * @see org.apache.ode.utils.xsd.SchemaModel#isSimpleType(javax.xml.namespace.QName)
+     */
+    public boolean isSimpleType(QName type) {
+        if (type == null)
+            throw new NullPointerException("Null type argument!");
+
+        XSTypeDefinition typeDef = _model.getTypeDefinition(type.getLocalPart(),
+                type.getNamespaceURI());
+
+        return (typeDef != null)
+                && (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE);
+    }
+
+    /**
+     * @see org.apache.ode.utils.xsd.SchemaModel#knowsElementType(javax.xml.namespace.QName)
+     */
+    public boolean knowsElementType(QName elementType) {
+        if (elementType == null)
+            throw new NullPointerException("Null type argument!");
+
+        return _model.getElementDeclaration(elementType.getLocalPart(),
+                elementType.getNamespaceURI()) != null;
+    }
+
+    /**
+     * @see org.apache.ode.utils.xsd.SchemaModel#knowsSchemaType(javax.xml.namespace.QName)
+     */
+    public boolean knowsSchemaType(QName schemaType) {
+        if (schemaType == null)
+            throw new NullPointerException("Null type argument!");
+
+        return _model.getTypeDefinition(schemaType.getLocalPart(),
+                schemaType.getNamespaceURI()) != null;
+    }
+
+
+    public static class InternalSchemaResolver implements XMLEntityResolver {
+        private Map<String, byte[]> _schemas = new HashMap<String, byte[]>();
+        public void put(URI uri, byte[] bytes) {
+            _schemas.put(uri.toASCIIString(), bytes);
+        }
+        public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
+            XMLInputSource src = new XMLInputSource(resourceIdentifier);
+            String location = "";
+            if (resourceIdentifier.getNamespace() != null && _schemas.get(resourceIdentifier.getNamespace()) != null)
+                location = resourceIdentifier.getNamespace();
+            else if (resourceIdentifier.getBaseSystemId() != null && _schemas.get(resourceIdentifier.getBaseSystemId()) != null)
+                location = resourceIdentifier.getBaseSystemId();
+
+            src.setByteStream(new ByteArrayInputStream(_schemas.get(location)));
+            return src;
+        }
+    }
 }