axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r349929 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/deployment/ wsdl/src/org/apache/axis2/wsdl/java2wsdl/ wsdl/src/org/apache/axis2/wsdl/writer/
Date Wed, 30 Nov 2005 12:11:00 GMT
Author: deepal
Date: Wed Nov 30 04:10:37 2005
New Revision: 349929

URL: http://svn.apache.org/viewcvs?rev=349929&view=rev
Log:
 1. Added Java2wsdl codes (its not fully completed yet) , there are some code cleaning and
improvements.
    I checked the generated wsdl agings our WSDL2Java and it gave me accepted result. 

Added:
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java?rev=349929&r1=349928&r2=349929&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
Wed Nov 30 04:10:37 2005
@@ -492,7 +492,7 @@
                             String serviceStatus = "";
                             try {
                                 HashMap wsdlservice = archiveReader.processWSDLs(currentArchiveFile,
this);
-                                // AxisService service = archiveReader.createService(currentArchiveFile.getAbsolutePath());
+                                // AxisService service = archiveReader.generateService(currentArchiveFile.getAbsolutePath());
                                 AxisServiceGroup sericeGroup =
                                         new AxisServiceGroup(axisConfig);
                                 sericeGroup.setServiceGroupClassLoader(axisConfig.getServiceClassLoader());

Added: 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=349929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java
(added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WOM.java
Wed Nov 30 04:10:37 2005
@@ -0,0 +1,221 @@
+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;
+import org.apache.wsdl.extensions.ExtensionFactory;
+import org.apache.wsdl.extensions.impl.SOAPAddressImpl;
+import org.apache.wsdl.extensions.impl.SOAPBindingImpl;
+import org.apache.wsdl.extensions.impl.SOAPBodyImpl;
+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;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+import java.util.HashMap;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class Java2WOM {
+
+    private TypeTable table;
+    private JMethod method [];
+    private XmlSchema schema;
+    private String serviceName;
+
+    public Java2WOM(TypeTable table, JMethod[] method, XmlSchema schema, String serviceName)
{
+        this.table = table;
+        this.method = method;
+        this.schema = schema;
+        this.serviceName = serviceName;
+    }
+
+    public WSDLDescription generateWOM() throws Exception {
+        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
+        StringWriter writer = new StringWriter();
+        schema.write(writer);
+        writer.flush();
+        Document doc = domBuilder.parse(new ByteArrayInputStream(writer.toString().getBytes()));
+        Element documentElement = doc.getDocumentElement();
+        WSDLDescription womDescription;
+        WSDLComponentFactory wsdlComponentFactory = new WSDLDescriptionImpl();
+        womDescription = wsdlComponentFactory.createDescription();
+
+        WOMWriter womWriter = WOMWriterFactory.createWriter(org.apache.axis2.wsdl.WSDLConstants.WSDL_1_1);
+        womWriter.setdefaultWSDLPrefix("wsdl");
+        womWriter.writeWOM(womDescription, System.out);
+        WSDLInterface portType = generatePortType(womDescription, wsdlComponentFactory, documentElement);
+
+        QName bindingName = new QName(SchemaGenerator.TARGET_NAMESPACE, serviceName + "Binding"
+                , SchemaGenerator.TARGET_NAMESPACE_PRFIX);
+        WSDLBinding binding = genareteBinding(wsdlComponentFactory,
+                womDescription, portType,
+                bindingName,
+                method, "document", "literal", "http://schemas.xmlsoap.org/soap/http",
+                "http://www.org.apache.axis2");
+        WSDLService service = generateService(wsdlComponentFactory, womDescription, binding,
serviceName);
+        womDescription.addService(service);
+        return womDescription;
+    }
+
+    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 =
+                (org.apache.wsdl.extensions.Schema) extensionFactory.getExtensionElement(
+                        ExtensionConstants.SCHEMA);
+        wsdlTypes.addExtensibilityElement(schemaExtensibilityElement);
+        schemaExtensibilityElement.setElement(documentElement);
+        womDescription.setTypes(wsdlTypes);
+
+        WSDLInterface portType = womDescription.createInterface();
+        portType.setName(new QName(serviceName + "Port"));
+        womDescription.addInterface(portType);
+        //adding message refs
+        for (int i = 0; i < method.length; i++) {
+            JMethod jmethod = method[i];
+            //creating WSDLOperation
+            WSDLOperation operation = womDescription.createOperation();
+            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);
+            }
+
+            if (!jmethod.getReturnType().isVoidType()) {
+                MessageReference messageRefiout = wsdlComponentFactory.createMessageReference();
+                messageRefiout.setElementQName(table.getQNamefortheType(jmethod.getSimpleName()
+
+                        SchemaGenerator.METHOD_RESPONSE_WRAPPER));
+                messageRefiout.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
+                operation.setOutputMessage(messageRefiout);
+            }
+        }
+        return portType;
+    }
+
+    private WSDLBinding genareteBinding(WSDLComponentFactory wsdlComponentFactory,
+                                        WSDLDescription womDescription,
+                                        WSDLInterface portType, QName bindingName,
+                                        JMethod metods[],
+                                        String style,
+                                        String use,
+                                        String trsportURI,
+                                        String namespeceURI) {
+        WSDLBinding binding = wsdlComponentFactory.createBinding();
+        binding.setBoundInterface(portType);
+        binding.setName(bindingName);
+        womDescription.addBinding(binding);
+
+        SOAPBindingImpl soapbindingImpl = new SOAPBindingImpl();
+        soapbindingImpl.setStyle(style);
+        soapbindingImpl.setTransportURI(trsportURI);
+        binding.addExtensibilityElement(soapbindingImpl);
+        for (int i = 0; i < metods.length; i++) {
+            JMethod jmethod = metods[i];
+            //creating WSDLOperation     for the binding
+            WSDLBindingOperation bindingoperation = wsdlComponentFactory.createWSDLBindingOperation();
+            String methodName = jmethod.getSimpleName();
+            bindingoperation.setName(new QName(methodName));
+            bindingoperation.setOperation(portType.getOperation(methodName));
+            binding.addBindingOperation(bindingoperation);
+
+            SOAPOperationImpl soapOpimpl = new SOAPOperationImpl();
+            soapOpimpl.setStyle(style);
+            //to do heve to set a proper SOAPAction
+            soapOpimpl.setSoapAction(jmethod.getSimpleName());
+            bindingoperation.addExtensibilityElement(soapOpimpl);
+
+            //creating imput message
+            WSDLBindingMessageReference inMessage = wsdlComponentFactory.createWSDLBindingMessageReference();
+            inMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
+            bindingoperation.setInput(inMessage);
+            SOAPBodyImpl requestSoapbody = new SOAPBodyImpl();
+            requestSoapbody.setUse(use);
+            //todo need to fix this
+            requestSoapbody.setNamespaceURI(namespeceURI);
+            inMessage.addExtensibilityElement(requestSoapbody);
+
+            if (!jmethod.getReturnType().isVoidType()) {
+                WSDLBindingMessageReference outMessage = wsdlComponentFactory.createWSDLBindingMessageReference();
+
+                outMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
+                bindingoperation.setOutput(outMessage);
+                SOAPBodyImpl resSoapbody = new SOAPBodyImpl();
+                resSoapbody.setUse(use);
+                resSoapbody.setNamespaceURI(namespeceURI);
+                outMessage.addExtensibilityElement(resSoapbody);
+            }
+        }
+        return binding;
+    }
+
+    public WSDLService generateService(WSDLComponentFactory wsdlComponentFactory,
+                                       WSDLDescription womDescription,
+                                       WSDLBinding binding, String ServiceName) {
+        WSDLService service = wsdlComponentFactory.createService();
+        service.setName(new QName(ServiceName));
+        WSDLEndpoint endpoints = wsdlComponentFactory.createEndpoint();
+        endpoints.setBinding(binding);
+        endpoints.setName(new QName(ServiceName + "PortType"));
+        SOAPAddressImpl address = new SOAPAddressImpl();
+        address.setLocationURI("http://127.0.0.1:8080:/axis2/services/" + ServiceName);
+        endpoints.addExtensibilityElement(address);
+        service.setEndpoint(endpoints);
+        return service;
+    }
+
+}

