Author: dkulp
Date: Tue Jul 22 13:42:43 2008
New Revision: 678891

URL: http://svn.apache.org/viewvc?rev=678891&view=rev
Log:
[CXF-1620] Support for jaxb:extensionBindingPrefix attributes (and thus the 
xjc:simple things and such)


Added:
    
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
   (with props)
    
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
   (with props)
Modified:
    
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
    
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
    
cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java

Modified: 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java?rev=678891&r1=678890&r2=678891&view=diff
==============================================================================
--- 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
 (original)
+++ 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/CustomizationParser.java
 Tue Jul 22 13:42:43 2008
@@ -33,8 +33,10 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.w3c.dom.Attr;
 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;
 
@@ -234,6 +236,9 @@
         for (Node childNode = jaxwsBindingNode.getFirstChild();
             childNode != null;
             childNode = childNode.getNextSibling()) {
+            
+            copyJaxbAttributes(childNode, (Element)schemaNode);
+            
             if (!isJaxbBindings(childNode)) {
                 continue;
             }
@@ -246,8 +251,18 @@
                     copyAllJaxbDeclarations(node, childEl);
                 }
             } else {
-                final Node jaxbNode = childEl;
-                Node cloneNode = 
ProcessorUtil.cloneNode(schemaNode.getOwnerDocument(), jaxbNode, true);
+                Element cloneNode = 
(Element)ProcessorUtil.cloneNode(schemaNode.getOwnerDocument(), 
+                                                                     childEl, 
true);
+                
+                NamedNodeMap atts = cloneNode.getAttributes();
+                for (int x = 0; x < atts.getLength(); x++) {
+                    Attr attr = (Attr)atts.item(x);
+                    if 
(ToolConstants.NS_JAXB_BINDINGS.equals(attr.getNamespaceURI())) {
+                        cloneNode.removeAttributeNode(attr);
+                        atts = cloneNode.getAttributes();
+                        x = -1;
+                    }
+                }
                 appinfoNode.appendChild(cloneNode);
                 childNode = childNode.getNextSibling();
             }
@@ -260,6 +275,38 @@
         }
     }
 
+    private void copyJaxbAttributes(Node childNode, Element schemaNode) {
+        if (childNode instanceof Element) {
+            Element el = (Element)childNode;
+            NamedNodeMap atts = el.getAttributes();
+            for (int x = 0; x < atts.getLength(); x++) {
+                Attr attr = (Attr)atts.item(x);
+                if 
(ToolConstants.NS_JAXB_BINDINGS.equals(attr.getNamespaceURI())) {
+                    schemaNode.setAttributeNS(attr.getNamespaceURI(),
+                                              attr.getName(),
+                                              attr.getValue());
+                    if 
("extensionBindingPrefixes".equals(attr.getLocalName())) {
+                        String pfxs = attr.getValue();
+                        while (pfxs.length() > 0) {
+                            String pfx = pfxs;
+                            int idx = pfx.indexOf(',');
+                            if (idx != -1) {
+                                pfxs = pfxs.substring(idx + 1);
+                                pfx = pfx.substring(0, idx);
+                            } else {
+                                pfxs = "";
+                            }
+                            String ns = el.lookupNamespaceURI(pfx);
+                            schemaNode.setAttribute("xmlns:" + pfx,
+                                                    ns);
+                        }
+                    }
+                }
+            }
+        }
+        
+    }
+
     protected void internalizeBinding(Element bindings, Element targetNode, 
String expression) {
         if (bindings.getAttributeNode("wsdlLocation") != null) {
             expression = "/";

Modified: 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java?rev=678891&r1=678890&r2=678891&view=diff
==============================================================================
--- 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
 (original)
+++ 
cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/processor/internal/ProcessorUtil.java
 Tue Jul 22 13:42:43 2008
@@ -31,6 +31,7 @@
 
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -334,11 +335,13 @@
             clone = document.createEntityReference(node.getNodeName());
             break;
         case Node.ELEMENT_NODE:
-            clone = document.createElement(node.getNodeName());
+            clone = document.createElementNS(node.getNamespaceURI(), 
node.getNodeName());
             NamedNodeMap attributes = node.getAttributes();
             for (int i = 0; i < attributes.getLength(); i++) {
-                
((Element)clone).setAttribute(attributes.item(i).getNodeName(), 
attributes.item(i)
-                    .getNodeValue());
+                Attr attr = (Attr)attributes.item(i);
+                ((Element)clone).setAttributeNS(attr.getNamespaceURI(),
+                                                attr.getNodeName(),
+                                                attr.getNodeValue());
             }
             break;
        

Modified: 
cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java?rev=678891&r1=678890&r2=678891&view=diff
==============================================================================
--- 
cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
 (original)
+++ 
cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
 Tue Jul 22 13:42:43 2008
@@ -1002,4 +1002,21 @@
         assertEquals("int", webFault.name());
     }
     
+    @Test
+    public void testCXF1620() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, 
+                getLocation("/wsdl2java_wsdl/jaxb_custom_extensors.wsdl"));   
+        env.put(ToolConstants.CFG_BINDING,
+                getLocation("/wsdl2java_wsdl/jaxb_custom_extensors.xjb"));
+
+        processor.setContext(env);
+        processor.execute();
+        Class<?> clz = 
classLoader.loadClass("org.apache.cxf.w2j.jaxb_custom_ext.types.Foo");
+        
+        assertEquals(3, clz.getDeclaredFields().length);
+        
+        clz = 
classLoader.loadClass("org.apache.cxf.w2j.jaxb_custom_ext.types.Foo2");
+        assertEquals(1, clz.getDeclaredFields().length);
+    }
+    
 }

