axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r357670 - in /webservices/axis2/trunk/java/modules: common/src/org/apache/axis2/i18n/ core/src/org/apache/axis2/context/ wsdl/src/org/apache/axis2/wsdl/java2wsdl/ wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/
Date Mon, 19 Dec 2005 09:19:41 GMT
Author: deepal
Date: Mon Dec 19 01:19:21 2005
New Revision: 357670

URL: http://svn.apache.org/viewcvs?rev=357670&view=rev
Log:
1. Coping byte code reading from Axis 1.x for java2wsdl
2. removing un-used code from Java2WOM
3. code improvement in configuration context factory  

Added:
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ChainedParamReader.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ClassReader.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/MethodTable.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamNameExtractor.java
    webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamReader.java
Modified:
    webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
    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/SchemaGenerator.java

Modified: webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties?rev=357670&r1=357669&r2=357670&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/i18n/resource.properties Mon Dec 19 01:19:21 2005
@@ -134,4 +134,9 @@
 failedJMSConnectorShutdown=failure in JMSConnectorShutdown
 #outMessageNull=Out message is null
 malformedURLException00=MalformedURLException:
-exception00=Exception:
\ No newline at end of file
+exception00=Exception:
+#Byte code reading for Java2WSDL
+badClassFile00=Error looking for paramter names in bytecode: input does not appear to be a valid class file
+cantLoadByecode=Unable to load bytecode for class "{0}"
+unexpectedEOF00=Error looking for paramter names in bytecode: unexpected end of file
+unexpectedBytes00=Error looking for paramter names in bytecode: unexpected bytes in file
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java?rev=357670&r1=357669&r2=357670&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java Mon Dec 19 01:19:21 2005
@@ -24,6 +24,24 @@
     private Log log = LogFactory.getLog(getClass());
 
     /**
+     * To create a AxisConfiguration depending on the user requiremnt , this method can be used.
+     * First create a AxisConfigurationCreator object giving necessary parameters into it.
+     * Depending on the implementation getAxisConfiguration(); will give the AxisConfiguration and
+     * using the ConfigurationContext will be created and return that.
+     *
+     * @param axisConfigurationCreator
+     * @return
+     * @throws AxisFault
+     */
+    public ConfigurationContext getConfigurationContext(
+            AxisConfigurationCreator axisConfigurationCreator) throws AxisFault {
+        AxisConfiguration axisConfig = axisConfigurationCreator.getAxisConfiguration();
+        ConfigurationContext configContext = new ConfigurationContext(axisConfig);
+        init(configContext);
+        return configContext;
+    }
+
+    /**
      * Builds the configuration for the client.
      *
      * @param axis2home the value can be null and resolves to the default axis2.xml file
@@ -33,12 +51,7 @@
     public ConfigurationContext buildClientConfigurationContext(String axis2home) throws AxisFault {
         AxisConfigurationCreator repoBasedConfigCreator =
                 new FileSystemConfigurationCreator(axis2home, false);
-        AxisConfiguration axisConfig = repoBasedConfigCreator.getAxisConfiguration();
-        ConfigurationContext configurationContext = new ConfigurationContext(axisConfig);
-
-        init(configurationContext);
-
-        return configurationContext;
+        return getConfigurationContext(repoBasedConfigCreator);
     }
 
     /**
@@ -51,12 +64,8 @@
     public ConfigurationContext buildConfigurationContext(String repositoryName) throws AxisFault {
         AxisConfigurationCreator repoBasedConfigCreator =
                 new FileSystemConfigurationCreator(repositoryName, true);
-        AxisConfiguration axisConfig = repoBasedConfigCreator.getAxisConfiguration();
-        ConfigurationContext configurationContext = new ConfigurationContext(axisConfig);
-
-        init(configurationContext);
+        return getConfigurationContext(repoBasedConfigCreator);
 
-        return configurationContext;
     }
 
     /**
@@ -145,17 +154,6 @@
                 }
             }
         }
-    }
-
-    public ConfigurationContext getConfigurationContext(
-            AxisConfigurationCreator axisConfigurationCreator)
-            throws AxisFault {
-        AxisConfiguration axisConfig = axisConfigurationCreator.getAxisConfiguration();
-        ConfigurationContext configContext = new ConfigurationContext(axisConfig);
-
-        init(configContext);
-
-        return configContext;
     }
 
     /**

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=357670&r1=357669&r2=357670&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 Mon Dec 19 01:19:21 2005
@@ -142,62 +142,6 @@
         return portType;
     }
 
-    private WSDLBinding generateBinding(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) {

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=357670&r1=357669&r2=357670&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 Mon Dec 19 01:19:21 2005
@@ -1,321 +1,348 @@
-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.
-*
-*/
-
-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_NAMESPACE = "http://ws.apache.org/axis2/xsd";
-    public static String SCHEMA_NAMESPACE_PREFIX = "ns1";
-    public static String TARGET_NAMESPACE_PREFIX = "tns";
-
-    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_NAMESPACE = scheamtargetNamespace;
-        }
-        if (scheamtargetNamespacePrefix != null && !scheamtargetNamespacePrefix.trim().equals("")) {
-            SCHEMA_NAMESPACE_PREFIX = scheamtargetNamespacePrefix;
-        }
-
-        prefixmap = new Hashtable();
-        prefixmap.put(SCHEMA_NAMESPACE_PREFIX, SCHEMA_TARGET_NAMESPACE);
-
-        schemaCollection = new XmlSchemaCollection();
-
-        schema = new XmlSchema(SCHEMA_TARGET_NAMESPACE, schemaCollection);
-        schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
-        schema.setPrefixToNamespaceMap(prefixmap);
-        this.typeTable = new TypeTable();
-    }
-
-    /**
-     * Generates schema for all the parameters in method. It first generates schema for all different
-     * parameter type and later refers to them.
-     *
-     * @return Returns XmlSchema
-     * @throws Exception
-     */
-    public XmlSchema generateSchema() throws Exception {
-
-        JamServiceFactory factory = JamServiceFactory.getInstance();
-        JamServiceParams jam_service_parms = factory.createServiceParams();
-
-        //it can possible 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
-        while (jClassIter.hasNext()) {
-            JClass jclass = (JClass) jClassIter.next();
-
-            //todo in the future , when we support annotation we can use this
-            //JAnnotation[] annotations = jclass.getAnnotations();
-
-            /**
-             * Schema generation done in two stage
-             *  1. Load all the methods and create type for methods parameters (if the parameters are
-             *     Beans then it will create Complex types for those , and if the parameters are simple
-             *     type which described in SimpleTypeTable nothing will happen)
-             *  2. In the next stage for all the methods messages and port types will be
-             *     created.
-             */
-            methods = jclass.getDeclaredMethods();
-
-            for (int i = 0; i < methods.length; i++) {
-                JMethod jMethod = methods[i];
-
-                JParameter [] params = jMethod.getParameters();
-                for (int j = 0; j < params.length; j++) {
-                    JParameter methodParameter = params[j];
-                    JClass paramType = methodParameter.getType();
-                    String classTypeName = paramType.getQualifiedName();
-                    if (paramType.isArrayType()) {
-                        classTypeName = paramType.getArrayComponentType().getQualifiedName();
-                        if (!typeTable.isSimpleType(classTypeName)) {
-                            generateSchema(paramType.getArrayComponentType());
-                        }
-                    } else {
-                        if (!typeTable.isSimpleType(classTypeName)) {
-                            generateSchema(methodParameter.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
-                     */
-
-                }
-                // for its return type
-                JClass returnType = jMethod.getReturnType();
-                if (!returnType.isVoidType()) {
-                    if (returnType.isArrayType()) {
-                        String returnTypeName = returnType.getArrayComponentType().getQualifiedName();
-                        if (!typeTable.isSimpleType(returnTypeName)) {
-                            generateSchema(returnType.getArrayComponentType());
-                        }
-                    } else {
-                        if (!typeTable.isSimpleType(returnType.getQualifiedName())) {
-                            generateSchema(returnType);
-                        }
-                    }
-                }
-
-            }
-            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:fooInParameterElement"">
-     * <complexType name="fooInParameterElement">
-     * <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];
-            generateWrapperElementforMethod(method);
-        }
-    }
-
-    private void generateWrapperElementforMethod(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);
-        schema.getItems().add(eltOuter);
-        eltOuter.setSchemaType(complexType);
-        // adding this type to the table
-        //todo pls ask this from Ajith
-        QName elementName = new QName(SchemaGenerator.SCHEMA_TARGET_NAMESPACE,
-                eltOuter.getName(), SCHEMA_NAMESPACE_PREFIX);
-        typeTable.addComplexScheam(methodName + METHOD_REQUEST_WRAPPER, elementName);
-
-        JParameter [] params = method.getParameters();
-        if (params.length > 0) {
-            complexType.setParticle(sequence);
-        }
-        for (int j = 0; j < params.length; j++) {
-            JParameter methodParameter = params[j];
-            String classTypeName = methodParameter.getType().getQualifiedName();
-            boolean isArrayType = methodParameter.getType().isArrayType();
-            if (isArrayType) {
-                classTypeName = methodParameter.getType().getArrayComponentType().getQualifiedName();
-            }
-            if (typeTable.isSimpleType(classTypeName)) {
-                XmlSchemaElement elt1 = new XmlSchemaElement();
-                elt1.setName(methodParameter.getSimpleName());
-                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
-                sequence.getItems().add(elt1);
-                if (isArrayType) {
-                    elt1.setMaxOccurs(Long.MAX_VALUE);
-                }
-            } else {
-                XmlSchemaElement elt1 = new XmlSchemaElement();
-                elt1.setName(methodParameter.getSimpleName());
-                elt1.setSchemaTypeName(typeTable.getComplexScheamType(classTypeName));
-                sequence.getItems().add(elt1);
-                if (isArrayType) {
-                    elt1.setMaxOccurs(Long.MAX_VALUE);
-                }
-            }
-        }
-
-        //generating wrapper element for return element
-        JClass methodReturnType = method.getReturnType();
-        generateWrapperforReturnType(methodReturnType, methodName);
-
-    }
-
-    private void generateWrapperforReturnType(JClass returnType, String methodName) {
-        if (!returnType.isVoidType()) {
-            XmlSchemaComplexType return_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(return_com_type);
-            QName ret_comTypeName = new QName(SchemaGenerator.SCHEMA_TARGET_NAMESPACE,
-                    ret_eltOuter.getName(), SCHEMA_NAMESPACE_PREFIX);
-            typeTable.addComplexScheam(methodName + METHOD_RESPONSE_WRAPPER, ret_comTypeName);
-            String classTypeName = returnType.getQualifiedName();
-            boolean isArrayType = returnType.isArrayType();
-            XmlSchemaSequence sequence = new XmlSchemaSequence();
-            return_com_type.setParticle(sequence);
-            if (isArrayType) {
-                classTypeName = returnType.getArrayComponentType().getQualifiedName();
-            }
-            if (typeTable.isSimpleType(classTypeName)) {
-                XmlSchemaElement elt1 = new XmlSchemaElement();
-                elt1.setName("return");
-                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
-                sequence.getItems().add(elt1);
-                if (isArrayType) {
-                    elt1.setMaxOccurs(Long.MAX_VALUE);
-                }
-            } else {
-                XmlSchemaElement elt1 = new XmlSchemaElement();
-                elt1.setName("return");
-                elt1.setSchemaTypeName(typeTable.getComplexScheamType(classTypeName));
-                sequence.getItems().add(elt1);
-                if (isArrayType) {
-                    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_NAMESPACE, simpleName, SCHEMA_NAMESPACE_PREFIX);
-            eltOuter.setName(simpleName);
-            eltOuter.setQName(elemntName);
-            complexType.setParticle(sequence);
-            complexType.setName(simpleName);
-
-            schema.getItems().add(eltOuter);
-            schema.getItems().add(complexType);
-            eltOuter.setSchemaTypeName(complexType.getQName());
-
-            // adding this type to the table
-            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 isArrayType = property.getType().isArrayType();
-                if (isArrayType) {
-                    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 (isArrayType) {
-                        //todo pls check this with Ajith
-                        elt1.setMaxOccurs(Long.MAX_VALUE);
-                    }
-                } else {
-                    if (isArrayType) {
-                        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 (isArrayType) {
-                        elt1.setMaxOccurs(Long.MAX_VALUE);
-                    }
-                }
-            }
-        }
-    }
-
-    public TypeTable getTypeTable() {
-        return typeTable;
-    }
-
-    public JMethod[] getMethods() {
-        return methods;
-    }
-
-}
+package org.apache.axis2.wsdl.java2wsdl;
+
+import org.apache.axis2.wsdl.java2wsdl.bytecode.MethodTable;
+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 [];
+    private MethodTable methodTable;
+
+    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 String TARGET_NAMESPACE_PREFIX = "tns";
+
+    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);
+
+        schemaCollection = new XmlSchemaCollection();
+
+        schema = new XmlSchema(SCHEMA_TARGET_NAMESPASE, schemaCollection);
+        schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
+        schema.setPrefixToNamespaceMap(prefixmap);
+        this.typeTable = new TypeTable();
+
+        try {
+            Class clazz = Class.forName(className, true, loader);
+            methodTable = new MethodTable(clazz);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * To generate schema for all the parameters in method , first generate schema for all different
+     * parameter type and later refer to them
+     *
+     * @return
+     * @throws Exception
+     */
+    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
+        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 parameters (if the parameters are
+             *     Bean then it will create Complex types for those , and if the parameters 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 methodParameter = paras[j];
+                    JClass paraType = methodParameter.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(methodParameter.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
+                     */
+
+                }
+                // for its return type
+                JClass retuenType = jMethod.getReturnType();
+                if (!retuenType.isVoidType()) {
+                    if (retuenType.isArrayType()) {
+                        String returnTypeName = retuenType.getArrayComponentType().getQualifiedName();
+                        if (!typeTable.isSimpleType(returnTypeName)) {
+                            generateSchema(retuenType.getArrayComponentType());
+                        }
+                    } else {
+                        if (!typeTable.isSimpleType(retuenType.getQualifiedName())) {
+                            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:fooInParameterElement"">
+     * <complexType name="fooInParameterElement">
+     * <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];
+            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);
+//        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
+        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);
+        }
+        String parameterNames [] = methodTable.getParameterNames(methodName);
+        for (int j = 0; j < paras.length; j++) {
+            JParameter methodParameter = paras[j];
+            String paraName = methodParameter.getSimpleName();
+            String classTypeName = methodParameter.getType().getQualifiedName();
+            boolean isArryType = methodParameter.getType().isArrayType();
+            if (isArryType) {
+                classTypeName = methodParameter.getType().getArrayComponentType().getQualifiedName();
+            }
+
+            if (parameterNames != null) {
+                paraName = parameterNames[j];
+            }
+
+            if (typeTable.isSimpleType(classTypeName)) {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(paraName);
+                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            } else {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName(paraName);
+                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("return");
+                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(classTypeName));
+                sequence.getItems().add(elt1);
+                if (isArryType) {
+                    elt1.setMaxOccurs(Long.MAX_VALUE);
+                }
+            } else {
+                XmlSchemaElement elt1 = new XmlSchemaElement();
+                elt1.setName("return");
+                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, SCHEMA_NAMESPASE_PRFIX);
+            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/bytecode/ChainedParamReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ChainedParamReader.java?rev=357670&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ChainedParamReader.java (added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ChainedParamReader.java Mon Dec 19 01:19:21 2005
@@ -0,0 +1,100 @@
+package org.apache.axis2.wsdl.java2wsdl.bytecode;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * Description: In ParamReader class, user can not get inherited method parameter
+ * from the class they passed in. This is done because of performance. This class
+ * is intended to setup the inheritant chain. If the method could not be found in
+ * the derived class, it will try to search it from super class, if not in the
+ * immedidate super class it will search super class's super class, until it reaches
+ * the root which is java.lang.Object. This is not an eager load since it only
+ * start searching the super class when it is asked to
+ * User: pengyu
+ * Date: Sep 6, 2003
+ * Time: 11:43:24 PM
+ */
+public class ChainedParamReader {
+    private List chain = new ArrayList();
+    private List clsChain = new ArrayList();
+    private Map methodToParamMap = new HashMap();
+
+    /**
+     * Process a given class's parameter names
+     *
+     * @param cls the class which user wants to get parameter info from
+     * @throws IOException
+     */
+    public ChainedParamReader(Class cls) throws IOException {
+        ParamReader reader = new ParamReader(cls);
+        chain.add(reader);
+        clsChain.add(cls);
+    }
+
+    //now I need to create deligate methods
+
+    /**
+     * return the names of the declared parameters for the given constructor.
+     * If we cannot determine the names, return null.  The returned array will
+     * have one name per parameter.  The length of the array will be the same
+     * as the length of the Class[] array returned by Constructor.getParameterTypes().
+     *
+     * @param ctor
+     * @return array of names, one per parameter, or null
+     */
+    public String[] getParameterNames(Constructor ctor) {
+        //there is no need for the constructor chaining.
+        return ((ParamReader) chain.get(0)).getParameterNames(ctor);
+    }
+
+    /**
+     * return the names of the declared parameters for the given method.
+     * If we cannot determine the names in the current class, we will try
+     * to search its parent class until we reach java.lang.Object. If we
+     * still can not find the method we will return null. The returned array
+     * will have one name per parameter. The length of the array will be the same
+     * as the length of the Class[] array returned by Method.getParameterTypes().
+     *
+     * @param method
+     * @return String[] array of names, one per parameter, or null
+     */
+    public String[] getParameterNames(Method method) {
+        //go find the one from the cache first
+        if (methodToParamMap.containsKey(method)) {
+            return (String[]) methodToParamMap.get(method);
+        }
+
+        String[] ret = null;
+        for (Iterator it = chain.iterator(); it.hasNext();) {
+            ParamReader reader = (ParamReader) it.next();
+            ret = reader.getParameterNames(method);
+            if (ret != null) {
+                methodToParamMap.put(method, ret);
+                return ret;
+            }
+        }
+        //if we here, it means we need to create new chain.
+        Class cls = (Class) clsChain.get(chain.size() - 1);
+        while (cls.getSuperclass() != null) {
+            Class superClass = cls.getSuperclass();
+            try {
+                ParamReader _reader = new ParamReader(superClass);
+                chain.add(_reader);
+                clsChain.add(cls);
+                ret = _reader.getParameterNames(method);
+                if (ret != null) { //we found it so just return it.
+                    methodToParamMap.put(method, ret);
+                    return ret;
+                }
+            } catch (IOException e) {
+                //can not find the super class in the class path, abort here
+                return null;
+            }
+        }
+        methodToParamMap.put(method, ret);
+        return null;
+    }
+}

Added: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ClassReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ClassReader.java?rev=357670&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ClassReader.java (added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ClassReader.java Mon Dec 19 01:19:21 2005
@@ -0,0 +1,409 @@
+package org.apache.axis2.wsdl.java2wsdl.bytecode;
+
+import org.apache.axis2.i18n.Messages;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is the class file reader for obtaining the parameter names
+ * for declared methods in a class.  The class must have debugging
+ * attributes for us to obtain this information. <p>
+ * <p/>
+ * This does not work for inherited methods.  To obtain parameter
+ * names for inherited methods, you must use a paramReader for the
+ * class that originally declared the method. <p>
+ * <p/>
+ * don't get tricky, it's the bare minimum.  Instances of this class
+ * are not threadsafe -- don't share them. <p>
+ *
+ * @author Edwin Smith, Macromedia
+ */
+public class ClassReader extends ByteArrayInputStream {
+    // constants values that appear in java class files,
+    // from jvm spec 2nd ed, section 4.4, pp 103
+    private final int CONSTANT_Class = 7;
+    private final int CONSTANT_Fieldref = 9;
+    private final int CONSTANT_Methodref = 10;
+    private final int CONSTANT_InterfaceMethodref = 11;
+    private final int CONSTANT_String = 8;
+    private final int CONSTANT_Integer = 3;
+    private final int CONSTANT_Float = 4;
+    private final int CONSTANT_Long = 5;
+    private final int CONSTANT_Double = 6;
+    private final int CONSTANT_NameAndType = 12;
+    private final int CONSTANT_Utf8 = 1;
+    /**
+     * the constant pool.  constant pool indices in the class file
+     * directly index into this array.  The value stored in this array
+     * is the position in the class file where that constant begins.
+     */
+    private int[] cpoolIndex;
+    private Object[] cpool;
+
+    private Map attrMethods;
+
+    /**
+     * load the bytecode for a given class, by using the class's defining
+     * classloader and assuming that for a class named P.C, the bytecodes are
+     * in a resource named /P/C.class.
+     *
+     * @param c the class of interest
+     * @return a byte array containing the bytecode
+     * @throws IOException
+     */
+    protected static byte[] getBytes(Class c) throws IOException {
+        InputStream fin = c.getResourceAsStream('/' + c.getName().replace('.', '/') + ".class");
+        if (fin == null) {
+            throw new IOException(
+                    Messages.getMessage("cantLoadByecode", c.getName()));
+        }
+        try {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            byte[] buf = new byte[1024];
+            int actual;
+            do {
+                actual = fin.read(buf);
+                if (actual > 0) {
+                    out.write(buf, 0, actual);
+                }
+            } while (actual > 0);
+            return out.toByteArray();
+        } finally {
+            fin.close();
+        }
+    }
+
+    static String classDescriptorToName(String desc) {
+        return desc.replace('/', '.');
+    }
+
+    protected static Map findAttributeReaders(Class c) {
+        HashMap map = new HashMap();
+        Method[] methods = c.getMethods();
+
+        for (int i = 0; i < methods.length; i++) {
+            String name = methods[i].getName();
+            if (name.startsWith("read") && methods[i].getReturnType() == void.class) {
+                map.put(name.substring(4), methods[i]);
+            }
+        }
+
+        return map;
+    }
+
+
+    protected static String getSignature(Member method, Class[] paramTypes) {
+        // compute the method descriptor
+
+        StringBuffer b = new StringBuffer((method instanceof Method) ? method.getName() : "<init>");
+        b.append('(');
+
+        for (int i = 0; i < paramTypes.length; i++) {
+            addDescriptor(b, paramTypes[i]);
+        }
+
+        b.append(')');
+        if (method instanceof Method) {
+            addDescriptor(b, ((Method) method).getReturnType());
+        } else if (method instanceof Constructor) {
+            addDescriptor(b, void.class);
+        }
+
+        return b.toString();
+    }
+
+    private static void addDescriptor(StringBuffer b, Class c) {
+        if (c.isPrimitive()) {
+            if (c == void.class)
+                b.append('V');
+            else if (c == int.class)
+                b.append('I');
+            else if (c == boolean.class)
+                b.append('Z');
+            else if (c == byte.class)
+                b.append('B');
+            else if (c == short.class)
+                b.append('S');
+            else if (c == long.class)
+                b.append('J');
+            else if (c == char.class)
+                b.append('C');
+            else if (c == float.class)
+                b.append('F');
+            else if (c == double.class) b.append('D');
+        } else if (c.isArray()) {
+            b.append('[');
+            addDescriptor(b, c.getComponentType());
+        } else {
+            b.append('L').append(c.getName().replace('.', '/')).append(';');
+        }
+    }
+
+
+    /**
+     * @return the next unsigned 16 bit value
+     */
+    protected final int readShort() {
+        return (read() << 8) | read();
+    }
+
+    /**
+     * @return the next signed 32 bit value
+     */
+    protected final int readInt() {
+        return (read() << 24) | (read() << 16) | (read() << 8) | read();
+    }
+
+    /**
+     * skip n bytes in the input stream.
+     */
+    protected void skipFully(int n) throws IOException {
+        while (n > 0) {
+            int c = (int) skip(n);
+            if (c <= 0)
+                throw new EOFException(Messages.getMessage("unexpectedEOF00"));
+            n -= c;
+        }
+    }
+
+    protected final Member resolveMethod(int index) throws IOException, ClassNotFoundException, NoSuchMethodException {
+        int oldPos = pos;
+        try {
+            Member m = (Member) cpool[index];
+            if (m == null) {
+                pos = cpoolIndex[index];
+                Class owner = resolveClass(readShort());
+                NameAndType nt = resolveNameAndType(readShort());
+                String signature = nt.name + nt.type;
+                if (nt.name.equals("<init>")) {
+                    Constructor[] ctors = owner.getConstructors();
+                    for (int i = 0; i < ctors.length; i++) {
+                        String sig = getSignature(ctors[i], ctors[i].getParameterTypes());
+                        if (sig.equals(signature)) {
+                            cpool[index] = m = ctors[i];
+                            return m;
+                        }
+                    }
+                } else {
+                    Method[] methods = owner.getDeclaredMethods();
+                    for (int i = 0; i < methods.length; i++) {
+                        String sig = getSignature(methods[i], methods[i].getParameterTypes());
+                        if (sig.equals(signature)) {
+                            cpool[index] = m = methods[i];
+                            return m;
+                        }
+                    }
+                }
+                throw new NoSuchMethodException(signature);
+            }
+            return m;
+        } finally {
+            pos = oldPos;
+        }
+
+    }
+
+    protected final Field resolveField(int i) throws IOException, ClassNotFoundException, NoSuchFieldException {
+        int oldPos = pos;
+        try {
+            Field f = (Field) cpool[i];
+            if (f == null) {
+                pos = cpoolIndex[i];
+                Class owner = resolveClass(readShort());
+                NameAndType nt = resolveNameAndType(readShort());
+                cpool[i] = f = owner.getDeclaredField(nt.name);
+            }
+            return f;
+        } finally {
+            pos = oldPos;
+        }
+    }
+
+    private static class NameAndType {
+        String name;
+        String type;
+
+        public NameAndType(String name, String type) {
+            this.name = name;
+            this.type = type;
+        }
+    }
+
+    protected final NameAndType resolveNameAndType(int i) throws IOException {
+        int oldPos = pos;
+        try {
+            NameAndType nt = (NameAndType) cpool[i];
+            if (nt == null) {
+                pos = cpoolIndex[i];
+                String name = resolveUtf8(readShort());
+                String type = resolveUtf8(readShort());
+                cpool[i] = nt = new NameAndType(name, type);
+            }
+            return nt;
+        } finally {
+            pos = oldPos;
+        }
+    }
+
+
+    protected final Class resolveClass(int i) throws IOException, ClassNotFoundException {
+        int oldPos = pos;
+        try {
+            Class c = (Class) cpool[i];
+            if (c == null) {
+                pos = cpoolIndex[i];
+                String name = resolveUtf8(readShort());
+                cpool[i] = c = Class.forName(classDescriptorToName(name));
+            }
+            return c;
+        } finally {
+            pos = oldPos;
+        }
+    }
+
+    protected final String resolveUtf8(int i) throws IOException {
+        int oldPos = pos;
+        try {
+            String s = (String) cpool[i];
+            if (s == null) {
+                pos = cpoolIndex[i];
+                int len = readShort();
+                skipFully(len);
+                cpool[i] = s = new String(buf, pos - len, len, "utf-8");
+            }
+            return s;
+        } finally {
+            pos = oldPos;
+        }
+    }
+
+    protected final void readCpool() throws IOException {
+        int count = readShort(); // cpool count
+        cpoolIndex = new int[count];
+        cpool = new Object[count];
+        for (int i = 1; i < count; i++) {
+            int c = read();
+            cpoolIndex[i] = super.pos;
+            switch (c) // constant pool tag
+            {
+                case CONSTANT_Fieldref:
+                case CONSTANT_Methodref:
+                case CONSTANT_InterfaceMethodref:
+                case CONSTANT_NameAndType:
+
+                    readShort(); // class index or (12) name index
+                    // fall through
+
+                case CONSTANT_Class:
+                case CONSTANT_String:
+
+                    readShort(); // string index or class index
+                    break;
+
+                case CONSTANT_Long:
+                case CONSTANT_Double:
+
+                    readInt(); // hi-value
+
+                    // see jvm spec section 4.4.5 - double and long cpool
+                    // entries occupy two "slots" in the cpool table.
+                    i++;
+                    // fall through
+
+                case CONSTANT_Integer:
+                case CONSTANT_Float:
+
+                    readInt(); // value
+                    break;
+
+                case CONSTANT_Utf8:
+
+                    int len = readShort();
+                    skipFully(len);
+                    break;
+
+                default:
+                    // corrupt class file
+                    throw new IllegalStateException(
+                            Messages.getMessage("unexpectedBytes00"));
+            }
+        }
+    }
+
+    protected final void skipAttributes() throws IOException {
+        int count = readShort();
+        for (int i = 0; i < count; i++) {
+            readShort(); // name index
+            skipFully(readInt());
+        }
+    }
+
+    /**
+     * read an attributes array.  the elements of a class file that
+     * can contain attributes are: fields, methods, the class itself,
+     * and some other types of attributes.
+     */
+    protected final void readAttributes() throws IOException {
+        int count = readShort();
+        for (int i = 0; i < count; i++) {
+            int nameIndex = readShort(); // name index
+            int attrLen = readInt();
+            int curPos = pos;
+
+            String attrName = resolveUtf8(nameIndex);
+
+            Method m = (Method) attrMethods.get(attrName);
+
+            if (m != null) {
+                try {
+                    m.invoke(this, new Object[]{});
+                } catch (IllegalAccessException e) {
+                    pos = curPos;
+                    skipFully(attrLen);
+                } catch (InvocationTargetException e) {
+                    try {
+                        throw e.getTargetException();
+                    } catch (Error ex) {
+                        throw ex;
+                    } catch (RuntimeException ex) {
+                        throw ex;
+                    } catch (IOException ex) {
+                        throw ex;
+                    } catch (Throwable ex) {
+                        pos = curPos;
+                        skipFully(attrLen);
+                    }
+                }
+            } else {
+                // don't care what attribute this is
+                skipFully(attrLen);
+            }
+        }
+    }
+
+    /**
+     * read a code attribute
+     *
+     * @throws IOException
+     */
+    public void readCode() throws IOException {
+        readShort(); // max stack
+        readShort(); // max locals
+        skipFully(readInt()); // code
+        skipFully(8 * readShort()); // exception table
+
+        // read the code attributes (recursive).  This is where
+        // we will find the LocalVariableTable attribute.
+        readAttributes();
+    }
+
+    protected ClassReader(byte buf[], Map attrMethods) {
+        super(buf);
+
+        this.attrMethods = attrMethods;
+    }
+}
+

Added: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/MethodTable.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/MethodTable.java?rev=357670&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/MethodTable.java (added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/MethodTable.java Mon Dec 19 01:19:21 2005
@@ -0,0 +1,58 @@
+package org.apache.axis2.wsdl.java2wsdl.bytecode;
+
+import java.lang.reflect.Method;
+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 MethodTable {
+
+    private HashMap nameToMethodMap;
+    private ChainedParamReader cpr;
+
+    public MethodTable(Class cls) throws Exception {
+        cpr = new ChainedParamReader(cls);
+        nameToMethodMap = new HashMap();
+        loadMethods(cls);
+    }
+
+    /**
+     * To load all the methods in the given class by Java reflection
+     *
+     * @param cls
+     * @throws Exception
+     */
+    private void loadMethods(Class cls) throws Exception {
+        Method [] methods = cls.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            nameToMethodMap.put(method.getName(), method);
+        }
+    }
+
+    public String [] getParameterNames(String methodName) {
+        Method method = (Method) nameToMethodMap.get(methodName);
+        if (method == null) {
+            return null;
+        }
+        return cpr.getParameterNames(method);
+    }
+
+
+}

Added: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamNameExtractor.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamNameExtractor.java?rev=357670&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamNameExtractor.java (added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamNameExtractor.java Mon Dec 19 01:19:21 2005
@@ -0,0 +1,51 @@
+package org.apache.axis2.wsdl.java2wsdl.bytecode;
+
+import org.apache.axis2.i18n.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * This class retieves function parameter names from bytecode built with
+ * debugging symbols.  Used as a last resort when creating WSDL.
+ *
+ * @author <a href="mailto:tomj@macromedia.com">Tom Jordahl</a>
+ */
+public class ParamNameExtractor {
+
+    protected static Log log = LogFactory.getLog(ParamNameExtractor.class.getName());
+
+    /**
+     * Retrieve a list of function parameter names from a method
+     * Returns null if unable to read parameter names (i.e. bytecode not
+     * built with debug).
+     */
+    public static String[] getParameterNamesFromDebugInfo(Method method) {
+        // Don't worry about it if there are no params.
+        int numParams = method.getParameterTypes().length;
+        if (numParams == 0)
+            return null;
+
+        // get declaring class
+        Class c = method.getDeclaringClass();
+
+        // Don't worry about it if the class is a Java dynamic proxy
+        if (Proxy.isProxyClass(c)) {
+            return null;
+        }
+
+        try {
+            // get a parameter reader
+            ParamReader pr = new ParamReader(c);
+            // get the paramter names
+            return pr.getParameterNames(method);
+        } catch (IOException e) {
+            // log it and leave
+            log.info(Messages.getMessage("error00") + ":" + e);
+            return null;
+        }
+    }
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamReader.java?rev=357670&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamReader.java (added)
+++ webservices/axis2/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/java2wsdl/bytecode/ParamReader.java Mon Dec 19 01:19:21 2005
@@ -0,0 +1,208 @@
+package org.apache.axis2.wsdl.java2wsdl.bytecode;
+
+import org.apache.axis2.i18n.Messages;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is the class file reader for obtaining the parameter names
+ * for declared methods in a class.  The class must have debugging
+ * attributes for us to obtain this information. <p>
+ * <p/>
+ * This does not work for inherited methods.  To obtain parameter
+ * names for inherited methods, you must use a paramReader for the
+ * class that originally declared the method. <p>
+ * <p/>
+ * don't get tricky, it's the bare minimum.  Instances of this class
+ * are not threadsafe -- don't share them. <p>
+ *
+ * @author Edwin Smith, Macromedia
+ */
+public class ParamReader
+        extends ClassReader {
+    private String methodName;
+    private Map methods = new HashMap();
+    private Class[] paramTypes;
+
+    /**
+     * process a class file, given it's class.  We'll use the defining
+     * classloader to locate the bytecode.
+     *
+     * @param c
+     * @throws java.io.IOException
+     */
+    public ParamReader(Class c) throws IOException {
+        this(getBytes(c));
+    }
+
+    /**
+     * process the given class bytes directly.
+     *
+     * @param b
+     * @throws IOException
+     */
+    public ParamReader(byte[] b) throws IOException {
+        super(b, findAttributeReaders(ParamReader.class));
+
+        // check the magic number
+        if (readInt() != 0xCAFEBABE) {
+            // not a class file!
+            throw new IOException(Messages.getMessage("badClassFile00"));
+        }
+
+        readShort(); // minor version
+        readShort(); // major version
+
+        readCpool(); // slurp in the constant pool
+
+        readShort(); // access flags
+        readShort(); // this class name
+        readShort(); // super class name
+
+        int count = readShort(); // ifaces count
+        for (int i = 0; i < count; i++) {
+            readShort(); // interface index
+        }
+
+        count = readShort(); // fields count
+        for (int i = 0; i < count; i++) {
+            readShort(); // access flags
+            readShort(); // name index
+            readShort(); // descriptor index
+            skipAttributes(); // field attributes
+        }
+
+        count = readShort(); // methods count
+        for (int i = 0; i < count; i++) {
+            readShort(); // access flags
+            int m = readShort(); // name index
+            String name = resolveUtf8(m);
+            int d = readShort(); // descriptor index
+            this.methodName = name + resolveUtf8(d);
+            readAttributes(); // method attributes
+        }
+
+    }
+
+    public void readCode() throws IOException {
+        readShort(); // max stack
+        int maxLocals = readShort(); // max locals
+
+        MethodInfo info = new MethodInfo(maxLocals);
+        if (methods != null && methodName != null) {
+            methods.put(methodName, info);
+        }
+
+        skipFully(readInt()); // code
+        skipFully(8 * readShort()); // exception table
+        // read the code attributes (recursive).  This is where
+        // we will find the LocalVariableTable attribute.
+        readAttributes();
+    }
+
+    /**
+     * return the names of the declared parameters for the given constructor.
+     * If we cannot determine the names, return null.  The returned array will
+     * have one name per parameter.  The length of the array will be the same
+     * as the length of the Class[] array returned by Constructor.getParameterTypes().
+     *
+     * @param ctor
+     * @return String[] array of names, one per parameter, or null
+     */
+    public String[] getParameterNames(Constructor ctor) {
+        paramTypes = ctor.getParameterTypes();
+        return getParameterNames(ctor, paramTypes);
+    }
+
+    /**
+     * return the names of the declared parameters for the given method.
+     * If we cannot determine the names, return null.  The returned array will
+     * have one name per parameter.  The length of the array will be the same
+     * as the length of the Class[] array returned by Method.getParameterTypes().
+     *
+     * @param method
+     * @return String[] array of names, one per parameter, or null
+     */
+    public String[] getParameterNames(Method method) {
+        paramTypes = method.getParameterTypes();
+        return getParameterNames(method, paramTypes);
+    }
+
+    protected String[] getParameterNames(Member member, Class [] paramTypes) {
+        // look up the names for this method
+        MethodInfo info = (MethodInfo) methods.get(getSignature(member, paramTypes));
+
+        // we know all the local variable names, but we only need to return
+        // the names of the parameters.
+
+        if (info != null) {
+            String[] paramNames = new String[paramTypes.length];
+            int j = Modifier.isStatic(member.getModifiers()) ? 0 : 1;
+
+            boolean found = false;  // did we find any non-null names
+            for (int i = 0; i < paramNames.length; i++) {
+                if (info.names[j] != null) {
+                    found = true;
+                    paramNames[i] = info.names[j];
+                }
+                j++;
+                if (paramTypes[i] == double.class || paramTypes[i] == long.class) {
+                    // skip a slot for 64bit params
+                    j++;
+                }
+            }
+
+            if (found) {
+                return paramNames;
+            } else {
+                return null;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    private static class MethodInfo {
+        String[] names;
+        int maxLocals;
+
+        public MethodInfo(int maxLocals) {
+            this.maxLocals = maxLocals;
+            names = new String[maxLocals];
+        }
+    }
+
+    private MethodInfo getMethodInfo() {
+        MethodInfo info = null;
+        if (methods != null && methodName != null) {
+            info = (MethodInfo) methods.get(methodName);
+        }
+        return info;
+    }
+
+    /**
+     * this is invoked when a LocalVariableTable attribute is encountered.
+     *
+     * @throws IOException
+     */
+    public void readLocalVariableTable() throws IOException {
+        int len = readShort(); // table length
+        MethodInfo info = getMethodInfo();
+        for (int j = 0; j < len; j++) {
+            readShort(); // start pc
+            readShort(); // length
+            int nameIndex = readShort(); // name_index
+            readShort(); // descriptor_index
+            int index = readShort(); // local index
+            if (info != null) {
+                info.names[index] = resolveUtf8(nameIndex);
+            }
+        }
+    }
+}



Mime
View raw message