You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2005/12/01 08:57:47 UTC

svn commit: r350203 [3/3] - in /webservices/axis2/trunk/java/modules: addressing/test-resources/ codegen/test-resources/xmls/ codegen/test/org/apache/axis2/rpc/ core/src/org/apache/axis2/deployment/ core/src/org/apache/axis2/deployment/util/ core/src/o...

Modified: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java?rev=350203&r1=350202&r2=350203&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java (original)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java Wed Nov 30 23:55:51 2005
@@ -1,8 +1,6 @@
 package org.apache.axis2.wsdl.java2wsdl;
 
 import org.apache.axis2.wsdl.builder.WSDLComponentFactory;
-import org.apache.axis2.wsdl.writer.WOMWriter;
-import org.apache.axis2.wsdl.writer.WOMWriterFactory;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.wsdl.*;
 import org.apache.wsdl.extensions.ExtensionConstants;
@@ -13,7 +11,6 @@
 import org.apache.wsdl.extensions.impl.SOAPOperationImpl;
 import org.apache.wsdl.impl.WSDLDescriptionImpl;
 import org.apache.xmlbeans.impl.jam.JMethod;
-import org.apache.xmlbeans.impl.jam.JParameter;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -23,6 +20,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.StringWriter;
 import java.util.HashMap;
