axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r782417 - in /webservices/axis2/trunk/java/modules: integration/test/org/apache/axis2/integration/ jaxbri/src/org/apache/axis2/jaxbri/ kernel/src/org/apache/axis2/description/java2wsdl/
Date Sun, 07 Jun 2009 17:57:16 GMT
Author: deepal
Date: Sun Jun  7 17:57:16 2009
New Revision: 782417

URL: http://svn.apache.org/viewvc?rev=782417&view=rev
Log:
Applied the generic patch (AXIS2-2782) with a number of additional changes. I went though
the patch, and found that a number of changes. I will comment on the jira about few other
comments.

Modified:
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
    webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/JaxbSchemaGenerator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/DefaultSchemaGenerator.java

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java?rev=782417&r1=782416&r2=782417&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/LocalTestCase.java
Sun Jun  7 17:57:16 2009
@@ -153,14 +153,11 @@
      */
     protected AxisService deployClassAsService(String name, Class myClass, String scope)
             throws Exception {
-        AxisService service = new AxisService(name);
-        if (scope != null) service.setScope(scope);
-
+         AxisService service = AxisService.createService(myClass.getName(),serverConfig);
+         if (scope != null) service.setScope(scope);
         service.addParameter(Constants.SERVICE_CLASS,
                               myClass.getName());
-
-        Utils.fillAxisService(service, serverConfig, null, null);
-
+        service.setName(name);
         serverCtx.deployService(service);
         return service;
     }

Modified: webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/JaxbSchemaGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/JaxbSchemaGenerator.java?rev=782417&r1=782416&r2=782417&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/JaxbSchemaGenerator.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/JaxbSchemaGenerator.java
Sun Jun  7 17:57:16 2009
@@ -23,7 +23,9 @@
 import com.sun.xml.bind.v2.runtime.JaxBeanInfo;
 import org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator;
 import org.apache.axis2.util.Loader;
