You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/10/25 03:39:49 UTC

svn commit: r588108 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/wsdl11/ systests/src/test/java/org/apache/cxf/systest/wsdl/ systests/src/test/resources/

Author: dkulp
Date: Wed Oct 24 18:39:48 2007
New Revision: 588108

URL: http://svn.apache.org/viewvc?rev=588108&view=rev
Log:
Merged revisions 587966 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r587966 | bimargulies | 2007-10-24 14:55:16 -0400 (Wed, 24 Oct 2007) | 3 lines
  
  CXF-1103. Add missing cross-schema imports.
........

Added:
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/
      - copied from r587966, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
      - copied unchanged from r587966, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/resources/crossSchemaBeans.xml
      - copied unchanged from r587966, incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml
Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?rev=588108&r1=588107&r2=588108&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Wed Oct 24 18:39:48 2007
@@ -156,8 +156,7 @@
             it.setOutputProperty(OutputKeys.ENCODING, charset);
             it.transform(src, new StreamResult(os));
         } catch (TransformerException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new RuntimeException("Failed to configure TRaX", e);
         }
 
     }

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=588108&r1=588107&r2=588108&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Wed Oct 24 18:39:48 2007
@@ -25,6 +25,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+
 import javax.wsdl.Binding;
 import javax.wsdl.BindingFault;
 import javax.wsdl.BindingInput;
@@ -48,6 +49,7 @@
 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;
@@ -57,6 +59,7 @@
 import org.apache.cxf.Bus;
 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;
@@ -72,6 +75,7 @@
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.wsdl.WSDLConstants;
 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
@@ -82,7 +86,7 @@
  * the code creates a new definition element (i.e., Definition object), and imports it into
  * the top-level object.
  */
-public final class ServiceWSDLBuilder {
+public class ServiceWSDLBuilder {
     
     private final Map<String, String> ns2prefix;
     private Definition definition;
@@ -224,6 +228,39 @@
             }
         }
     }
+    
+    /**
+     * 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.NU_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.NU_SCHEMA_XSD)
+                && !xpu.isExist("xs:import[@namespace='" + namespace + "']", 
+                                 schemaElement, 
+                                 XPathConstants.NODE)) {
+                Element importElement = XMLUtils.createElementNS(schemaElement.getOwnerDocument(), 
+                                                                 WSDLConstants.NU_SCHEMA_XSD,
+                                                                 "import");
+                importElement.setAttribute("namespace", namespace);
+                schemaElement.insertBefore(importElement, schemaElement.getFirstChild());
+            }
+        }
+    }
 
     protected void buildTypes(final Collection<SchemaInfo> schemas,
                               final Map<String, SchemaInfo> imports,
@@ -261,6 +298,8 @@
                                
                 imports.put(name, schemaInfo);
             }
+            // add imports for those schemata which are inlined.
+            addRequiredSchemaImports(schemaInfo);
         }
         if (useSchemaImports) {
             SchemaImpl schemaImpl = new SchemaImpl();