+import java.util.Iterator;
 /*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
@@ -49,11 +47,21 @@
     private XmlSchema schema;
     private String serviceName;
 
-    public Java2WOM(TypeTable table, JMethod[] method, XmlSchema schema, String serviceName) {
+    public Java2WOM(TypeTable table, JMethod[] method, XmlSchema schema, String serviceName,
+                    String targentNamespece,
+                    String targetNamespecheprefix) {
         this.table = table;
         this.method = method;
         this.schema = schema;
         this.serviceName = serviceName;
+
+        if (targentNamespece != null && !targentNamespece.trim().equals("")) {
+            SchemaGenerator.TARGET_NAMESPACE = targentNamespece;
+        }
+        if (targetNamespecheprefix != null && !targetNamespecheprefix.trim().equals("")) {
+            SchemaGenerator.TARGET_NAMESPACE_PRFIX = targetNamespecheprefix;
+        }
+
     }
 
     public WSDLDescription generateWOM() throws Exception {
@@ -67,19 +75,29 @@
         WSDLDescription womDescription;
         WSDLComponentFactory wsdlComponentFactory = new WSDLDescriptionImpl();
         womDescription = wsdlComponentFactory.createDescription();
+        HashMap namspaseMap = new HashMap();
+        namspaseMap.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        namspaseMap.put(SchemaGenerator.TARGET_NAMESPACE_PRFIX, SchemaGenerator.TARGET_NAMESPACE);
+        namspaseMap.put("ns1", "http://org.apache.axis2/xsd");
+        namspaseMap.put("xs", "http://www.w3.org/2001/XMLSchema");
+        womDescription.setNamespaces(namspaseMap);
+        womDescription.setTargetNameSpace(SchemaGenerator.TARGET_NAMESPACE);
 
-        WOMWriter womWriter = WOMWriterFactory.createWriter(org.apache.axis2.wsdl.WSDLConstants.WSDL_1_1);
-        womWriter.setdefaultWSDLPrefix("wsdl");
-        womWriter.writeWOM(womDescription, System.out);
+        //generating port type
         WSDLInterface portType = generatePortType(womDescription, wsdlComponentFactory, documentElement);
+        womDescription.addInterface(portType);
 
         QName bindingName = new QName(SchemaGenerator.TARGET_NAMESPACE, serviceName + "Binding"
                 , SchemaGenerator.TARGET_NAMESPACE_PRFIX);
+        //generating binding
         WSDLBinding binding = genareteBinding(wsdlComponentFactory,
-                womDescription, portType,
+                portType,
                 bindingName,
-                method, "document", "literal", "http://schemas.xmlsoap.org/soap/http",
+                "document", "literal", "http://schemas.xmlsoap.org/soap/http",
                 "http://www.org.apache.axis2");
+        womDescription.addBinding(binding);
+
+        //generating service
         WSDLService service = generateService(wsdlComponentFactory, womDescription, binding, serviceName);
         womDescription.addService(service);
         return womDescription;
@@ -88,14 +106,6 @@
     public WSDLInterface generatePortType(WSDLDescription womDescription,
                                           WSDLComponentFactory wsdlComponentFactory,
                                           Element documentElement) {
-        HashMap namspaseMap = new HashMap();
-        namspaseMap.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
-        namspaseMap.put(SchemaGenerator.TARGET_NAMESPACE_PRFIX, SchemaGenerator.TARGET_NAMESPACE);
-        namspaseMap.put("ns1", "http://org.apache.axis2/xsd");
-        namspaseMap.put("xs", "http://www.w3.org/2001/XMLSchema");
-        womDescription.setNamespaces(namspaseMap);
-
-        womDescription.setTargetNameSpace(SchemaGenerator.TARGET_NAMESPACE);
         WSDLTypes wsdlTypes = wsdlComponentFactory.createTypes();
         ExtensionFactory extensionFactory = wsdlComponentFactory.createExtensionFactory();
         org.apache.wsdl.extensions.Schema schemaExtensibilityElement =
@@ -107,7 +117,7 @@
 
         WSDLInterface portType = womDescription.createInterface();
         portType.setName(new QName(serviceName + "Port"));
-        womDescription.addInterface(portType);
+//        womDescription.addInterface(portType);
         //adding message refs
         for (int i = 0; i < method.length; i++) {
             JMethod jmethod = method[i];
@@ -116,25 +126,12 @@
             operation.setName(new QName(jmethod.getSimpleName()));
 
             MessageReference messageRefinput = wsdlComponentFactory.createMessageReference();
-            JParameter [] paras = jmethod.getParameters();
-            QName typeName = null;
-            boolean addMessage = false;
-            if (paras.length == 0) {
-                //todo have to fix this, method take no arugment
-//                } else if (paras.length == 1) {
-//                    typeName = table.getQNamefortheType(paras[0].getType().getQualifiedName());
-//                    addMessage = true;
-            } else {
-                typeName = table.getComplexScheamType(jmethod.getSimpleName() +
-                        SchemaGenerator.METHOD_REQUEST_WRAPPER);
-                addMessage = true;
-            }
-            if (addMessage) {
-                messageRefinput.setElementQName(typeName);
-                messageRefinput.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
-                operation.setInputMessage(messageRefinput);
-                portType.setOperation(operation);
-            }
+            QName typeName = table.getComplexScheamType(jmethod.getSimpleName() +
+                    SchemaGenerator.METHOD_REQUEST_WRAPPER);
+            messageRefinput.setElementQName(typeName);
+            messageRefinput.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
+            operation.setInputMessage(messageRefinput);
+            portType.setOperation(operation);
 
             if (!jmethod.getReturnType().isVoidType()) {
                 MessageReference messageRefiout = wsdlComponentFactory.createMessageReference();
@@ -217,5 +214,64 @@
         service.setEndpoint(endpoints);
         return service;
     }
+
+
+    private WSDLBinding genareteBinding(WSDLComponentFactory wsdlComponentFactory,
+                                        WSDLInterface portType, QName bindingName,
+                                        String style,
+                                        String use,
+                                        String trsportURI,
+                                        String namespeceURI) {
+        WSDLBinding binding = wsdlComponentFactory.createBinding();
+        binding.setBoundInterface(portType);
+        binding.setName(bindingName);
+
+        SOAPBindingImpl soapbindingImpl = new SOAPBindingImpl();
+        soapbindingImpl.setStyle(style);
+        soapbindingImpl.setTransportURI(trsportURI);
+        binding.addExtensibilityElement(soapbindingImpl);
+
+        Iterator op_itr = portType.getOperations().keySet().iterator();
+        while (op_itr.hasNext()) {
+            String opName = (String) op_itr.next();
+            WSDLOperation wsdlOperation = portType.getOperation(opName);
+            MessageReference inMessage = wsdlOperation.getInputMessage();
+
+            WSDLBindingOperation bindingoperation = wsdlComponentFactory.createWSDLBindingOperation();
+            bindingoperation.setName(new QName(opName));
+            bindingoperation.setOperation(wsdlOperation);
+            binding.addBindingOperation(bindingoperation);
+
+            SOAPOperationImpl soapOpimpl = new SOAPOperationImpl();
+            soapOpimpl.setStyle(style);
+            //to do heve to set a proper SOAPAction
+            soapOpimpl.setSoapAction(opName);
+            bindingoperation.addExtensibilityElement(soapOpimpl);
+            if (inMessage != null) {
+                WSDLBindingMessageReference bindingInMessage = wsdlComponentFactory.createWSDLBindingMessageReference();
+                bindingInMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
+                bindingoperation.setInput(bindingInMessage);
+                SOAPBodyImpl requestSoapbody = new SOAPBodyImpl();
+                requestSoapbody.setUse(use);
+                //todo need to fix this
+                requestSoapbody.setNamespaceURI(namespeceURI);
+                bindingInMessage.addExtensibilityElement(requestSoapbody);
+            }
+
+            MessageReference outMessage = wsdlOperation.getOutputMessage();
+            if (outMessage != null) {
+                WSDLBindingMessageReference bindingOutMessage = wsdlComponentFactory.createWSDLBindingMessageReference();
+
+                bindingOutMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
+                bindingoperation.setOutput(bindingOutMessage);
+                SOAPBodyImpl resSoapbody = new SOAPBodyImpl();
+                resSoapbody.setUse(use);
+                resSoapbody.setNamespaceURI(namespeceURI);
+                bindingOutMessage.addExtensibilityElement(resSoapbody);
+            }
+        }
+        return binding;
+    }
+
 
 }

Modified: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java?rev=350203&r1=350202&r2=350203&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java (original)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java Wed Nov 30 23:55:51 2005
@@ -39,10 +39,10 @@
     }
 
     public void generateWSDL() throws Exception {
-        SchemaGenerator sg = new SchemaGenerator(classLoader, className);
+        SchemaGenerator sg = new SchemaGenerator(classLoader, className,null,null);
         XmlSchema scheam = sg.generateSchema();
         WSDLDescription wommodel = new Java2WOM(
-                sg.getTypeTable(), sg.getMethods(), scheam, className).generateWOM();
+                sg.getTypeTable(), sg.getMethods(), scheam, className,null,null).generateWOM();
         WOMWriter womWriter = WOMWriterFactory.createWriter(WSDLConstants.WSDL_1_1);
         womWriter.setdefaultWSDLPrefix("wsdl");
         womWriter.writeWOM(wommodel, out);

Modified: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java?rev=350203&r1=350202&r2=350203&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java (original)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java Wed Nov 30 23:55:51 2005
@@ -38,12 +38,20 @@
     public static String TARGET_NAMESPACE = null;
     public static String SCHEMA_TARGET_NAMESPASE = "http://org.apache.axis2/xsd";
     public static String SCHEMA_NAMESPASE_PRFIX = "ns1";
-    public static final String TARGET_NAMESPACE_PRFIX = "tns";
+    public static String TARGET_NAMESPACE_PRFIX = "tns";
 
-    public SchemaGenerator(ClassLoader loader, String className) {
+    public SchemaGenerator(ClassLoader loader, String className,
+                           String scheamtargetNamespace,
+                           String scheamtargetNamespacePrefix) {
         this.classLoader = loader;
         this.className = className;
         TARGET_NAMESPACE = "http://" + className;
+        if (scheamtargetNamespace != null && !scheamtargetNamespace.trim().equals("")) {
+            SCHEMA_TARGET_NAMESPASE = scheamtargetNamespace;
+        }
+        if (scheamtargetNamespacePrefix != null && !scheamtargetNamespacePrefix.trim().equals("")) {
+            SCHEMA_NAMESPASE_PRFIX = scheamtargetNamespacePrefix;
+        }
 
         prefixmap = new Hashtable();
         prefixmap.put(SCHEMA_NAMESPASE_PRFIX, SCHEMA_TARGET_NAMESPASE);
@@ -56,6 +64,13 @@
         this.typeTable = new TypeTable();
     }
 
+    /**
+     * To generate schema for all the parameters in method , first generate scheam for all diffrent
+     * paramter type and latter refferd them
+     *
+     * @return
+     * @throws Exception
+     */
     public XmlSchema generateSchema() throws Exception {
 
         JamServiceFactory factory = JamServiceFactory.getInstance();
@@ -69,10 +84,9 @@
 
         JamClassIterator jClassIter = service.getClasses();
         //all most all the time the ittr will have only one class in it
-        String serviceName;
         while (jClassIter.hasNext()) {
             JClass jclass = (JClass) jClassIter.next();
-            serviceName = jclass.getSimpleName();
+            // serviceName = jclass.getSimpleName();
             //todo in the future , when we support annotation we can use this
             //JAnnotation[] annotations = jclass.getAnnotations();
 
@@ -94,26 +108,38 @@
                 JParameter [] paras = jMethod.getParameters();
                 for (int j = 0; j < paras.length; j++) {
                     JParameter methodParamter = paras[j];
-                    String classTypeName = methodParamter.getType().getQualifiedName();
+                    JClass paraType = methodParamter.getType();
+                    String classTypeName = paraType.getQualifiedName();
+                    if (paraType.isArrayType()) {
+                        classTypeName = paraType.getArrayComponentType().getQualifiedName();
+                        if (!typeTable.isSimpleType(classTypeName)) {
+                            generateSchema(paraType.getArrayComponentType());
+                        }
+                    } else {
+                        if (!typeTable.isSimpleType(classTypeName)) {
+                            generateSchema(methodParamter.getType());
+                        }
+                    }
                     /**
                      * 1. have to check whethet its a simple type
                      * 2. then to check whther its a simple type array
                      * 3. OM elemney
                      * 4. Bean
                      */
-                    if (typeTable.isSimpleType(classTypeName)) {
-                    } else {
-                        //todo this need to be improved to check OMElement sa well
-                        generateSchema(methodParamter.getType());
-                    }
+
                 }
                 // for its return type
                 JClass retuenType = jMethod.getReturnType();
                 if (!retuenType.isVoidType()) {
-                    if (typeTable.isSimpleType(retuenType.getQualifiedName())) {
+                    if (retuenType.isArrayType()) {
+                        String returnTypeName = retuenType.getArrayComponentType().getQualifiedName();
+                        if (!typeTable.isSimpleType(returnTypeName)) {
+                            generateSchema(retuenType.getArrayComponentType());
+                        }
                     } else {
-                        //todo this need to be improved to check OMElement sa well
-                        generateSchema(retuenType);
+                        if (!typeTable.isSimpleType(retuenType.getQualifiedName())) {
+                            generateSchema(retuenType);
+                        }
                     }
                 }
 
@@ -139,10 +165,7 @@
     private void generateWrapperElements(JMethod methods[]) {
         for (int i = 0; i < methods.length; i++) {
             JMethod method = methods[i];
-            JParameter [] paras = method.getParameters();
-            // if (paras.length > 1) {
             genereteWrapperElementforMethod(method);
-//            }
         }
     }
 
@@ -153,7 +176,6 @@
 
         XmlSchemaElement eltOuter = new XmlSchemaElement();
         eltOuter.setName(methodName + METHOD_REQUEST_WRAPPER);
-        complexType.setParticle(sequence);
 //        String complexTypeName = methodName + METHOD_REQUEST_WRAPPER;
 //        complexType.setName(complexTypeName);
         schema.getItems().add(eltOuter);
@@ -162,10 +184,14 @@
         eltOuter.setSchemaType(complexType);
         // adding this type to the table
         //todo pls ask this from Ajith
-        QName comTypeName = new QName(SchemaGenerator.SCHEMA_TARGET_NAMESPASE, eltOuter.getName(), SCHEMA_NAMESPASE_PRFIX);
-        typeTable.addComplexScheam(methodName + METHOD_REQUEST_WRAPPER, comTypeName);
+        QName elementName = new QName(SchemaGenerator.SCHEMA_TARGET_NAMESPASE,
+                eltOuter.getName(), SCHEMA_NAMESPASE_PRFIX);
+        typeTable.addComplexScheam(methodName + METHOD_REQUEST_WRAPPER, elementName);
 
         JParameter [] paras = method.getParameters();
+        if (paras.length > 0) {
+            complexType.setParticle(sequence);
+        }
         for (int j = 0; j < paras.length; j++) {
             JParameter methodParamter = paras[j];
             String classTypeName = methodParamter.getType().getQualifiedName();
@@ -305,5 +331,5 @@
     public JMethod[] getMethods() {
         return methods;
     }
-    
+
 }

Modified: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java?rev=350203&r1=350202&r2=350203&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java (original)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java Wed Nov 30 23:55:51 2005
@@ -1,8 +1,9 @@
 package org.apache.axis2.wsdl.java2wsdl;
 
+import org.apache.axis2.om.OMElement;
+
 import javax.xml.namespace.QName;
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.*;
 /*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
@@ -74,6 +75,16 @@
                 new QName("http://www.w3.org/2001/XMLSchema", "dateTime", "xs"));
 
         simpleTypetoxsd.put("java.lang.Object",
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+
+        // Any types
+        simpleTypetoxsd.put(OMElement.class.getName(),
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+        simpleTypetoxsd.put(ArrayList.class.getName(),
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+        simpleTypetoxsd.put(Vector.class.getName(),
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+        simpleTypetoxsd.put(List.class.getName(),
                 new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
     }