Added: 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=349929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java
(added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/Java2WSDL.java
Wed Nov 30 04:10:37 2005
@@ -0,0 +1,51 @@
+package org.apache.axis2.wsdl.java2wsdl;
+
+import org.apache.axis2.wsdl.WSDLConstants;
+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.WSDLDescription;
+
+import java.io.OutputStream;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class Java2WSDL {
+
+    private OutputStream out;
+    private String className;
+    private ClassLoader classLoader;
+
+    public Java2WSDL(OutputStream out, String className, ClassLoader classLoader) {
+        this.out = out;
+        this.className = className;
+        this.classLoader = classLoader;
+    }
+
+    public void generateWSDL() throws Exception {
+        SchemaGenerator sg = new SchemaGenerator(classLoader, className);
+        XmlSchema scheam = sg.generateSchema();
+        WSDLDescription wommodel = new Java2WOM(
+                sg.getTypeTable(), sg.getMethods(), scheam, className).generateWOM();
+        WOMWriter womWriter = WOMWriterFactory.createWriter(WSDLConstants.WSDL_1_1);
+        womWriter.setdefaultWSDLPrefix("wsdl");
+        womWriter.writeWOM(wommodel, out);
+
+    }
+}

Added: 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=349929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java
(added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/SchemaGenerator.java
Wed Nov 30 04:10:37 2005
@@ -0,0 +1,309 @@
+package org.apache.axis2.wsdl.java2wsdl;
+
+import org.apache.ws.commons.schema.*;
+import org.apache.xmlbeans.impl.jam.*;
+
+import javax.xml.namespace.QName;
+import java.util.Hashtable;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class SchemaGenerator {
+    private ClassLoader classLoader;
+    private String className;
+    Hashtable prefixmap;
+    XmlSchemaCollection schemaCollection;
+    XmlSchema schema;
+    TypeTable typeTable;
+    private JMethod methods [];
+
+    public static String METHOD_REQUEST_WRAPPER = "Request";
+    public static String METHOD_RESPONSE_WRAPPER = "Response";
+    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 SchemaGenerator(ClassLoader loader, String className) {
+        this.classLoader = loader;
+        this.className = className;
+        TARGET_NAMESPACE = "http://" + className;
+
+        prefixmap = new Hashtable();
+        prefixmap.put(SCHEMA_NAMESPASE_PRFIX, SCHEMA_TARGET_NAMESPASE);
+
+        schemaCollection = new XmlSchemaCollection();
+
+        schema = new XmlSchema(SCHEMA_TARGET_NAMESPASE, schemaCollection);
+        schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
+        schema.setPrefixToNamespaceMap(prefixmap);
+        this.typeTable = new TypeTable();
+    }
+
+    public XmlSchema generateSchema() throws Exception {
+
+        JamServiceFactory factory = JamServiceFactory.getInstance();
+        JamServiceParams jam_service_parms = factory.createServiceParams();
+        //setting the classLoder
+//        jam_service_parms.setParentClassLoader(factory.createJamClassLoader(classLoader));
+        //it can posible to add the classLoader as well
+        jam_service_parms.addClassLoader(classLoader);
+        jam_service_parms.includeClass(className);
+        JamService service = factory.createService(jam_service_parms);
+
+        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();
+            //todo in the future , when we support annotation we can use this
+            //JAnnotation[] annotations = jclass.getAnnotations();
+
+            /**
+             * Schema genertaion done in two stage
+             *  1. Load all the methods and create type for methods paramters (if the paramters
are
+             *     Bean then it will create Complex types for those , and if the paramters
are simple
+             *     type which decribe in SimpleTypeTable nothing will happen)
+             *  2. In the next stage for all the methods messages and port types will be
+             *     creteated
+             */
+            methods = jclass.getDeclaredMethods();
+
+            for (int i = 0; i < methods.length; i++) {
+                JMethod jMethod = methods[i];
+
+                //it can easily get the annotations
+//                jMethod.getAnnotations();
+                JParameter [] paras = jMethod.getParameters();
+                for (int j = 0; j < paras.length; j++) {
+                    JParameter methodParamter = paras[j];
+                    String classTypeName = methodParamter.getType().getQualifiedName();
+                    /**
+                     * 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())) {
+                    } else {
+                        //todo this need to be improved to check OMElement sa well
+                        generateSchema(retuenType);
+                    }
+                }
+
+            }
+            generateWrapperElements(methods);
+        }
+        return schema;
+    }
+
+    /**
+     * To generate wrapper element , if a method take more than one parameter
+     * if the method look like foo(Type1 para1, Type2 para2){}
+     * will creat e Wrapper element like
+     * <element name="fooInParameter type="tns:fooInParamterElement"">
+     * <complexType name="fooInParamterElement">
+     * <sequnce>
+     * <element name="para1" type="tns:Type1">
+     * <element name="para2" type="tns:Type2">
+     * </sequnce>
+     * </complexType>
+     * </element>
+     */
+    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);
+//            }
+        }
+    }
+
+    private void genereteWrapperElementforMethod(JMethod method) {
+        String methodName = method.getSimpleName();
+        XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
+        XmlSchemaSequence sequence = new XmlSchemaSequence();
+
+        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);
+//        schema.getItems().add(complexType);
+//        eltOuter.setSchemaTypeName(complexType.getQName());
+        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);
+
+        JParameter [] paras = method.getParameters();
+        for (int j = 0; j < paras.length; j++) {
+            JParameter methodParamter = paras[j];
+            String classTypeName = methodParamter.getType().getQualifiedName();
+            boolean isArryType = methodParamter.getType().isArrayType();
+            if (isArryType) {
+                classTypeName = methodParamter.getType().getArrayComponentType().getQualifiedName();
+            }
+            if (typeTable.isSimpleType(classTypeName)) {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(methodParamter.getSimpleName());
+                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            } else {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(methodParamter.getSimpleName());
+                elt1.setSchemaTypeName(typeTable.getComplexScheamType(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            }
+        }
+
+        //generating wrapper element for retuen element
+        JClass methodReturnType = method.getReturnType();
+        generateWrapperforReturnType(methodReturnType, methodName);
+
+    }
+
+    private void generateWrapperforReturnType(JClass retuenType, String methodName) {
+        if (!retuenType.isVoidType()) {
+            XmlSchemaComplexType retuen_com_type = new XmlSchemaComplexType(schema);
+            XmlSchemaElement ret_eltOuter = new XmlSchemaElement();
+            ret_eltOuter.setName(methodName + METHOD_RESPONSE_WRAPPER);
+            schema.getItems().add(ret_eltOuter);
+            ret_eltOuter.setSchemaType(retuen_com_type);
+            QName ret_comTypeName = new QName(SchemaGenerator.SCHEMA_TARGET_NAMESPASE,
+                    ret_eltOuter.getName(), SCHEMA_NAMESPASE_PRFIX);
+            typeTable.addComplexScheam(methodName + METHOD_RESPONSE_WRAPPER, ret_comTypeName);
+            String classTypeName = retuenType.getQualifiedName();
+            boolean isArryType = retuenType.isArrayType();
+            XmlSchemaSequence sequence = new XmlSchemaSequence();
+            retuen_com_type.setParticle(sequence);
+            if (isArryType) {
+                classTypeName = retuenType.getArrayComponentType().getQualifiedName();
+            }
+            if (typeTable.isSimpleType(classTypeName)) {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(retuenType.getSimpleName());
+                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            } else {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(methodName);
+                elt1.setSchemaTypeName(typeTable.getComplexScheamType(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            }
+        }
+    }
+
+
+    private void generateSchema(JClass javaType) {
+        String name = javaType.getQualifiedName();
+        if (typeTable.getComplexScheamType(name) == null) {
+            String simpleName = javaType.getSimpleName();
+
+            XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
+            XmlSchemaSequence sequence = new XmlSchemaSequence();
+
+            XmlSchemaElement eltOuter = new XmlSchemaElement();
+//            QName elemntName = new QName(SCHEMA_TARGET_NAMESPASE, simpleName + "Wrapper",
SCHEMA_NAMESPASE_PRFIX);
+            QName elemntName = new QName(SCHEMA_TARGET_NAMESPASE, simpleName, SCHEMA_NAMESPASE_PRFIX);
+//            eltOuter.setName(simpleName + "Wrapper");
+            eltOuter.setName(simpleName);
+            eltOuter.setQName(elemntName);
+            complexType.setParticle(sequence);
+            complexType.setName(simpleName);
+
+            schema.getItems().add(eltOuter);
+            schema.getItems().add(complexType);
+            eltOuter.setSchemaTypeName(complexType.getQName());
+//            System.out.println("QNAme: " + eltOuter.getQName().getPrefix());
+
+            // adding this type to the table
+            //  typeTable.addComplexScheam(name, complexType.getQName());
+            typeTable.addComplexScheam(name, eltOuter.getQName());
+
+            JProperty [] properties = javaType.getDeclaredProperties();
+            for (int i = 0; i < properties.length; i++) {
+                JProperty property = properties[i];
+                String propertyName = property.getType().getQualifiedName();
+                boolean isArryType = property.getType().isArrayType();
+                if (isArryType) {
+                    propertyName = property.getType().getArrayComponentType().getQualifiedName();
+                }
+                if (typeTable.isSimpleType(propertyName)) {
+                    XmlSchemaElement elt1 = new XmlSchemaElement();
+                    elt1.setName(property.getSimpleName());
+                    elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(propertyName));
+                    sequence.getItems().add(elt1);
+                    if (isArryType) {
+                        //todo pls check this with Ajith
+                        elt1.setMaxOccurs(Long.MAX_VALUE);
+//                        elt1.setMinOccurs(2);
+                    }
+                } else {
+                    if (isArryType) {
+                        generateSchema(property.getType().getArrayComponentType());
+                    } else {
+                        generateSchema(property.getType());
+                    }
+                    XmlSchemaElement elt1 = new XmlSchemaElement();
+                    elt1.setName(property.getSimpleName());
+                    elt1.setSchemaTypeName(typeTable.getComplexScheamType(propertyName));
+                    sequence.getItems().add(elt1);
+                    if (isArryType) {
+                        elt1.setMaxOccurs(Long.MAX_VALUE);
+                    }
+                }
+            }
+        }
+    }
+
+    public TypeTable getTypeTable() {
+        return typeTable;
+    }
+
+    public JMethod[] getMethods() {
+        return methods;
+    }
+    
+}
\ No newline at end of file

Added: 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=349929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java
(added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/TypeTable.java
Wed Nov 30 04:10:37 2005
@@ -0,0 +1,111 @@
+package org.apache.axis2.wsdl.java2wsdl;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Iterator;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+* @author : Deepal Jayasinghe (deepal@apache.org)
+*
+*/
+
+public class TypeTable {
+    private HashMap simpleTypetoxsd;
+    private HashMap complecTypeMap;
+
+    public TypeTable() {
+        simpleTypetoxsd = new HashMap();
+        complecTypeMap = new HashMap();
+        populateSimpleTypes();
+    }
+
+    private void populateSimpleTypes() {
+        //todo pls use the types from org.apache.ws.commons.schema.constants.Constants
+        simpleTypetoxsd.put("int",
+                new QName("http://www.w3.org/2001/XMLSchema", "int", "xs"));
+        simpleTypetoxsd.put("java.lang.String",
+                new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"));
+        simpleTypetoxsd.put("boolean",
+                new QName("http://www.w3.org/2001/XMLSchema", "boolean", "xs"));
+        simpleTypetoxsd.put("float",
+                new QName("http://www.w3.org/2001/XMLSchema", "float", "xs"));
+        simpleTypetoxsd.put("double",
+                new QName("http://www.w3.org/2001/XMLSchema", "double", "xs"));
+        simpleTypetoxsd.put("short",
+                new QName("http://www.w3.org/2001/XMLSchema", "short", "xs"));
+        simpleTypetoxsd.put("long",
+                new QName("http://www.w3.org/2001/XMLSchema", "long", "xs"));
+        simpleTypetoxsd.put("byte",
+                new QName("http://www.w3.org/2001/XMLSchema", "byte", "xs"));
+        simpleTypetoxsd.put("char",
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+        simpleTypetoxsd.put("java.lang.Integer",
+                new QName("http://www.w3.org/2001/XMLSchema", "int", "xs"));
+        simpleTypetoxsd.put("java.lang.Double",
+                new QName("http://www.w3.org/2001/XMLSchema", "double", "xs"));
+        simpleTypetoxsd.put("java.lang.Float",
+                new QName("http://www.w3.org/2001/XMLSchema", "float", "xs"));
+        simpleTypetoxsd.put("java.lang.Long",
+                new QName("http://www.w3.org/2001/XMLSchema", "long", "xs"));
+        simpleTypetoxsd.put("java.lang.Character",
+                new QName("http://www.w3.org/2001/XMLSchema", "anyType", "xs"));
+        simpleTypetoxsd.put("java.lang.Boolean",
+                new QName("http://www.w3.org/2001/XMLSchema", "boolean", "xs"));
+        simpleTypetoxsd.put("java.lang.Byte",
+                new QName("http://www.w3.org/2001/XMLSchema", "byte", "xs"));
+        simpleTypetoxsd.put("java.lang.Short",
+                new QName("http://www.w3.org/2001/XMLSchema", "short", "xs"));
+        simpleTypetoxsd.put("java.util.Date",
+                new QName("http://www.w3.org/2001/XMLSchema", "dateTime", "xs"));
+        simpleTypetoxsd.put("java.util.Calendar",
+                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"));
+    }
+
+    public QName getSimpleSchemaTypeName(String typename) {
+        return (QName) simpleTypetoxsd.get(typename);
+    }
+
+    public boolean isSimpleType(String typeName) {
+        Iterator keys = simpleTypetoxsd.keySet().iterator();
+        while (keys.hasNext()) {
+            String s = (String) keys.next();
+            if (s.equals(typeName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public void addComplexScheam(String name, QName scheamType) {
+        complecTypeMap.put(name, scheamType);
+    }
+
+    public QName getComplexScheamType(String name) {
+        return (QName) complecTypeMap.get(name);
+    }
+
+    public QName getQNamefortheType(String typeName) {
+        QName type = getSimpleSchemaTypeName(typeName);
+        if (type == null) {
+            type = getComplexScheamType(typeName);
+        }
+        return type;
+    }
+}
+

Modified: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java?rev=349929&r1=349928&r2=349929&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java
(original)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java
Wed Nov 30 04:10:37 2005
@@ -547,8 +547,8 @@
 
     //to write scheam types into output straem
     private void writeScheams(Element element) throws XMLStreamException {
+        writer.flush();
         String scheamTypes = DOM2Writer.nodeToString(element);
-        System.out.println(scheamTypes);
         XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new
                 ByteArrayInputStream(scheamTypes.getBytes()));
         OMFactory fac = OMAbstractFactory.getOMFactory();
@@ -556,6 +556,7 @@
         StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
         OMElement scheamElement = staxOMBuilder.getDocumentElement();
         scheamElement.serialize(new OMOutputImpl(writer));
+       // writer.flush();
     }
 
     /**



Mime
View raw message