Added: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl?rev=678891&view=auto
==============================================================================
--- 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
 (added)
+++ 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
 Tue Jul 22 13:42:43 2008
@@ -0,0 +1,197 @@
+<?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.
+-->
+<wsdl:definitions name="HelloWorld" 
targetNamespace="http://cxf.apache.org/w2j/jaxb_custom_ext"; 
+    xmlns="http://schemas.xmlsoap.org/wsdl/"; 
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; 
+    xmlns:tns="http://cxf.apache.org/w2j/jaxb_custom_ext";
+    xmlns:x1="http://cxf.apache.org/w2j/jaxb_custom_ext/types";
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+    <wsdl:types>
+        <schema 
targetNamespace="http://cxf.apache.org/w2j/jaxb_custom_ext/types"; 
+            xmlns="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified">
+
+            
+            <complexType name="foo">
+                               <choice>
+                                       <sequence>
+                                               <element name="a" 
type="xsd:int" />
+                                               <element name="b" 
type="xsd:int" />
+                                       </sequence>
+                                       <sequence>
+                                               <element name="b" 
type="xsd:int" />
+                                               <element name="c" 
type="xsd:int" />
+                                       </sequence>
+                               </choice>
+                       </complexType>
+                        
+                       <complexType name="foo2">
+                <sequence>
+                    <element name="property" type="xsd:string"/>
+                    <choice maxOccurs="unbounded">
+                        <element name="property" type="xsd:string"/>
+                        <element name="compound" type="xsd:int"/>
+                    </choice>
+                </sequence>
+            </complexType>
+            
+            <element name="sayHi">
+                <complexType/>
+            </element>
+            <element name="sayHiResponse">
+                <complexType>
+                    <sequence>
+                        <element name="responseType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+            <element name="greetMe">
+                <complexType>
+                    <sequence>
+                        <element name="requestType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+            <element name="greetMeResponse">
+                <complexType>
+                    <sequence>
+                        <element name="responseType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+            <element name="greetMeOneWay">
+                <complexType>
+                    <sequence>
+                        <element name="requestType" type="xsd:string"/>
+                    </sequence>
+                </complexType>
+            </element>
+               <element name="pingMe">
+                               <complexType/>
+                       </element>
+                       <element name="pingMeResponse">
+                               <complexType/>
+                       </element>
+                       <element name="faultDetail">
+                               <complexType>
+                                       <sequence>
+                                               <element name="minor" 
type="xsd:short"/>
+                                               <element name="major" 
type="xsd:short"/>
+                                       </sequence>
+                               </complexType>
+                       </element>
+        </schema>
+    </wsdl:types>
+    <wsdl:message name="sayHiRequest">
+        <wsdl:part element="x1:sayHi" name="in"/>
+    </wsdl:message>
+    <wsdl:message name="sayHiResponse">
+        <wsdl:part element="x1:sayHiResponse" name="out"/>
+    </wsdl:message>
+    <wsdl:message name="greetMeRequest">
+        <wsdl:part element="x1:greetMe" name="in"/>
+    </wsdl:message>
+    <wsdl:message name="greetMeResponse">
+        <wsdl:part element="x1:greetMeResponse" name="out"/>
+    </wsdl:message>
+    <wsdl:message name="greetMeOneWayRequest">
+        <wsdl:part element="x1:greetMeOneWay" name="in"/>
+    </wsdl:message>
+    <wsdl:message name="pingMeRequest">
+               <wsdl:part name="in" element="x1:pingMe"/>
+       </wsdl:message>
+       <wsdl:message name="pingMeResponse">
+               <wsdl:part name="out" element="x1:pingMeResponse"/>
+       </wsdl:message>         
+       <wsdl:message name="pingMeFault">
+               <wsdl:part name="faultDetail" element="x1:faultDetail"/>
+       </wsdl:message>
+    
+    <wsdl:portType name="Greeter">
+        <wsdl:operation name="sayHi">
+            <wsdl:input message="tns:sayHiRequest" name="sayHiRequest"/>
+            <wsdl:output message="tns:sayHiResponse" name="sayHiResponse"/>
+        </wsdl:operation>
+        
+        <wsdl:operation name="greetMe">
+            <wsdl:input message="tns:greetMeRequest" name="greetMeRequest"/>
+            <wsdl:output message="tns:greetMeResponse" name="greetMeResponse"/>
+        </wsdl:operation>
+        
+        <wsdl:operation name="greetMeOneWay">
+            <wsdl:input message="tns:greetMeOneWayRequest" 
name="greetMeOneWayRequest"/>
+        </wsdl:operation>
+
+           <wsdl:operation name="pingMe">
+               <wsdl:input name="pingMeRequest" message="tns:pingMeRequest"/>
+                       <wsdl:output name="pingMeResponse" 
message="tns:pingMeResponse"/>
+                       <wsdl:fault name="pingMeFault" 
message="tns:pingMeFault"/>
+           </wsdl:operation> 
+    </wsdl:portType>
+    <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
+        <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"/>
+        
+        <wsdl:operation name="sayHi">
+            <soap:operation soapAction="" style="document"/>
+            <wsdl:input name="sayHiRequest">
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output name="sayHiResponse">
+                <soap:body use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+        
+        <wsdl:operation name="greetMe">
+            <soap:operation soapAction="" style="document"/>
+            <wsdl:input name="greetMeRequest">
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output name="greetMeResponse">
+                <soap:body use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+        
+        <wsdl:operation name="greetMeOneWay">
+            <soap:operation soapAction="" style="document"/>
+            <wsdl:input name="greetMeOneWayRequest">
+                <soap:body use="literal"/>
+            </wsdl:input>
+        </wsdl:operation>
+
+                       <wsdl:operation name="pingMe">
+                       <soap:operation style="document"/>
+                       <wsdl:input>
+                               <soap:body use="literal"/>
+                       </wsdl:input>
+                       <wsdl:output>
+                               <soap:body use="literal"/>
+                       </wsdl:output>
+                       <wsdl:fault name="pingMeFault">
+                               <soap:fault name="pingMeFault" use="literal"/>
+                       </wsdl:fault>
+               </wsdl:operation>
+        
+    </wsdl:binding>
+    <wsdl:service name="SOAPService">
+        <wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort">
+            <soap:address 
location="http://localhost:9000/SoapContext/SoapPort"/>
+        </wsdl:port>
+    </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
URL: 
http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb?rev=678891&view=auto
==============================================================================
--- 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
 (added)
+++ 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
 Tue Jul 22 13:42:43 2008
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  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.
+-->
+<jaxws:bindings wsdlLocation="jaxb_custom_extensors.wsdl"
+    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"; 
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
+            
+        <jaxb:globalBindings 
+               jaxb:version="2.0"
+            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
+               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc";
+               jaxb:extensionBindingPrefixes="xjc">
+            <xjc:simple />
+        </jaxb:globalBindings>
+    </jaxws:bindings>
+</jaxws:bindings>

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/jaxb_custom_extensors.xjb
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to