You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2005/10/26 19:07:11 UTC

svn commit: r328680 - in /incubator/woden/java/src/org/apache/woden: internal/DOMWSDLReader.java internal/schema/SchemaImpl.java internal/util/ComponentModelBuilder.java schema/Schema.java

Author: jkaputin
Date: Wed Oct 26 10:06:59 2005
New Revision: 328680

URL: http://svn.apache.org/viewcvs?rev=328680&view=rev
Log:
Changed use of W3C XMLSchema API to ws-commons XmlSchema

Modified:
    incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
    incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java
    incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
    incubator/woden/java/src/org/apache/woden/schema/Schema.java

Modified: incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java?rev=328680&r1=328679&r2=328680&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/DOMWSDLReader.java Wed Oct 26 10:06:59 2005
@@ -16,8 +16,6 @@
 package org.apache.woden.internal;
 
 import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Hashtable;
@@ -34,7 +32,6 @@
 import org.apache.woden.internal.schema.SchemaImpl;
 import org.apache.woden.internal.schema.SchemaImportImpl;
 import org.apache.woden.internal.util.StringUtils;
-import org.apache.woden.internal.util.dom.DOM2Writer;
 import org.apache.woden.internal.util.dom.DOMUtils;
 import org.apache.woden.internal.util.dom.QNameUtils;
 import org.apache.woden.internal.wsdl20.Constants;
@@ -49,21 +46,15 @@
 import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
 import org.apache.woden.wsdl20.xml.PropertyElement;
 import org.apache.woden.wsdl20.xml.TypesElement;
-import org.apache.xerces.xs.XSException;
-import org.apache.xerces.xs.XSImplementation;
-import org.apache.xerces.xs.XSLoader;
-import org.apache.xerces.xs.XSModel;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.w3c.dom.Attr;
-import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
-import org.w3c.dom.bootstrap.DOMImplementationRegistry;
-import org.w3c.dom.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSInput;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -393,7 +384,7 @@
             getErrorReporter().reportError( 
                                   new ErrorLocatorImpl(),  //TODO line&col nos.
                                   "WSDL504",
-                                  new Object[] {"element", "fault"}, 
+                                  new Object[] {element, "fault"}, 
                                   ErrorReporter.SEVERITY_ERROR);
             //TODO if validation is off and continue-on-error is off, terminate here
         }
@@ -537,9 +528,6 @@
         return property;
     }
 
-    /*
-     * TODO use ws-commons XmlSchema, instead of Xerces XML Schema API
-     */
     private Schema parseSchema(Element schemaEl,
                                DescriptionElement desc) 
                                throws WSDLException
@@ -567,133 +555,12 @@
             return schema;
         }
         
