You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2009/03/29 14:26:18 UTC

svn commit: r759672 - in /cxf/trunk: api/src/main/java/org/apache/cxf/service/model/ api/src/test/java/org/apache/cxf/service/model/ rt/core/src/main/java/org/apache/cxf/wsdl11/ rt/core/src/test/java/org/apache/cxf/wsdl11/

Author: bimargulies
Date: Sun Mar 29 12:26:17 2009
New Revision: 759672

URL: http://svn.apache.org/viewvc?rev=759672&view=rev
Log:
CXF-2127

Removed:
    cxf/trunk/api/src/test/java/org/apache/cxf/service/model/SchemaInfoTest.java
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/SchemaUtil.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java?rev=759672&r1=759671&r2=759672&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java Sun Mar 29 12:26:17 2009
@@ -27,21 +27,19 @@
 
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.io.CachedOutputStream;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaForm;
+import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 
 public final class SchemaInfo extends AbstractPropertiesHolder {
   
-    String namespaceUri;
-    Element element;
-    boolean isElementQualified;
-    boolean isAttributeQualified;
-    XmlSchema schema;
-    String systemId;
+    private String namespaceUri;
+    private boolean isElementQualified;
+    private boolean isAttributeQualified;
+    private XmlSchema schema;
+    private String systemId;
     
     public SchemaInfo(String namespaceUri) {
         this(namespaceUri, false, false);
@@ -73,58 +71,44 @@
     }
 
     public synchronized Element getElement() {
-        if (element == null && getSchema() != null) {
-            CachedOutputStream cout = new CachedOutputStream();
-            XmlSchema sch = getSchema();
-            synchronized (sch) {
-                XmlSchema schAgain = getSchema();
-                // XML Schema blows up when the context is null as opposed to empty.
-                // Some unit tests really want to see 'tns:'.
-                if (schAgain.getNamespaceContext() == null) {
-                    NamespaceMap nsMap = new NamespaceMap();
-                    nsMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
-                    nsMap.add("tns", schAgain.getTargetNamespace());
-                    schAgain.setNamespaceContext(nsMap);
-                }
-                schAgain.write(cout);
+        Element element = null;
+        if (getSchema() == null) {
+            throw new RuntimeException("No XmlSchma in SchemaInfo");
+        }
+
+        XmlSchema sch = getSchema();
+        synchronized (sch) {
+            XmlSchema schAgain = getSchema();
+            // XML Schema blows up when the context is null as opposed to empty.
+            // Some unit tests really want to see 'tns:'.
+            if (schAgain.getNamespaceContext() == null) {
+                NamespaceMap nsMap = new NamespaceMap();
+                nsMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
+                nsMap.add("tns", schAgain.getTargetNamespace());
+                schAgain.setNamespaceContext(nsMap);
             }
-            Document sdoc = null;
+            Document serializedSchema;
             try {
-                sdoc = XMLUtils.parse(cout.getInputStream());
-                cout.close();
-            } catch (Exception e1) {
-                return null;
-            }
-            
-            Element e = sdoc.getDocumentElement();
-            // XXX A problem can occur with the ibm jdk when the XmlSchema
-            // object is serialized. The xmlns declaration gets incorrectly
-            // set to the same value as the targetNamespace attribute.
-            // The aegis databinding tests demonstrate this particularly.
-            if (e.getPrefix() == null
-                && !WSDLConstants.NS_SCHEMA_XSD.equals(e.getAttributeNS(WSDLConstants.NS_XMLNS,
-                                                                        WSDLConstants.NP_XMLNS))) {
-                
-                Attr attr = e.getOwnerDocument().createAttributeNS(WSDLConstants.NS_XMLNS, 
-                                                                   WSDLConstants.NP_XMLNS);
-                attr.setValue(WSDLConstants.NS_SCHEMA_XSD);
-                e.setAttributeNodeNS(attr);
+                serializedSchema = schAgain.getSchemaDocument();
+            } catch (XmlSchemaSerializerException e) {
+                throw new RuntimeException("Error serializing Xml Schema", e);
             }
-            setElement(e);
+            element = serializedSchema.getDocumentElement();
         }
-        return element;
-    }
-
-    public void setElement(Element element) {
-        this.element = element;        
-        String form = element.getAttribute("elementFormDefault");
-        if ((form != null) && form.equals("qualified")) {
-            isElementQualified = true;
-        }
-        form = element.getAttribute("attributeFormDefault");
-        if ((form != null) && form.equals("qualified")) {
-            isAttributeQualified = true;
+        // XXX A problem can occur with the ibm jdk when the XmlSchema
+        // object is serialized. The xmlns declaration gets incorrectly
+        // set to the same value as the targetNamespace attribute.
+        // The aegis databinding tests demonstrate this particularly.
+        if (element.getPrefix() == null
+            && !WSDLConstants.NS_SCHEMA_XSD.equals(element.getAttributeNS(WSDLConstants.NS_XMLNS,
+                                                                    WSDLConstants.NP_XMLNS))) {
+
+            Attr attr = element.getOwnerDocument()
+                .createAttributeNS(WSDLConstants.NS_XMLNS, WSDLConstants.NP_XMLNS);
+            attr.setValue(WSDLConstants.NS_SCHEMA_XSD);
+            element.setAttributeNodeNS(attr);
         }
+        return element;
     }
 
     public boolean isElementFormQualified() {
@@ -162,4 +146,16 @@
         }
         return null;
     }
+
+    String getNamespaceUri() {
+        return namespaceUri;
+    }
+    
+    boolean isElementQualified() {
+        return isElementQualified;
+    }
+    
+    boolean isAttributeQualified() {
+        return isAttributeQualified;
+    }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/SchemaUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/SchemaUtil.java?rev=759672&r1=759671&r2=759672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/SchemaUtil.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/SchemaUtil.java Sun Mar 29 12:26:17 2009
@@ -124,7 +124,6 @@
                         XmlSchema xmlSchema = schemaCol.read(schemaElem, systemId);
                         catalogResolved.putAll(schemaResolver.getResolvedMap());
                         SchemaInfo schemaInfo = new SchemaInfo(xmlSchema.getTargetNamespace());
-                        schemaInfo.setElement(schemaElem);
                         schemaInfo.setSchema(xmlSchema);
                         schemaInfo.setSystemId(systemId);
                         schemaInfos.add(schemaInfo);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=759672&r1=759671&r2=759672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Sun Mar 29 12:26:17 2009
@@ -50,7 +50,6 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -62,7 +61,6 @@
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.AbstractPropertiesHolder;
 import org.apache.cxf.service.model.BindingFaultInfo;
@@ -78,7 +76,6 @@
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.wsdl.WSDLManager;
-import org.apache.ws.commons.schema.utils.NamespacePrefixList;
 
 /**
  * Consume a set of service definitions and produce a WSDL model. The ServiceInfo objects
@@ -245,39 +242,6 @@
         }
     }
     
-    /**
-     * For a schema, require all namespace with prefixes to be imported. In theory,
-     * if a namespace has a prefix but is not used, the import is not needed, and could
-     * cause a problem. In practice, the code generating these schemas should not be adding
-     * spurious prefixes. Hypothetically, we could check that, in the overall WSDL, that
-     * all of the schemas that we are importing are accounted for. However, that's a validation
-     * that is best left to the validator.
-     * @param schemaInfo Schema to process.
-     */
-    protected void addRequiredSchemaImports(SchemaInfo schemaInfo) {
-        Element schemaElement = schemaInfo.getElement();
-        // we need an import for every namespace except the main one.
-        String schemaNamespace = schemaInfo.getNamespaceURI();
-        Map<String, String> queryPrefixMap = new HashMap<String, String>();
-        queryPrefixMap.put("xs", WSDLConstants.NS_SCHEMA_XSD);
-        XPathUtils xpu = new XPathUtils(queryPrefixMap);
-        NamespacePrefixList schemaPrefixes = schemaInfo.getSchema().getNamespaceContext();
-        for (String prefix : schemaPrefixes.getDeclaredPrefixes()) {
-            String namespace = schemaPrefixes.getNamespaceURI(prefix);
-            if (!namespace.equals(schemaNamespace) 
-                && !namespace.equals(WSDLConstants.NS_SCHEMA_XSD)
-                && !xpu.isExist("xs:import[@namespace='" + namespace + "']", 
-                                 schemaElement, 
-                                 XPathConstants.NODE)) {
-                Element importElement = XMLUtils.createElementNS(schemaElement.getOwnerDocument(), 
-                                                                 WSDLConstants.NS_SCHEMA_XSD,
-                                                                 "import");
-                importElement.setAttribute("namespace", namespace);
-                schemaElement.insertBefore(importElement, schemaElement.getFirstChild());
-            }
-        }
-    }
-
     protected void buildTypes(final Collection<SchemaInfo> schemas,
                               final Map<String, SchemaInfo> imports,
                               final Definition def) {
@@ -314,8 +278,7 @@
                                
                 imports.put(name, schemaInfo);
             }
-            // add imports for those schemata which are inlined.
-            addRequiredSchemaImports(schemaInfo);
+
         }
         if (useSchemaImports) {
             SchemaImpl schemaImpl = new SchemaImpl();

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java?rev=759672&r1=759671&r2=759672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java Sun Mar 29 12:26:17 2009
@@ -49,6 +49,7 @@
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
@@ -293,8 +294,9 @@
         assertEquals(1, schemas.size());
         XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
         Element schemaElem = ((Schema)schemas.iterator().next()).getElement();
+        XmlSchema newSchema = schemaCollection.read(schemaElem); 
         assertEquals("http://apache.org/hello_world_soap_http/types",
-                     schemaCollection.read(schemaElem).getTargetNamespace() 
+                     newSchema.getTargetNamespace() 
                      );
     }