You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gd...@apache.org on 2005/05/21 16:32:13 UTC

svn commit: r171212 - in /geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder: AxisBuilder.java AxisServiceBuilder.java HeavyweightTypeInfoBuilder.java

Author: gdamour
Date: Sat May 21 07:32:12 2005
New Revision: 171212

URL: http://svn.apache.org/viewcvs?rev=171212&view=rev
Log:
o GERONIMO-652 Use the information of the <service-endpoint-method-mapping> to
 infer additional java to XML types mappings.

o support mapping of java arrays to list simple types.

o remove the TypeDesc registrations during the build of JavaServiceDesc. The
registrations are not required during deployment.

Modified:
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
    geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java?rev=171212&r1=171211&r2=171212&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisBuilder.java Sat May 21 07:32:12 2005
@@ -26,6 +26,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -388,6 +389,7 @@
         }
         Class enhancedServiceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointInterface, context, module, classLoader);
 
+        Collection operationDescs = new ArrayList();
         ServiceEndpointMethodMappingType[] methodMappings = endpointMapping.getServiceEndpointMethodMappingArray();
         int i = 0;
         Set wrapperElementQNames = new HashSet();
@@ -414,10 +416,11 @@
             HeavyweightOperationDescBuilder operationDescBuilder = new HeavyweightOperationDescBuilder(bindingOperation, mapping, methodMapping, portStyle, exceptionMap, schemaInfoBuilder, javaXmlTypeMappings, classLoader, enhancedServiceEndpointClass);
             OperationInfo operationInfo = operationDescBuilder.buildOperationInfo(soapVersion);
             operationInfos[i++] = operationInfo;
+            operationDescs.add(operationInfo.getOperationDesc());
             wrapperElementQNames.addAll(operationDescBuilder.getWrapperElementQNames());
             hasEncoded |= operationDescBuilder.isEncoded();
         }
-        HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(classLoader, schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(), wrapperElementQNames, hasEncoded);
+        HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(classLoader, schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(), wrapperElementQNames, operationDescs, hasEncoded);
         List typeInfo = builder.buildTypeInfo(mapping);
 
         seiFactory = createSEIFactory(serviceName, portName, enhancedServiceEndpointClass, serviceImpl, typeInfo, location, operationInfos, handlerInfos, credentialsName, context, classLoader);

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java?rev=171212&r1=171211&r2=171212&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/AxisServiceBuilder.java Sat May 21 07:32:12 2005
@@ -21,6 +21,8 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -28,6 +30,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarFile;
+
 import javax.wsdl.Binding;
 import javax.wsdl.BindingInput;
 import javax.wsdl.BindingOperation;
@@ -45,6 +48,7 @@
 import org.apache.axis.constants.Style;
 import org.apache.axis.constants.Use;
 import org.apache.axis.description.JavaServiceDesc;
+import org.apache.axis.description.OperationDesc;
 import org.apache.axis.encoding.TypeMapping;
 import org.apache.axis.encoding.TypeMappingRegistryImpl;
 import org.apache.geronimo.axis.client.TypeInfo;
@@ -155,8 +159,13 @@
             validateLightweightMapping(portInfo.getDefinition());
         }
 
-        Set wrapperElementQNames = buildOperations(binding, serviceEndpointInterface, isLightweight, portInfo, exceptionMap, classLoader, serviceDesc);
-
+        Collection operations = new ArrayList();
+        Set wrapperElementQNames = buildOperations(binding, serviceEndpointInterface, isLightweight, portInfo, exceptionMap, classLoader, operations);
+        for (Iterator iter = operations.iterator(); iter.hasNext();) {
+            OperationDesc operation = (OperationDesc) iter.next();
+            serviceDesc.addOperationDesc(operation);
+        }
+     
         TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
         tmr.doRegisterFromVersion("1.3");
 
@@ -170,16 +179,14 @@
             LightweightTypeInfoBuilder builder = new LightweightTypeInfoBuilder(classLoader, schemaTypeKeyToSchemaTypeMap, wrapperElementQNames);
             typeInfo = builder.buildTypeInfo(portInfo.getJavaWsdlMapping());
         } else {
-            HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(classLoader, schemaTypeKeyToSchemaTypeMap, wrapperElementQNames, hasEncoded);
+            HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(classLoader, schemaTypeKeyToSchemaTypeMap, wrapperElementQNames, operations, hasEncoded);
             typeInfo = builder.buildTypeInfo(portInfo.getJavaWsdlMapping());
         }
-        TypeInfo.register(typeInfo, typeMapping);
 
-        serviceDesc.getOperations();
         return new ReadOnlyServiceDesc(serviceDesc, typeInfo);
     }
 