-import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.axis2.deployment.util.BeanExcludeInfo;
+import org.apache.ws.commons.schema.*;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -37,6 +39,9 @@
 import javax.xml.transform.dom.DOMResult;
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -45,6 +50,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
 
 public class JaxbSchemaGenerator extends DefaultSchemaGenerator {
     public JaxbSchemaGenerator(ClassLoader loader, String className,
@@ -236,4 +244,121 @@
         return JAXBContext.newInstance(classes.toArray(new Class[classes.size()]), map);
     }
 
+    protected QName generateSchema(Class javaType) throws Exception {
+        String name = getClassName(javaType);
+        QName schemaTypeName = typeTable.getComplexSchemaType(name);
+        if (schemaTypeName == null) {
+            String simpleName = javaType.getSimpleName();
+
+            String packageName = getQualifiedName(javaType.getPackage());
+            String targetNameSpace = resolveSchemaNamespace(packageName);
+
+            XmlSchema xmlSchema = getXmlSchema(targetNameSpace);
+            String targetNamespacePrefix = (String) targetNamespacePrefixMap.get(targetNameSpace);
+            if (targetNamespacePrefix == null) {
+                targetNamespacePrefix = generatePrefix();
+                targetNamespacePrefixMap.put(targetNameSpace, targetNamespacePrefix);
+            }
+
+            XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema);
+            XmlSchemaSequence sequence = new XmlSchemaSequence();
+            XmlSchemaComplexContentExtension complexExtension =
+                    new XmlSchemaComplexContentExtension();
+
+            XmlSchemaElement eltOuter = new XmlSchemaElement();
+            schemaTypeName = new QName(targetNameSpace, simpleName, targetNamespacePrefix);
+            eltOuter.setName(simpleName);
+            eltOuter.setQName(schemaTypeName);
+
+            Class sup = javaType.getSuperclass();
+            if ((sup != null) && !("java.lang.Object".compareTo(sup.getName()) ==
0) &&
+                    !(getQualifiedName(sup.getPackage()).indexOf("org.apache.axis2") >
0)
+                    && !(getQualifiedName(sup.getPackage()).indexOf("java.util")
> 0))
+            {
+                String superClassName = sup.getName();
+                String superclassname = sup.getSimpleName();
+                String tgtNamespace;
+                String tgtNamespacepfx;
+                QName qName = typeTable.getSimpleSchemaTypeName(superClassName);
+                if (qName != null) {
+                    tgtNamespace = qName.getNamespaceURI();
+                    tgtNamespacepfx = qName.getPrefix();
+                } else {
+                    tgtNamespace = resolveSchemaNamespace(getQualifiedName(sup.getPackage()));
+                    tgtNamespacepfx = (String) targetNamespacePrefixMap.get(tgtNamespace);
+                    QName superClassQname = generateSchema(sup);
+                    if (superClassQname != null) {
+                        tgtNamespacepfx = superClassQname.getPrefix();
+                        tgtNamespace = superClassQname.getNamespaceURI();
+                    }
+                }
+                if (tgtNamespacepfx == null) {
+                    tgtNamespacepfx = generatePrefix();
+                    targetNamespacePrefixMap.put(tgtNamespace, tgtNamespacepfx);
+                }
+                //if the parent class package name is differ from the child
+                if (!((NamespaceMap) xmlSchema.getNamespaceContext()).values().
+                        contains(tgtNamespace)) {
+                    XmlSchemaImport importElement = new XmlSchemaImport();
+                    importElement.setNamespace(tgtNamespace);
+                    xmlSchema.getItems().add(importElement);
+                    ((NamespaceMap) xmlSchema.getNamespaceContext()).
+                            put(generatePrefix(), tgtNamespace);
+                }
+
+                QName basetype = new QName(tgtNamespace, superclassname, tgtNamespacepfx);
+                complexExtension.setBaseTypeName(basetype);
+                complexExtension.setParticle(sequence);
+                XmlSchemaComplexContent contentModel = new XmlSchemaComplexContent();
+                contentModel.setContent(complexExtension);
+                complexType.setContentModel(contentModel);
+
+            } else {
+                complexType.setParticle(sequence);
+            }
+
+            complexType.setName(simpleName);
+
+//            xmlSchema.getItems().add(eltOuter);
+            xmlSchema.getElements().add(schemaTypeName, eltOuter);
+            eltOuter.setSchemaTypeName(complexType.getQName());
+
+            xmlSchema.getItems().add(complexType);
+            xmlSchema.getSchemaTypes().add(schemaTypeName, complexType);
+
+            // adding this type to the table
+            typeTable.addComplexSchema(name, eltOuter.getQName());
+            // adding this type's package to the table, to support inheritance.
+            typeTable.addComplexSchema(getQualifiedName(javaType.getPackage()), eltOuter.getQName());
+
+            BeanExcludeInfo beanExcludeInfo = null;
+            if (service.getExcludeInfo() != null) {
+                beanExcludeInfo = service.getExcludeInfo().getBeanExcludeInfoForClass(getClassName(javaType));
+            }
+
+            // we need to get properties only for this bean. hence ignore the super
+            // class properties
+            BeanInfo beanInfo = Introspector.getBeanInfo(javaType, javaType.getSuperclass());
+            PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
+            PropertyDescriptor property ;
+            String propertyName ;
+
+            for (int i = 0; i < properties.length; i++) {
+                property = properties[i];
+                propertyName = property.getName();
+                if (!property.getName().equals("class") && (property.getPropertyType()
!= null)) {
+                    if ((beanExcludeInfo == null) || !beanExcludeInfo.isExcludedProperty(propertyName))
{
+
+                        generateSchemaforFieldsandProperties(xmlSchema,
+                                sequence,
+                                property.getPropertyType(),
+                                propertyName,
+                                property.getPropertyType().isArray());
+                    }
+                }
+            }
+        }
+        return schemaTypeName;
+    }
+
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/DefaultSchemaGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/DefaultSchemaGenerator.java?rev=782417&r1=782416&r2=782417&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/DefaultSchemaGenerator.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/java2wsdl/DefaultSchemaGenerator.java
Sun Jun  7 17:57:16 2009
@@ -44,8 +44,7 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import java.io.*;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
+import java.lang.reflect.*;
 import java.util.*;
 import java.beans.PropertyDescriptor;
 import java.beans.BeanInfo;