-        /*
-         * TODO Limitations in ws-commons XmlSchema slowing down Woden progress
-         * for M1, so reverting to Xerces XMLSchema API for the time being.
-         * 
-        XmlSchemaCollection xsc = 
-            new XmlSchemaCollection();
-        
+        XmlSchemaCollection xsc = new XmlSchemaCollection();
         XmlSchema xs = xsc.read(schemaEl);
         
         schema.setSchemaContent(xs);
-         */
-        
-        try {
-            //create an LSInput object to hold the schema string
-            DOMImplementationLS domImpl = null;
-            boolean useDom3Bootstrap = true;
-            Object domImplRegObj = null;
-            Method newInstanceMethod = null;
-            Method getDomImplMethod = null;
-            
-            System.setProperty(DOMImplementationRegistry.PROPERTY,
-            "org.apache.xerces.dom.DOMImplementationSourceImpl");
-            
-            try {
-                DOMImplementationRegistry domRegistry = DOMImplementationRegistry.newInstance();
-                
-                domImpl = (DOMImplementationLS)domRegistry.getDOMImplementation("LS");
-            } 
-            catch (ClassCastException e1) 
-            {
-                /*
-                 * This exception occurs with the IBM 1.42 JRE which contains an
-                 * implementation of Xerces (2.6?) that expects a different version
-                 * of DOMImplementationRegistry to the DOM Level 3 bootstrap used by
-                 * Xerces 2.7.1, on which Woden is dependent. Use Java reflection to
-                 * bootstrap with the expected version of DOMImplementationRegistry.
-                 */
-                useDom3Bootstrap = false;
-                
-                Class c = this.getClass().getClassLoader().loadClass(
-                        "org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry");
-
-                Method[] ms = c.getDeclaredMethods();
-                for(int i=0; i<ms.length; i++)
-                {
-                    if("newInstance".equals(ms[i].getName())) {
-                        newInstanceMethod = ms[i];
-                    }
-                    else if("getDOMImplementation".equals(ms[i].getName())) {
-                        getDomImplMethod = ms[i];
-                    }
-                }
-                
-                domImplRegObj = newInstanceMethod.invoke(new Object(), null);
-                
-                DOMImplementation di = (DOMImplementation) 
-                    getDomImplMethod.invoke(domImplRegObj, new Object[] {"LS"});
-                
-                domImpl = (DOMImplementationLS)di;
-            }
-            
-            LSInput lsInput = domImpl.createLSInput();
-            
-            //store the schema as a string in the LSInput 
-            String schemaString = DOM2Writer.nodeToString(schemaEl);
-            lsInput.setStringData(schemaString);
-            
-            //Use DOM level 3 bootstrap to get an XSLoader
-            XSImplementation xsImpl = null;
-            System.setProperty(DOMImplementationRegistry.PROPERTY,
-            "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
-            
-            if(useDom3Bootstrap)
-            {
-                DOMImplementationRegistry xsRegistry = DOMImplementationRegistry.newInstance();
-                
-                xsImpl = (XSImplementation) xsRegistry.getDOMImplementation("XS-Loader");
-            }
-            else
-            {
-                /*
-                 * Ditto the comment above about DOMImplementationRegistry in IBM 1.42 JRE.
-                 */
-                domImplRegObj = newInstanceMethod.invoke(new Object(), null);
-                
-                DOMImplementation di = (DOMImplementation) 
-                    getDomImplMethod.invoke(domImplRegObj, new Object[] {"XS-Loader"});
-                
-                xsImpl = (XSImplementation)di;
-            }
-            
-            XSLoader xsLoader = xsImpl.createXSLoader(null);
-            
-            //load the XSModel from the schema string
-            XSModel xsModel = xsLoader.load(lsInput);
-            
-            //TODO handle a null xsmodel if an error is encountered
-            schema.setSchemaContent(xsModel);
-            
-        } catch (ClassCastException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        } catch (XSException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        } catch (ClassNotFoundException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        } catch (InstantiationException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        } catch (IllegalAccessException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        } catch (InvocationTargetException e) {
-            getErrorReporter().reportError(
-                    new ErrorLocatorImpl(),  //TODO line&col nos.
-                    "WSDL002", new Object[] {"Schema"}, ErrorReporter.SEVERITY_FATAL_ERROR, e);
-        }
         
         return schema;
-
     }
 
     /*

Modified: incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java?rev=328680&r1=328679&r2=328680&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/schema/SchemaImpl.java Wed Oct 26 10:06:59 2005
@@ -16,8 +16,7 @@
 package org.apache.woden.internal.schema;
 
 import org.apache.woden.schema.Schema;
-//import org.apache.ws.commons.schema.XmlSchema;  //TODO test ws-commons XmlSchema
-import org.apache.xerces.xs.XSModel;
+import org.apache.ws.commons.schema.XmlSchema;
 
 /**
  * Represents a &lt;xs:schema&gt; element.
@@ -28,7 +27,7 @@
     
     private String fTargetNamespace = null;
     private String fId = null;
-    private XSModel fSchemaContent = null;
+    private XmlSchema fSchemaContent = null;
 
     public void setId(String id)
     {
@@ -56,12 +55,12 @@
         return fTargetNamespace;
     }
     
-    public void setSchemaContent(XSModel xmlSchema)
+    public void setSchemaContent(XmlSchema xmlSchema)
     {
         fSchemaContent = xmlSchema;
     }
     
-    public XSModel getSchemaContent()
+    public XmlSchema getSchemaContent()
     {
         return fSchemaContent;
     }

Modified: incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java?rev=328680&r1=328679&r2=328680&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/util/ComponentModelBuilder.java Wed Oct 26 10:06:59 2005
@@ -31,10 +31,8 @@
 import org.apache.woden.wsdl20.Description;
 import org.apache.woden.wsdl20.xml.DescriptionElement;
 import org.apache.woden.wsdl20.xml.TypesElement;
-import org.apache.xerces.xs.XSConstants;
-import org.apache.xerces.xs.XSModel;
-import org.apache.xerces.xs.XSNamedMap;
-import org.apache.xerces.xs.XSObject;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 
 /**
  * Converts the xml representation of a WSDL document to the WSDL
@@ -148,48 +146,48 @@
      */
     private void buildElementDeclarations(Schema schema)
     {
-        XSModel xsModel = schema.getSchemaContent();
-        XSNamedMap map = 
-            xsModel.getComponentsByNamespace(XSConstants.ELEMENT_DECLARATION,
-                                             schema.getTargetNamespace());
+        String schemaTns = schema.getTargetNamespace();
+        XmlSchema xmlSchema = schema.getSchemaContent();
+        XmlSchemaObjectTable elementTable = xmlSchema.getElements();
+        Iterator qnames = elementTable.getNames();
         
-        for(int j=0; j < map.getLength(); j++)
+        while(qnames.hasNext())
         {
-            XSObject xsED = map.item(j);
-            QName qn = new QName(xsED.getNamespace(), xsED.getName());
+            QName qname = (QName)qnames.next();
             
-            ElementDeclarationImpl ed = new ElementDeclarationImpl();
-            ed.setName(qn);
-            ed.setContentModel(Constants.API_W3C_XS);
-            ed.setContent(xsED);
-            
-            fDescComponent.addElementDeclaration(ed);
+            if(qname.getNamespaceURI().equals(schemaTns))
+            {
+                ElementDeclarationImpl ed = new ElementDeclarationImpl();
+                ed.setName(qname);
+                ed.setContentModel(Constants.API_APACHE_WS_XS);
+                ed.setContent(elementTable.getItem(qname));
+                fDescComponent.addElementDeclaration(ed);
+            }
         }
     }
         
     /*
-     * Extract from the collections of in-scope schemas
-     * the type definitions.
+     * Extract the type definitions from the given schema. 
      */