-    private static Set buildOperations(Binding binding, Class serviceEndpointInterface, boolean lightweight, PortInfo portInfo, Map exceptionMap, ClassLoader classLoader, JavaServiceDesc serviceDesc) throws DeploymentException {
+    private static Set buildOperations(Binding binding, Class serviceEndpointInterface, boolean lightweight, PortInfo portInfo, Map exceptionMap, ClassLoader classLoader, Collection operations) throws DeploymentException {
         Set wrappedElementQNames = new HashSet();
 
         SOAPBinding soapBinding = (SOAPBinding) SchemaInfoBuilder.getExtensibilityElement(SOAPBinding.class, binding.getExtensibilityElements());
@@ -204,7 +211,7 @@
                 wrappedElementQNames.addAll(wrappedElementQNamesForOper);
             }
 
-            serviceDesc.addOperationDesc(operationDescBuilder.buildOperationDesc());
+            operations.add(operationDescBuilder.buildOperationDesc());
         }
 
         return wrappedElementQNames;

Modified: geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java?rev=171212&r1=171211&r2=171212&view=diff
==============================================================================
--- geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java (original)
+++ geronimo/trunk/modules/axis-builder/src/java/org/apache/geronimo/axis/builder/HeavyweightTypeInfoBuilder.java Sat May 21 07:32:12 2005
@@ -21,7 +21,10 @@
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -31,6 +34,8 @@
 import org.apache.axis.description.AttributeDesc;
 import org.apache.axis.description.ElementDesc;
 import org.apache.axis.description.FieldDesc;
+import org.apache.axis.description.OperationDesc;
+import org.apache.axis.description.ParameterDesc;
 import org.apache.axis.encoding.ser.ArrayDeserializerFactory;
 import org.apache.axis.encoding.ser.ArraySerializerFactory;
 import org.apache.axis.encoding.ser.Base64DeserializerFactory;
@@ -69,18 +74,22 @@
     private final ClassLoader cl;
     private final Map schemaTypeKeyToSchemaTypeMap;
     private final Set wrapperElementQNames;
+    private final Collection operations;
     private final boolean hasEncoded;
 