@@ -99,7 +98,7 @@
     protected NamespaceGenerator nsGen = null;
 
     protected String targetNamespace = null;
-    //to keep the list of operation which uses MR other than RPC MR
+    //to keep the list of operations which use other MR not RPC MR
     protected ArrayList nonRpcMethods = new ArrayList();
 
     protected Class serviceClass = null;
@@ -335,6 +334,8 @@
                         axisOperation);
             }
             Annotation[][] parameterAnnotation = jMethod.getParameterAnnotations();
+
+            Type[] genericParameterTypes = jMethod.getGenericParameterTypes();
             for (int j = 0; j < parameters.length; j++) {
                 Class methodParameter = parameters[j];
                 String parameterName = getParameterName(parameterAnnotation, j, parameterNames);
@@ -342,7 +343,16 @@
                     generateSchemaForType(sequence, null, jMethod.getName());
                     break;
                 } else {
-                    generateSchemaForType(sequence, methodParameter, parameterName);
+                    Type genericParameterType = genericParameterTypes[j];
+                    Type genericType = null;
+                    if(genericParameterType instanceof ParameterizedType){
+                        ParameterizedType aType = (ParameterizedType) genericParameterType;
+                        Type[] parameterArgTypes = aType.getActualTypeArguments();
+                        genericType = parameterArgTypes[0];
+                        generateSchemaForType(sequence, genericType, parameterName, true);
+                    }else{
+                        generateSchemaForType(sequence, methodParameter, parameterName);
+                    }
                 }
             }
             // for its return type
@@ -361,11 +371,19 @@
                         returnName = "return";
                     }
                 }
+                Type genericParameterType = jMethod.getGenericReturnType();
                 if (nonRpcMethods.contains(jMethod.getName())) {
                     generateSchemaForType(sequence, null, returnName);
-                } else {
+                } else if(genericParameterType instanceof ParameterizedType){
+                        ParameterizedType aType = (ParameterizedType) genericParameterType;
+                        Type[] parameterArgTypes = aType.getActualTypeArguments();
+                        generateSchemaForType(sequence, parameterArgTypes[0], returnName,
true);
+                    } else {
                     generateSchemaForType(sequence, returnType, returnName);
                 }
