You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2010/03/31 09:32:17 UTC

svn commit: r929409 - in /servicemix/components/bindings/servicemix-cxf-bc/trunk/src: main/java/org/apache/servicemix/cxfbc/ test/resources/org/apache/servicemix/cxfbc/ws/security/

Author: ffang
Date: Wed Mar 31 07:32:16 2010
New Revision: 929409

URL: http://svn.apache.org/viewvc?rev=929409&view=rev
Log:
[SMXCOMP-730]delegate inline transformers to SchemaUtil

Added:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base2.xsd
Modified:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/SchemaUtil.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base.xsd
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/hello_world_base_security.wsdl

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java?rev=929409&r1=929408&r2=929409&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java Wed Mar 31 07:32:16 2010
@@ -45,6 +45,7 @@ import javax.xml.transform.dom.DOMSource
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
 import com.ibm.wsdl.Constants;
@@ -440,43 +441,10 @@ public class CxfBcProvider extends Provi
                 serInfo = ei.getService();
                 List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>();
                 serviceInfos.add(serInfo);
-                //transform import xsd to inline xsd
+                
                 ServiceWSDLBuilder swBuilder = new ServiceWSDLBuilder(getBus(),
                         serviceInfos);
-                for (String key : schemaList.keySet()) {
-                    if (!key.endsWith(".xsd")) {
-                        continue;
-                    }
-                    Element ele = schemaList.get(key);
-                    for (SchemaInfo sInfo : serInfo.getSchemas()) {
-                        Node nl = sInfo.getElement().getElementsByTagNameNS(
-                                "http://www.w3.org/2001/XMLSchema", "import")
-                                .item(0);
-                        
-                        if (sInfo.getNamespaceURI() == null // it's import
-                                                            // schema
-                                && nl != null
-                                && ((Element) nl)
-                                        .getAttribute("namespace")
-                                        .equals(
-                                                ele
-                                                        .getAttribute("targetNamespace"))) {
-
-                            sInfo.setElement(ele);
-                        }
-                    }
-                    for (SchemaInfo sInfo : serInfo.getSchemas()) {
-                        Node nl = sInfo.getElement().getElementsByTagNameNS(
-                                "http://www.w3.org/2001/XMLSchema", "include")
-                                .item(0);
-                        if (nl != null
-                                && sInfo.getNamespaceURI()
-                                        .equals(ele.getAttribute("targetNamespace"))) {
-
-                            sInfo.setElement(ele);
-                        }
-                    }
-                }
+                
                 serInfo.setProperty(WSDLServiceBuilder.WSDL_DEFINITION, null);
                 serInfo.getInterface().setProperty(WSDLServiceBuilder.WSDL_PORTTYPE, null);
                 for (OperationInfo opInfo : serInfo.getInterface().getOperations()) {
@@ -484,7 +452,6 @@ public class CxfBcProvider extends Provi
                 }
                 description = WSDLFactory.newInstance().newWSDLWriter()
                         .getDocument(swBuilder.build());
-
                 if (endpoint == null) {
                     endpoint = ei.getName().getLocalPart();
                 }
@@ -596,6 +563,8 @@ public class CxfBcProvider extends Provi
         } 
     }
 
+   
+    
     protected Bus getBus() {
         if (providedBus != null) {
             return providedBus;

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/SchemaUtil.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/SchemaUtil.java?rev=929409&r1=929408&r2=929409&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/SchemaUtil.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/SchemaUtil.java Wed Mar 31 07:32:16 2010
@@ -33,6 +33,7 @@ import javax.wsdl.extensions.schema.Sche
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.catalog.CatalogXmlSchemaURIResolver;
@@ -211,6 +212,10 @@ public final class SchemaUtil {
                         && !schemaList.containsValue(tempImport.getElement())) {
                         addSchema(key, tempImport);
                     }
+                    if (tempImport != null) {
+                      //keep this imported schema inline
+                      inlineTransformer(key, tempImport.getElement(), schema.getElement(), false);
+                    }
                 }
 
             }