-    public HeavyweightTypeInfoBuilder(ClassLoader cl, Map schemaTypeKeyToSchemaTypeMap, Set wrapperElementQNames, boolean hasEncoded) {
+    public HeavyweightTypeInfoBuilder(ClassLoader cl, Map schemaTypeKeyToSchemaTypeMap, Set wrapperElementQNames, Collection operations, boolean hasEncoded) {
         this.cl = cl;
         this.schemaTypeKeyToSchemaTypeMap = schemaTypeKeyToSchemaTypeMap;
         this.wrapperElementQNames = wrapperElementQNames;
+        this.operations = operations;
         this.hasEncoded = hasEncoded;
     }
 
     public List buildTypeInfo(JavaWsdlMappingType mapping) throws DeploymentException {
         List typeInfoList = new ArrayList();
 
+        Set mappedTypeQNames = new HashSet();
+        
         JavaXmlTypeMappingType[] javaXmlTypeMappings = mapping.getJavaXmlTypeMappingArray();
         for (int j = 0; j < javaXmlTypeMappings.length; j++) {
             JavaXmlTypeMappingType javaXmlTypeMapping = javaXmlTypeMappings[j];
@@ -119,30 +128,9 @@
             if (schemaType == null) {
                 throw new DeploymentException("Schema type key " + key + " not found in analyzed schema: " + schemaTypeKeyToSchemaTypeMap);
             }
+            mappedTypeQNames.add(key.getqName());
 
-            Class serializerFactoryClass = null;
-            Class deserializerFactoryClass = null;
-            if (null == schemaType.getContentModel()) {
-                QName typeQName;
-                if (SchemaType.SIMPLE_CONTENT == schemaType.getContentType()) {
-                    typeQName = schemaType.getBaseType().getName();
-                } else {
-                    typeQName = schemaType.getName();
-                }
-                FactoryPair pair = (FactoryPair) qnamesToFactoryPair.get(typeQName);
-                if (null != pair) {
-                    serializerFactoryClass = pair.serializerFactoryClass;
-                    deserializerFactoryClass = pair.deserializerFactoryClass;
-                }
-                // TODO: shall we fail there?
-            }
-            if (null == serializerFactoryClass) {
-                serializerFactoryClass = BeanSerializerFactory.class;
-                deserializerFactoryClass = BeanDeserializerFactory.class;
-            }
-            
             String className = javaXmlTypeMapping.getJavaType().getStringValue().trim();
-
             Class clazz = null;
             try {
                 clazz = ClassLoading.loadClass(className, cl);
@@ -150,38 +138,101 @@
                 throw new DeploymentException("Could not load java type", e2);
             }
 
-            if (clazz.isArray()) {
-                serializerFactoryClass = ArraySerializerFactory.class;
-                deserializerFactoryClass = ArrayDeserializerFactory.class;
-            } else if (clazz == List.class) {
-                serializerFactoryClass = SimpleListSerializerFactory.class;
-                deserializerFactoryClass = SimpleListDeserializerFactory.class;
-            }
-
             TypeInfo.UpdatableTypeInfo internalTypeInfo = new TypeInfo.UpdatableTypeInfo();
-            internalTypeInfo.setClazz(clazz);
-
-            internalTypeInfo.setSerializerClass(serializerFactoryClass);
-            internalTypeInfo.setDeserializerClass(deserializerFactoryClass);
+            defineSerializerPair(internalTypeInfo, schemaType, clazz);
 
             populateInternalTypeInfo(clazz, key, schemaType, javaXmlTypeMapping, internalTypeInfo);
 
             typeInfoList.add(internalTypeInfo.buildTypeInfo());
         }
+        
+        for (Iterator iter = operations.iterator(); iter.hasNext();) {
+            OperationDesc operationDesc = (OperationDesc) iter.next();
+            ArrayList parameters = new ArrayList(operationDesc.getParameters());
+            if (null != operationDesc.getReturnParamDesc()) {
+                parameters.add(operationDesc.getReturnParamDesc());
+            }
+            for (Iterator iterator = parameters.iterator(); iterator.hasNext();) {
+                ParameterDesc parameterDesc = (ParameterDesc) iterator.next();
+                QName typeQName = parameterDesc.getTypeQName();
+                if (mappedTypeQNames.contains(typeQName)) {
+                    continue;
+                }
+
+                SchemaTypeKey key = new SchemaTypeKey(typeQName, true, false, false, null);
+                SchemaType schemaType = (SchemaType) schemaTypeKeyToSchemaTypeMap.get(key);
+                if (schemaType == null) {
+                    throw new DeploymentException("Schema type key " + key + " not found in analyzed schema: " + schemaTypeKeyToSchemaTypeMap);
+                }
+                mappedTypeQNames.add(key.getqName());
+	            
+                Class clazz = parameterDesc.getJavaType();
+                TypeInfo.UpdatableTypeInfo internalTypeInfo = new TypeInfo.UpdatableTypeInfo();
+                setTypeQName(internalTypeInfo, key);
+                defineSerializerPair(internalTypeInfo, schemaType, clazz);
+                internalTypeInfo.setFields(new FieldDesc[0]);
+
+                typeInfoList.add(internalTypeInfo.buildTypeInfo());
+            }
+        }
 
         return typeInfoList;
     }
 
-    private void populateInternalTypeInfo(Class javaClass, SchemaTypeKey key, SchemaType schemaType, JavaXmlTypeMappingType javaXmlTypeMapping, TypeInfo.UpdatableTypeInfo typeInfo) throws DeploymentException {
-        String ns = key.getqName().getNamespaceURI();
-        typeInfo.setCanSearchParents(schemaType.getDerivationType() == SchemaType.DT_RESTRICTION);
+    private void defineSerializerPair(TypeInfo.UpdatableTypeInfo internalTypeInfo, SchemaType schemaType, Class clazz) {
+        Class serializerFactoryClass = null;
+        Class deserializerFactoryClass = null;
+        if (null == schemaType.getContentModel()) {
+            QName typeQName;
+            if (SchemaType.SIMPLE_CONTENT == schemaType.getContentType()) {
+                typeQName = schemaType.getBaseType().getName();
+            } else {
+                typeQName = schemaType.getName();
+            }
+            FactoryPair pair = (FactoryPair) qnamesToFactoryPair.get(typeQName);
+            if (null != pair) {
+                serializerFactoryClass = pair.serializerFactoryClass;
+                deserializerFactoryClass = pair.deserializerFactoryClass;
+            }
+            // TODO: shall we fail there?
+        }
+        if (null == serializerFactoryClass) {
+            serializerFactoryClass = BeanSerializerFactory.class;
+            deserializerFactoryClass = BeanDeserializerFactory.class;
+        }
+        
+        if (clazz.isArray()) {
+            if (schemaType.isSimpleType() && SchemaType.LIST == schemaType.getSimpleVariety()) {
+                serializerFactoryClass = SimpleListSerializerFactory.class;
+                deserializerFactoryClass = SimpleListDeserializerFactory.class;
+            } else {
+                serializerFactoryClass = ArraySerializerFactory.class;
+                deserializerFactoryClass = ArrayDeserializerFactory.class;
+            }
+        } else if (clazz == List.class) {
+            serializerFactoryClass = SimpleListSerializerFactory.class;
+            deserializerFactoryClass = SimpleListDeserializerFactory.class;
+        }
+        
+        internalTypeInfo.setClazz(clazz);
+        internalTypeInfo.setSerializerClass(serializerFactoryClass);
+        internalTypeInfo.setDeserializerClass(deserializerFactoryClass);
+    }
 
+    private void setTypeQName(TypeInfo.UpdatableTypeInfo typeInfo, SchemaTypeKey key) {
         //figure out the name axis expects to look up under.
         QName axisKey = key.getElementQName();
         if (axisKey == null) {
             axisKey = key.getqName();
         }
         typeInfo.setQName(axisKey);
+    }
+    
+    private void populateInternalTypeInfo(Class javaClass, SchemaTypeKey key, SchemaType schemaType, JavaXmlTypeMappingType javaXmlTypeMapping, TypeInfo.UpdatableTypeInfo typeInfo) throws DeploymentException {
+        String ns = key.getqName().getNamespaceURI();
+        typeInfo.setCanSearchParents(schemaType.getDerivationType() == SchemaType.DT_RESTRICTION);
+
+        setTypeQName(typeInfo, key);
 
         Map paramNameToType = new HashMap();
         if (null == schemaType.getContentModel()) {