cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r490101 - in /incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src: main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/ main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/ test/java/org/apache/cxf/tools/wsdlto/fronte...
Date Mon, 25 Dec 2006 02:51:47 GMT
Author: ema
Date: Sun Dec 24 18:51:46 2006
New Revision: 490101

URL: http://svn.apache.org/viewvc?view=rev&rev=490101
Log:
[CXF-306] Added parser and test case for jaxb binding nested in jaxws binding.


Modified:
    incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
    incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java
    incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java
    incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding2.xml
    incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/hello_world.wsdl

Modified: incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java?view=diff&rev=490101&r1=490100&r2=490101
==============================================================================
--- incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
(original)
+++ incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customiztion/CustomizationParser.java
Sun Dec 24 18:51:46 2006
@@ -35,6 +35,8 @@
 import javax.wsdl.Operation;
 import javax.wsdl.PortType;
 import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
@@ -88,6 +90,8 @@
 
     private Element handlerChains;
     private Element wsdlNode;;
+    
+    private Element customizedWSDLNode;
 
     private CustomizationParser() {
 
@@ -136,7 +140,13 @@
         for (URI wsdlUri : jaxwsBindings.keySet()) {
             Element element = jaxwsBindings.get(wsdlUri);
             definition = getWSDlDefinition(wsdlUri.toString());
-            wsdlNode = getTargetNode(wsdlUri);
+            URI uri = null;
+            try {
+                uri = new URI(definition.getDocumentBaseURI());
+            } catch (URISyntaxException e1) {
+                //ignore
+            }
+            wsdlNode = getTargetNode(uri);
             buildTargetNodeMap(element, "");
         }
 
@@ -144,11 +154,13 @@
     }
 
     public Element getTargetNode(URI wsdlLoc) {
+
         Document doc = null;
         try {
             File file = new File(wsdlLoc);
             java.io.InputStream ins = new java.io.FileInputStream(file);
             doc = DOMUtils.readXml(ins);
+            
         } catch (SAXException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
@@ -205,7 +217,7 @@
         if (isJAXWSParameter(bindings) && bindings.getAttribute("part") != null)
{
             String partExpression = "//" + bindings.getAttribute("part");
             try {
-                Node node = evaluateBindingsNode(partExpression);
+                Node node = evaluateBindingsNode(wsdlNode, partExpression);
 
                 if ("part".equals(node.getLocalName())) {
                     JAXWSBinding jaxwsBinding = bindingsParser.parse(PortType.class, bindings,
@@ -220,23 +232,64 @@
         }
 
         if (isJAXWSBindings(bindings) && bindings.getAttributeNode("node") != null)
{
-
             expression = expression + "/" + bindings.getAttribute("node");
             try {
-                Node node = evaluateBindingsNode(expression);
-
-                if ("portType".equals(node.getLocalName())) {
+                Node node = null;
+                boolean nestedJaxb = nestedJaxbBinding(bindings);               
+                if (nestedJaxb) {
+                    customizedWSDLNode = 
+                        customizedWSDLNode == null ? getNodeInDefinition(definition) : customizedWSDLNode;
+                    node = evaluateBindingsNode(customizedWSDLNode, expression);
+                } else {
+                    node = evaluateBindingsNode(wsdlNode, expression);
+                }
+                if (node != null && "portType".equals(node.getLocalName()) &&
!nestedJaxb) {
                     JAXWSBinding jaxwsBinding = bindingsParser.parse(PortType.class, bindings,
                                                                      getTargetNamspace(node));
                     addJAXWSBindingMap(portTypeBindingMap, node, jaxwsBinding);
                 }
 
-                if ("operation".equals(node.getLocalName())) {
+                if (node != null && "operation".equals(node.getLocalName()) &&
!nestedJaxb) {
                     JAXWSBinding jaxwsBinding = bindingsParser.parse(Operation.class, bindings,
                                                                      getTargetNamspace(node));
                     addJAXWSBindingMap(opertaionBindingMap, node, jaxwsBinding);
                 }
 
+                if (node != null && nestedJaxb) {
+                    // append xmlns:jaxb and jaxb:version attribute for schema
+                    Node schemaNode = getSchemaNode(node);
+                    Element schemaElement = (Element)schemaNode;
+                    
+                    String jaxbPrefix = schemaElement.lookupPrefix(ToolConstants.NS_JAXB_BINDINGS);
+                    if (jaxbPrefix == null) {
+                        schemaElement.setAttribute("xmlns:jaxb", ToolConstants.NS_JAXB_BINDINGS);
+                        schemaElement.setAttribute("jaxb:version", "2.0");
+                    }
+
+                    // append jaxb appinfo for value node
+                    Element annoElement = node.getOwnerDocument().createElementNS(ToolConstants.SCHEMA_URI,
+                                                                                  "annotation");
+                    Element appinfoEle = node.getOwnerDocument().createElementNS(ToolConstants.SCHEMA_URI,
+                                                                                 "appinfo");
+
+                    annoElement.appendChild(appinfoEle);
+
+                    NodeList jxbBinds = getJaxbBindingNode((Element)bindings);
+
+                    for (int l = 0; l < jxbBinds.getLength(); l++) {
+                        Node jaxbBindingNode = jxbBinds.item(l);
+                        Node cloneNode = ProcessorUtil.cloneNode(node.getOwnerDocument(),
jaxbBindingNode,
+                                                                 true);
+                        appinfoEle.appendChild(cloneNode);
+                    }
+
+                    if (node.getChildNodes().getLength() > 0) {
+                        node.insertBefore(annoElement, node.getChildNodes().item(0));
+                    } else {
+                        node.appendChild(annoElement);
+                    }
+                }
+
             } catch (WSDLException we) {
                 Message msg = new Message("PARSE_BINDINGFILE_EXCEPTION", LOG);
                 throw new ToolException(msg, we);
@@ -248,6 +301,33 @@
             buildTargetNodeMap(children[i], expression);
         }
     }
+    @SuppressWarnings("unchecked")
+    private Element getNodeInDefinition(Definition def) {
+        List<ExtensibilityElement> extList = def.getTypes().getExtensibilityElements();
+        for (ExtensibilityElement ele : extList) {
+            if (ele instanceof Schema) {
+                Schema schema = (Schema)ele;
+                Element element = schema.getElement();
+                Element target = element.getOwnerDocument().getDocumentElement();
+                return target;
+            }
+        }
+        return null;
+    }
+    
+    private Node getSchemaNode(Node node) {
+        if (!"schema".equals(node.getLocalName())) {
+            while (node.getParentNode() != null) {
+                node = node.getParentNode();
+
+                if ("schema".equals(node.getLocalName())) {
+                    return node;
+                }
+            }
+            return null;
+        }
+        return node;
+    }
 
     @SuppressWarnings("unchecked")
     public Definition getWSDlDefinition(String baseUrl) {
@@ -409,8 +489,8 @@
         }
     }
 
-    private Node evaluateBindingsNode(String expression) throws WSDLException {
-        Node node = evaluateXPathNode(wsdlNode, expression, new javax.xml.namespace.NamespaceContext()
{
+    private Node evaluateBindingsNode(Node targetNode, String expression) throws WSDLException
{
+        Node node = evaluateXPathNode(targetNode, expression, new javax.xml.namespace.NamespaceContext()
{
             public String getNamespaceURI(String prefix) {
                 return definition.getNamespace(prefix);
             }
@@ -507,6 +587,20 @@
                && "bindings".equals(bindings.getLocalName());
     }
 
+    private boolean nestedJaxbBinding(Element bindings) {
+        NodeList nodeList = bindings.getElementsByTagNameNS(ToolConstants.NS_JAXB_BINDINGS,
"bindings");
+        if (nodeList.getLength() == 1) {
+            return true;
+        }
+        return false;
+    }
+
+    private NodeList getJaxbBindingNode(Element bindings) {
+        NodeList nodeList = bindings.getElementsByTagNameNS(ToolConstants.NS_JAXB_BINDINGS,
"bindings");
+        return nodeList.item(0).getChildNodes();       
+    }
+
+
     public Map<String, JAXWSBinding> getDefinitionBindingMap() {
         return this.definitionBindingMap;
     }
@@ -522,5 +616,13 @@
     public Map<QName, JAXWSBinding> getPartBindingMap() {
         return this.partBindingMap;
     }
-
+    
+    public Element getCustomizedWSDLElement() {
+        if (this.customizedWSDLNode == null) {
+            customizedWSDLNode = this.wsdlNode;
+        }
+        return customizedWSDLNode;
+        
+    }
+    
 }

Modified: incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java?view=diff&rev=490101&r1=490100&r2=490101
==============================================================================
--- incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java
(original)
+++ incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java
Sun Dec 24 18:51:46 2006
@@ -33,7 +33,9 @@
 
 import javax.wsdl.PortType;
 import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.xml.WSDLReader;
 
+import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolException;
@@ -51,6 +53,8 @@
     protected static final Logger LOG = LogUtils.getL7dLogger(JAXWSDefinitionBuilder.class);
     protected CustomizationParser cusParser;
     
+    private WSDLReader reader;
+    
     public JAXWSDefinitionBuilder() {
     }
     
@@ -65,6 +69,8 @@
 
         registerJaxwsExtension(registry);
         Definition wsdlDefinition = builder.build(wsdlURL);
+        
+        reader = builder.getWSDLReader();
 
         context.put(ToolConstants.WSDL_DEFINITION, wsdlDefinition);
         context.put(ToolConstants.IMPORTED_DEFINITION, builder.getImportedDefinitions());
@@ -137,6 +143,20 @@
     public CustomizationParser getCustomizationParer() {
         return cusParser;
     }
+    
+    public Definition getCustomizedDefinition() {
+        try {
+
+            Definition def = reader.readWSDL(cusParser.getCustomizedWSDLElement().getBaseURI(),
cusParser
+                .getCustomizedWSDLElement());
+            return def;
+        } catch (Exception we) {
+            Message msg = new Message("FAIL_TO_CREATE_WSDL_DEFINITION", LOG, cusParser
+                .getCustomizedWSDLElement().getBaseURI());
+            throw new RuntimeException(msg.toString(), we);
+        }
+    }
+    
 
     public boolean validate(Definition def) throws ToolException {
         if (context.optionSet(ToolConstants.CFG_VALIDATE_WSDL)) {

Modified: incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java?view=diff&rev=490101&r1=490100&r2=490101
==============================================================================
--- incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java
(original)
+++ incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilderTest.java
Sun Dec 24 18:51:46 2006
@@ -30,8 +30,11 @@
 import javax.wsdl.Port;
 import javax.wsdl.Service;
 import javax.wsdl.extensions.http.HTTPAddress;
+import javax.wsdl.extensions.schema.Schema;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Element;
+
 import junit.framework.TestCase;
 
 import org.apache.cxf.bindings.xformat.XMLBindingMessageFormat;
@@ -127,31 +130,35 @@
         assertEquals("Package customiztion for definition is not correct", "com.foo", jaxwsBinding
             .getPackage());
 
-        
         QName qn = new QName(def.getTargetNamespace(), "Greeter");
         jaxwsBinding = parser.getPortTypeBindingMap().get(qn);
         assertNotNull("JAXWSBinding for PortType is null", jaxwsBinding);
-        assertTrue("AsynMapping customiztion for PortType is not true", 
-                   jaxwsBinding.isEnableAsyncMapping());
+        assertTrue("AsynMapping customiztion for PortType is not true", jaxwsBinding.isEnableAsyncMapping());
 
         qn = new QName(def.getTargetNamespace(), "greetMeOneWay");
         jaxwsBinding = parser.getOperationBindingMap().get(qn);
-        
+
         assertNotNull("JAXWSBinding for Operation is null", jaxwsBinding);
-        assertEquals("Method name customiztion for operation is not correct", 
-                     "echoMeOneWay", jaxwsBinding.getMethodName());
+        assertEquals("Method name customiztion for operation is not correct", "echoMeOneWay",
jaxwsBinding
+            .getMethodName());
 
         qn = new QName(def.getTargetNamespace(), "in");
         jaxwsBinding = parser.getPartBindingMap().get(qn);
-       
-        assertEquals("Parameter name customiztion for part is not correct", 
-                     "num1", jaxwsBinding.getJaxwsPara().getName());
 
-        // System.out.println("----size ---- " +
-        // parser.getDefinitionBindingMap().size());
+        assertEquals("Parameter name customiztion for part is not correct", "num1", jaxwsBinding
+            .getJaxwsPara().getName());
+
+        Definition cusDef = builder.getCustomizedDefinition();
+
+        Schema schema = (Schema)cusDef.getTypes().getExtensibilityElements().iterator().next();
+
+        Element appinfoElement = (Element)schema.getElement()
+            .getElementsByTagNameNS(ToolConstants.SCHEMA_URI, "appinfo").item(0);
+
+        assertNotNull("Appinfo element does not  be append to schema element", appinfoElement);
 
-        // CustomizationParser cusParser = CustomizationParser.getInstance();
-        // cusParser.parse(env);
+        assertNotNull("typesafeEnum element does not  be append to schema element", appinfoElement
+            .getElementsByTagName("jaxb:typesafeEnumClass").item(0));
 
     }
 }

Modified: incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding2.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding2.xml?view=diff&rev=490101&r1=490100&r2=490101
==============================================================================
--- incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding2.xml
(original)
+++ incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/binding2.xml
Sun Dec 24 18:51:46 2006
@@ -33,10 +33,9 @@
 		</jaxws:bindings>
 	</jaxws:bindings>
 
-	<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
-		<jaxb:bindings version="2.0"
-			node="xsd:element[@name='CreateProcess']/xsd:complexType/xsd:sequence/xsd:element[@name='MyProcess']/xsd:simpleType">
-			<jaxb:typesafeEnumClass name="MyProcess">
+	<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema/xsd:element[@name='CreateProcess']/xsd:complexType/xsd:sequence/xsd:element[@name='MyProcess']/xsd:simpleType">
+		<jaxb:bindings>
+		   <jaxb:typesafeEnumClass name="MyProcess">
 				<jaxb:typesafeEnumMember name="BLUE" value="BLUE" />
 				<jaxb:typesafeEnumMember name="RED" value="RED" />
 				<jaxb:typesafeEnumMember name="GREEN" value="GREEN" />

Modified: incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/hello_world.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/hello_world.wsdl?view=diff&rev=490101&r1=490100&r2=490101
==============================================================================
--- incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/hello_world.wsdl
(original)
+++ incubator/cxf/trunk/tools2/wsdlto/frontend/jaxws/src/test/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/hello_world.wsdl
Sun Dec 24 18:51:46 2006
@@ -26,7 +26,7 @@
 	targetNamespace="http://apache.org/hello_world_soap_http"
 	name="HelloWorld">
 	<wsdl:types>
-		<schema elementFormDefault="qualified"
+		<xsd:schema elementFormDefault="qualified"
 			targetNamespace="http://apache.org/hello_world_soap_http/types"
 			xmlns="http://www.w3.org/2001/XMLSchema">
 			<element name="CreateProcess">
@@ -45,7 +45,7 @@
 				</complexType>
 			</element>
 			
-		</schema>
+		</xsd:schema>
 	</wsdl:types>
 
 	<wsdl:message name="greetMeOneWayRequest">



Mime
View raw message