-
     private void buildTypeDefinitions(Schema schema)
     {
-        XSModel xsModel = schema.getSchemaContent();
-        XSNamedMap map = 
-            xsModel.getComponentsByNamespace(XSConstants.TYPE_DEFINITION, 
-                                             schema.getTargetNamespace());
+        String schemaTns = schema.getTargetNamespace();
+        XmlSchema xmlSchema = schema.getSchemaContent();
+        XmlSchemaObjectTable typeTable = xmlSchema.getSchemaTypes();
+        Iterator qnames = typeTable.getNames();
         
-        for(int j=0; j < map.getLength(); j++)
+        while(qnames.hasNext())
         {
-            XSObject xsTD = map.item(j);
-            QName qn = new QName(xsTD.getNamespace(), xsTD.getName());
-            
-            TypeDefinitionImpl td = new TypeDefinitionImpl();
-            td.setName(qn);
-            td.setContentModel(Constants.API_W3C_XS);
-            td.setContent(xsTD);
+            QName qname = (QName)qnames.next();
             
-            fDescComponent.addTypeDefinition(td);
+            if(qname.getNamespaceURI().equals(schemaTns))
+            {
+                TypeDefinitionImpl td = new TypeDefinitionImpl();
+                td.setName(qname);
+                td.setContentModel(Constants.API_APACHE_WS_XS);
+                td.setContent(typeTable.getItem(qname));
+                fDescComponent.addTypeDefinition(td);
+            }
         }
     }
     

Modified: incubator/woden/java/src/org/apache/woden/schema/Schema.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/schema/Schema.java?rev=328680&r1=328679&r2=328680&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/schema/Schema.java (original)
+++ incubator/woden/java/src/org/apache/woden/schema/Schema.java Wed Oct 26 10:06:59 2005
@@ -16,8 +16,7 @@
 package org.apache.woden.schema;
 
 
-//import org.apache.ws.commons.schema.*;  
-import org.apache.xerces.xs.XSModel; //temporarily using Xerces XMLSchema API
+import org.apache.ws.commons.schema.XmlSchema;  
 
 /**
  * This interface represents the a schema element from any XML based 
@@ -32,9 +31,6 @@
  * different elements and types from the same namespace). The actual 
  * schema content is represented as an <code>XmlSchema</code> object.
  * <p>
- * NOTE: TODO temporarily using Xerces XMLSchema API to represent the
- * schema content pending enhancements to ws-commons XmlSchema
- * <p>
  * NOTE: non-XML type systems like DTD are not handled by this interface. They must be
  * handled by WSDL 2.0 extension mechanisms.
  * 
@@ -54,20 +50,8 @@
     
     public String getTargetNamespace();
     
-    /**
-     * temporarily using Xerces XMLSchema API, pending 
-     * ws-commons XmlSchema enhancements.
-     * 
-     * @param xmlSchema the schema content
-     */
-    public void setSchemaContent(XSModel xmlSchema);
+    public void setSchemaContent(XmlSchema xmlSchema);
     
-    /**
-     * temporarily using Xerces XMLSchema API, pending 
-     * ws-commons XmlSchema enhancements.
-     * 
-     * @return XSModel the schema content
-     */
-    public XSModel getSchemaContent();
+    public XmlSchema getSchemaContent();
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org