+
+
+
                 AxisMessage outMessage = axisOperation.getMessage(
                         WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
                 outMessage.setElementQName(typeTable.getQNamefortheType(partQname));
@@ -557,17 +575,42 @@
             PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
             PropertyDescriptor property = null;
             String propertyName = null;
+
             for (int i = 0; i < properties.length; i++) {
                 property = properties[i];
                 propertyName = property.getName();
                 if (!property.getName().equals("class") && (property.getPropertyType()
!= null)) {
                     if ((beanExcludeInfo == null) || !beanExcludeInfo.isExcludedProperty(propertyName))
{
-                        property.getPropertyType();
-                        generateSchemaforFieldsandProperties(xmlSchema,
-                                sequence,
-                                property.getPropertyType(),
-                                propertyName,
-                                property.getPropertyType().isArray());
+                        Type genericFieldType = null;
+                        try {
+                            Field field = javaType.getDeclaredField(propertyName);
+                            genericFieldType = field.getGenericType();
+                        } catch (Exception e) {
+                            //log.info(e.getMessage());
+                        }
+
+                        if(genericFieldType instanceof ParameterizedType){
+                            ParameterizedType aType = (ParameterizedType) genericFieldType;
+                            Type[] fieldArgTypes = aType.getActualTypeArguments();
+                            try {
+                                generateSchemaforGenericFields(xmlSchema,
+                                    sequence,
+                                    fieldArgTypes[0],
+                                    propertyName);
+                            } catch (Exception e) {
+                                generateSchemaforFieldsandProperties(xmlSchema,
+                                    sequence,
+                                    property.getPropertyType(),
+                                    propertyName,
+                                    property.getPropertyType().isArray());
+                            }
+                        } else {
+                            generateSchemaforFieldsandProperties(xmlSchema,
+                                    sequence,
+                                    property.getPropertyType(),
+                                    propertyName,
+                                    property.getPropertyType().isArray());
+                        }
                     }
                 }
             }
@@ -585,7 +628,7 @@
         if (isArrayType) {
             propertyName = type.getComponentType().getName();
             if (type.getComponentType().isArray()) {
-                // this is a doble array element
+                // this is a double array element
                 Class simpleType = type.getComponentType();
                 String simpleTypeName = "";
                 while (simpleType.isArray()) {
@@ -655,37 +698,136 @@
 
             if (isGenerateWrappedArrayTypes && isArrayType) {
 
-                XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
-                xmlSchemaElement.setName( name + "Wrapper");
-                xmlSchemaElement.setNillable(true);
-                sequence.getItems().add(xmlSchemaElement);
+                processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType,
propertyName);
 
-                String complexTypeName =
-                        typeTable.getSimpleSchemaTypeName(propertyName).getLocalPart() +
"Wrapper";
 
-                XmlSchemaComplexType xmlSchemaComplexType = null;
-                if (xmlSchema.getTypeByName(complexTypeName) == null) {
-                    xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
-                    XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
-                    xmlSchemaComplexType.setParticle(xmlSchemaSequence);
-                    xmlSchemaComplexType.setName(complexTypeName);
-
-                    xmlSchema.getItems().add(xmlSchemaComplexType);
-                    xmlSchema.getSchemaTypes().add(
-                            new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
-                            xmlSchemaComplexType);
-                    addElementToSequence("array",
+            } else {
+                addElementToSequence(name,
                         typeTable.getSimpleSchemaTypeName(propertyName),
-                        xmlSchemaSequence,
+                        sequence,
                         propertyName.equals("base64Binary"),
                         isArrayType,
                         type.isPrimitive());
-                } else {
-                   xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(complexTypeName);
-                }
+            }
+
+        } else {
+            if (isArrayType) {
+                generateSchema(type.getComponentType());
+            } else {
+                generateSchema(type);
+            }
+
+            if (isGenerateWrappedArrayTypes && isArrayType) {
+
+                processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType,
propertyName);
+
+
+            } else {
+                addElementToSequence(name,
+                        typeTable.getComplexSchemaType(propertyName),
+                        sequence,
+                        false,
+                        isArrayType,
+                        type.isPrimitive());
+            }
+
+            if (typeTable.getComplexSchemaType(propertyName) != null && !((NamespaceMap)
xmlSchema.getNamespaceContext()).values().
+                    contains(typeTable.getComplexSchemaType(propertyName).getNamespaceURI()))
{
+                XmlSchemaImport importElement = new XmlSchemaImport();
+                importElement.setNamespace(
+                        typeTable.getComplexSchemaType(propertyName).getNamespaceURI());
+                xmlSchema.getItems().add(importElement);
+                ((NamespaceMap) xmlSchema.getNamespaceContext()).
+                        put(generatePrefix(),
+                                typeTable.getComplexSchemaType(propertyName).getNamespaceURI());
+            }
+        }
+
+
+    }
+
+    protected void generateSchemaforGenericFields(XmlSchema xmlSchema,
+                                                  XmlSchemaSequence sequence, Type genericType,
+                                                  String name)
+            throws Exception {
+        String propertyName;
+        Class type;
+        boolean isArrayType = true;
+        if (genericType instanceof GenericArrayType) {
+            Class simpleType = (Class) ((GenericArrayType) genericType).getGenericComponentType();
+            propertyName = simpleType.getName();
+            // this is a doble array element
+            String simpleTypeName = "";
+            while (simpleType.isArray()) {
+                simpleTypeName += "ArrayOf";
+                simpleType = simpleType.getComponentType();
+            }
+            simpleTypeName += simpleType.getSimpleName();
+
+            if (xmlSchema.getTypeByName(simpleTypeName) == null) {
+                XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+                xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+                generateSchemaforGenericFields(xmlSchema,
+                        xmlSchemaSequence, simpleType, "array");
+
+                xmlSchemaComplexType.setName(simpleTypeName);
+                xmlSchema.getItems().add(xmlSchemaComplexType);
+                xmlSchema.getSchemaTypes().add(
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName), xmlSchemaComplexType);
+            }
+
+            if (isGenerateWrappedArrayTypes) {
+                XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
+                xmlSchemaElement.setName( name + "Wrapper");
+                xmlSchemaElement.setNillable(true);
+                sequence.getItems().add(xmlSchemaElement);
+
+                String complexTypeName = simpleTypeName + "Wrapper";
+
+                XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+                xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+                xmlSchemaComplexType.setName(complexTypeName);
+
+                xmlSchema.getItems().add(xmlSchemaComplexType);
+                xmlSchema.getSchemaTypes().add(
+                        new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
+                        xmlSchemaComplexType);
+                addContentToMethodSchemaType(xmlSchemaSequence,
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                        "array",
+                        true);
 
                 xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
-                xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
+                xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace,
+                        xmlSchemaComplexType.getName()));
+
+            } else {
+                addContentToMethodSchemaType(sequence,
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                        name,
+                        true);
+
+            }
+            return;
+        } else {
+//            isArrayType = false;
+            type = (Class) genericType;
+            propertyName = type.getName();
+        }
+
+        if (isArrayType && "byte".equals(propertyName)) {
+            propertyName = "base64Binary";
+        }
+        if (isDataHandler(type)) {
+            propertyName = "base64Binary";
+        }
+        if (typeTable.isSimpleType(propertyName)) {
+
+            if (isGenerateWrappedArrayTypes && isArrayType) {
+
+                processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType,
propertyName);
 
 
             } else {
@@ -706,37 +848,7 @@
 
             if (isGenerateWrappedArrayTypes && isArrayType) {
 
-                XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
-                xmlSchemaElement.setName(name + "Wrapper");
-                xmlSchemaElement.setNillable(true);
-                sequence.getItems().add(xmlSchemaElement);
-
-                String complexTypeName =
-                        typeTable.getSimpleSchemaTypeName(propertyName).getLocalPart() +
"Wrapper";
-
-                XmlSchemaComplexType xmlSchemaComplexType = null;
-                if (xmlSchema.getTypeByName(complexTypeName) == null) {
-                    xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
-                    XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
-                    xmlSchemaComplexType.setParticle(xmlSchemaSequence);
-                    xmlSchemaComplexType.setName(complexTypeName);
-
-                    xmlSchema.getItems().add(xmlSchemaComplexType);
-                    xmlSchema.getSchemaTypes().add(
-                            new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
-                            xmlSchemaComplexType);
-                    addElementToSequence("array",
-                            typeTable.getSimpleSchemaTypeName(propertyName),
-                            xmlSchemaSequence,
-                            propertyName.equals("base64Binary"),
-                            isArrayType,
-                            type.isPrimitive());
-                } else {
-                    xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(complexTypeName);
-                }
-
-                xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
-                xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
+                processGenerateWrappedArrayTypes(xmlSchema, sequence, type, name, isArrayType,
propertyName);
 
 
             } else {
@@ -763,6 +875,46 @@
 
     }
 
+
+    private void processGenerateWrappedArrayTypes(XmlSchema xmlSchema,
+                                                  XmlSchemaSequence sequence,
+                                                  Class type,
+                                                  String name,
+                                                  boolean isArrayType,
+                                                  String propertyName) {
+        XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
+        xmlSchemaElement.setName( name + "Wrapper");
+        xmlSchemaElement.setNillable(true);
+        sequence.getItems().add(xmlSchemaElement);
+
+        String complexTypeName =
+                typeTable.getSimpleSchemaTypeName(propertyName).getLocalPart() + "Wrapper";
+
+        XmlSchemaComplexType xmlSchemaComplexType ;
+        if (xmlSchema.getTypeByName(complexTypeName) == null) {
+            xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+            xmlSchemaComplexType.setName(complexTypeName);
+
+            xmlSchema.getItems().add(xmlSchemaComplexType);
+            xmlSchema.getSchemaTypes().add(
+                    new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
+                    xmlSchemaComplexType);
+            addElementToSequence("array",
+                typeTable.getSimpleSchemaTypeName(propertyName),
+                xmlSchemaSequence,
+                propertyName.equals("base64Binary"),
+                isArrayType,
+                type.isPrimitive());
+        } else {
+           xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(complexTypeName);
+        }
+
+        xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
+        xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
+    }
+
     private void addElementToSequence(String name,
                                       QName propertyQName,
                                       XmlSchemaSequence sequence,
@@ -792,7 +944,7 @@
         }
         if (isArrayType) {
             if (type.getComponentType().isArray()) {
-                // this is a doble array element
+                // this is a double array element
                 Class simpleType = type.getComponentType();
                 String simpleTypeName = "";
                 while (simpleType.isArray()) {
@@ -801,55 +953,98 @@
                 }
                 simpleTypeName += simpleType.getSimpleName();
 
-                XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
-                if (xmlSchema.getTypeByName(simpleTypeName) == null) {
-                    XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
-                    XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
-                    xmlSchemaComplexType.setParticle(xmlSchemaSequence);
-                    generateSchemaForType(xmlSchemaSequence, type.getComponentType(), "array");
-                    xmlSchemaComplexType.setName(simpleTypeName);
-                    xmlSchema.getItems().add(xmlSchemaComplexType);
-                    xmlSchema.getSchemaTypes().add(
-                            new QName(xmlSchema.getTargetNamespace(), simpleTypeName), xmlSchemaComplexType);
-                }
+                return processParameterArrayTypes(sequence, type, partName, simpleTypeName);
 
-                if (isGenerateWrappedArrayTypes) {
-                    XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
-                    xmlSchemaElement.setName(partName + "Wrapper");
-                    xmlSchemaElement.setNillable(true);
-                    sequence.getItems().add(xmlSchemaElement);
 
-                    String complexTypeName = simpleTypeName + "Wrapper";
+            } else {
+                type = type.getComponentType();
+            }
+        }
+        if (AxisFault.class.getName().equals(type)) {
+            return null;
+        }
+        String classTypeName;
+        if (type == null) {
+            classTypeName = "java.lang.Object";
+        } else {
+            classTypeName = type.getName();
+        }
+        if (isArrayType && "byte".equals(classTypeName)) {
+            classTypeName = "base64Binary";
+            isArrayType = false;
+        }
 
-                    XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
-                    XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
-                    xmlSchemaComplexType.setParticle(xmlSchemaSequence);
-                    xmlSchemaComplexType.setName(complexTypeName);
+        if (isDataHandler(type)) {
+            classTypeName = "base64Binary";
+        }
 
-                    xmlSchema.getItems().add(xmlSchemaComplexType);
-                    xmlSchema.getSchemaTypes().add(
-                            new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
-                            xmlSchemaComplexType);
-                    addContentToMethodSchemaType(xmlSchemaSequence,
-                            new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
-                            "array",
-                            true);
+        return generateSchemaTypeforNameCommon(sequence, partName, isArrayType, type, classTypeName);
+    }
 
-                    xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
-                    xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
-                    return new QName(xmlSchema.getTargetNamespace(), complexTypeName);
-                } else {
-                    addContentToMethodSchemaType(sequence,
-                            new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
-                            partName,
-                            true);
-                    return new QName(xmlSchema.getTargetNamespace(), simpleTypeName);
-                }
+
+    private QName generateSchemaForType(XmlSchemaSequence sequence, Type genericType, String
partName, boolean isArrayType)
+            throws Exception {
 
 
+        Class type;
+        if (genericType instanceof GenericArrayType) {
+            // this is a double array element
+            Class simpleType = (Class) ((GenericArrayType) genericType).getGenericComponentType();
+            String simpleTypeName = "";
+            while (simpleType.isArray()) {
+                simpleTypeName += "ArrayOf";
+                simpleType = simpleType.getComponentType();
+            }
+            simpleTypeName += simpleType.getSimpleName();
+
+            XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
+            if (xmlSchema.getTypeByName(simpleTypeName) == null) {
+                XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+                xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+                generateSchemaForType(xmlSchemaSequence, simpleType, "array",true);
+                xmlSchemaComplexType.setName(simpleTypeName);
+                xmlSchema.getItems().add(xmlSchemaComplexType);
+                xmlSchema.getSchemaTypes().add(
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName), xmlSchemaComplexType);
+            }
+
+            if (isGenerateWrappedArrayTypes) {
+                XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
+                xmlSchemaElement.setName(partName + "Wrapper");
+                xmlSchemaElement.setNillable(true);
+                sequence.getItems().add(xmlSchemaElement);
+
+                String complexTypeName = simpleTypeName + "Wrapper";
+
+                XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+                xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+                xmlSchemaComplexType.setName(complexTypeName);
+
+                xmlSchema.getItems().add(xmlSchemaComplexType);
+                xmlSchema.getSchemaTypes().add(
+                        new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
+                        xmlSchemaComplexType);
+                addContentToMethodSchemaType(xmlSchemaSequence,
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                        "array",
+                        true);
+
+                xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
+                xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
+                return new QName(xmlSchema.getTargetNamespace(), complexTypeName);
             } else {
-                type = type.getComponentType();
+                addContentToMethodSchemaType(sequence,
+                        new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                        partName,
+                        true);
+                return new QName(xmlSchema.getTargetNamespace(), simpleTypeName);
             }
+
+
+        } else{
+            type = (Class) genericType;
         }
         if (AxisFault.class.getName().equals(type)) {
             return null;
@@ -868,6 +1063,15 @@
         if (isDataHandler(type)) {
             classTypeName = "base64Binary";
         }
+
+        return generateSchemaTypeforNameCommon(sequence, partName, isArrayType, type, classTypeName);
+    }
+
+    private QName generateSchemaTypeforNameCommon(XmlSchemaSequence sequence,
+                                                  String partName,
+                                                  boolean isArrayType,
+                                                  Class type,
+                                                  String classTypeName) throws Exception
{
         QName schemaTypeName = typeTable.getSimpleSchemaTypeName(classTypeName);
         if (schemaTypeName == null) {
             schemaTypeName = generateSchema(type);
@@ -961,6 +1165,53 @@
         return schemaTypeName;
     }
 
+    private QName processParameterArrayTypes(XmlSchemaSequence sequence, Class type, String
partName, String simpleTypeName) throws Exception {
+        XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
+        if (xmlSchema.getTypeByName(simpleTypeName) == null) {
+            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+            generateSchemaForType(xmlSchemaSequence, type.getComponentType(), "array");
+            xmlSchemaComplexType.setName(simpleTypeName);
+            xmlSchema.getItems().add(xmlSchemaComplexType);
+            xmlSchema.getSchemaTypes().add(
+                    new QName(xmlSchema.getTargetNamespace(), simpleTypeName), xmlSchemaComplexType);
+        }
+
+        if (isGenerateWrappedArrayTypes) {
+            XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
+            xmlSchemaElement.setName(partName + "Wrapper");
+            xmlSchemaElement.setNillable(true);
+            sequence.getItems().add(xmlSchemaElement);
+
+            String complexTypeName = simpleTypeName + "Wrapper";
+
+            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema);
+            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
+            xmlSchemaComplexType.setParticle(xmlSchemaSequence);
+            xmlSchemaComplexType.setName(complexTypeName);
+
+            xmlSchema.getItems().add(xmlSchemaComplexType);
+            xmlSchema.getSchemaTypes().add(
+                    new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()),
+                    xmlSchemaComplexType);
+            addContentToMethodSchemaType(xmlSchemaSequence,
+                    new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                    "array",
+                    true);
+
+            xmlSchemaElement.setSchemaType(xmlSchemaComplexType);
+            xmlSchemaElement.setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()));
+            return new QName(xmlSchema.getTargetNamespace(), complexTypeName);
+        } else {
+            addContentToMethodSchemaType(sequence,
+                    new QName(xmlSchema.getTargetNamespace(), simpleTypeName),
+                    partName,
+                    true);
+            return new QName(xmlSchema.getTargetNamespace(), simpleTypeName);
+        }
+    }
+
     protected boolean isDataHandler(Class clazz) {
         return clazz != null && DataHandler.class.isAssignableFrom(clazz);
     }



Mime
View raw message