@@ -235,6 +240,10 @@ public final class SchemaUtil {
                         && !schemaList.containsValue(tempInclude.getElement())) {
                     addSchema(key, tempInclude);
                 }
+                if (tempInclude != null) {
+                  //keep this included schema inline
+                  inlineTransformer(key, tempInclude.getElement(), schema.getElement(), true);
+                }
             }
 
         }
@@ -250,4 +259,42 @@ public final class SchemaUtil {
         }
         return false;
     }
+    
+    private void inlineTransformer(String key, Element inlineSchema, Element outerSchema, boolean isInclude) {
+        NodeList nl = null;
+        if (isInclude) {
+            nl = outerSchema.getElementsByTagNameNS(
+                    "http://www.w3.org/2001/XMLSchema", "include");
+        } else {
+            nl = outerSchema.getElementsByTagNameNS(
+                    "http://www.w3.org/2001/XMLSchema", "import");
+        }
+        for (int j = 0; j < nl.getLength(); j++) {
+        
+            String schemaLocation = ((Element)nl.item(j)).getAttribute("schemaLocation");
+            
+            if (schemaLocation != null && getXsdFileName(schemaLocation, "/").
+                    equals(getXsdFileName(key, "/"))) {
+                                            
+                outerSchema.removeChild(nl.item(j));
+                for (int i = 0; i < inlineSchema.getChildNodes().getLength(); i++) {
+                    outerSchema.appendChild(
+                            outerSchema.getOwnerDocument().importNode(
+                                inlineSchema.getChildNodes().item(i), true));
+                }
+                outerSchema.setPrefix("xs");
+                outerSchema.setAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
+            }
+        }
+    }
+    
+    private String getXsdFileName(String path, String sep) {
+        String name = "";
+        if (path.lastIndexOf(sep) >= 0) {
+            name = path.substring(path.lastIndexOf(sep) + 1);
+        } else {
+            name = path;
+        }
+        return name;
+    }
 }

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base.xsd
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base.xsd?rev=929409&r1=929408&r2=929409&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base.xsd (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base.xsd Wed Mar 31 07:32:16 2010
@@ -18,7 +18,7 @@
   under the License.
 -->
  <schema targetNamespace="http://apache.org/hello_world_soap_http/types" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://apache.org/hello_world_soap_http/types" elementFormDefault="qualified">
-            <element name="sayHi">
+           <element name="sayHi">
                 <complexType/>
             </element>
             <element name="sayHiResponse">

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base2.xsd
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base2.xsd?rev=929409&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base2.xsd (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/base2.xsd Wed Mar 31 07:32:16 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+ <xs:schema targetNamespace="http://apache.org/hello_world_soap_http/types"  xmlns:x1="http://apache.org/hello_world_soap_http/types" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+            <xs:element name="sayHelloResponse">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element name="responseType" type="xs:string"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+        
+</xs:schema>

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/hello_world_base_security.wsdl
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/hello_world_base_security.wsdl?rev=929409&r1=929408&r2=929409&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/hello_world_base_security.wsdl (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/hello_world_base_security.wsdl Wed Mar 31 07:32:16 2010
@@ -25,8 +25,15 @@
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://apache.org/hello_world_soap_http" name="HelloWorld">
     <wsdl:types>
-        <xsd:schema targetNamespace="http://apache.org/hello_world_soap_http/types">
-            <xsd:include schemaLocation="base.xsd"/>
+        <xsd:schema targetNamespace="http://apache.org/hello_world_soap_http/types"
+            xmlns="http://www.w3.org/2001/XMLSchema"
+            xmlns:tns="http://apache.org/hello_world_soap_http_provider/types"
+            elementFormDefault="qualified">
+            <xsd:import namespace="http://apache.org/hello_world_soap_http/types" schemaLocation="base.xsd"/>
+            <xsd:include schemaLocation="base2.xsd"/>
+            <element name="sayHello">
+                <complexType/>
+            </element>
         </xsd:schema>
     </wsdl:types>
     <wsdl:message name="sayHiRequest">