You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sc...@apache.org on 2011/01/26 02:18:02 UTC

svn commit: r1063548 - in /tuscany/sca-java-2.x/trunk/modules: binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/ databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/ databinding/src/main/java/org/apache/tusc...

Author: scottkurz
Date: Wed Jan 26 01:18:02 2011
New Revision: 1063548

URL: http://svn.apache.org/viewvc?rev=1063548&view=rev
Log:
Fix more issues with multiple outputs.

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
    tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
    tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java
    tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
    tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java Wed Jan 26 01:18:02 2011
@@ -753,39 +753,22 @@ public class Interface2WSDLGenerator {
             Method method = ((JavaOperation)operation).getJavaMethod();
             
             /*
-             * Making this change, though not understanding:
-             * 
-             * 1. Whether we can assume JAXWSJavaInterfaceProcessor was already used to process
-             * 
-             * 2. What the purpose is of calling getElementInfo() when we already have an ElementInfo
-             * 
+             * Making this change, though not understanding
+             * whether we can assume JAXWSJavaInterfaceProcessor was already used to process
              */
             if (input) {
-                Class<?>[] paramTypes = method.getParameterTypes();
-                for (int i = 0, inputsSeen = 0; i < paramTypes.length; i++) {
-                	ParameterMode mode = operation.getParameterModes().get(i);
-                	if (!mode.equals(ParameterMode.OUT)) {
-                		DataType dataType = operation.getInputType().getLogical().get(i);
-                		elements.set(inputsSeen, getElementInfo(paramTypes[i], dataType, elements.get(inputsSeen).getQName(), helpers));
-                		inputsSeen++;
-                	}
+                List<DataType> inputDTs = operation.getInputType().getLogical();
+                for (int i = 0; i < inputDTs.size(); i++) {
+                    DataType nextInput = inputDTs.get(i);
+                    elements.set(i, getElementInfo(nextInput.getPhysical(), nextInput, elements.get(i).getQName(), helpers));
                 }
+
             } else {
-            	int outputsSeen = 0;
-                Class<?> returnType = method.getReturnType();
-                if (returnType != Void.TYPE) {
-                    DataType dataType = operation.getOutputType().getLogical().get(0);
-                    elements.set(outputsSeen++, getElementInfo(returnType, dataType, elements.get(0).getQName(), helpers));
+                List<DataType> outputDTs = operation.getOutputType().getLogical();
+                for (int i = 0; i < outputDTs.size(); i++) {
+                    DataType nextOutput = outputDTs.get(i);
+                    elements.set(i, getElementInfo(nextOutput.getPhysical(), nextOutput, elements.get(i).getQName(), helpers));
                 }
-                Class<?>[] paramTypes = method.getParameterTypes();
-                for (int i = 0; i < paramTypes.length; i++) {
-                	ParameterMode mode = operation.getParameterModes().get(i);
-                	if (!mode.equals(ParameterMode.IN)) {
-                		DataType dataType = operation.getOutputType().getLogical().get(i);
-                		elements.set(outputsSeen, getElementInfo(paramTypes[i], dataType, elements.get(outputsSeen).getQName(), helpers));
-                		outputsSeen++;
-                	}
-                }                
             }
         }
         return part;

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java Wed Jan 26 01:18:02 2011
@@ -462,9 +462,8 @@ public final class JAXBContextHelper {
         {
             for (DataType dt1 : op.getInputType().getLogical()) {
                 dataTypes.add(dt1);
-            }
-            DataType dt2 = op.getOutputType();
-            if (dt2 != null) {
+            }            
+            for (DataType dt2 : op.getOutputType().getLogical()) {
                 dataTypes.add(dt2);
             }
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java Wed Jan 26 01:18:02 2011
@@ -559,30 +559,26 @@ public class MediatorImpl implements Med
         List<DataType> inputTypesTarget = targetOperation == null ? null : targetOperation.getInputType().getLogical();
         Object[] copy = new Object[data.length];
         Map<Object, Object> map = new IdentityHashMap<Object, Object>();
-        for (int i = 0, nextIndex = 0; i < inputTypes.size(); i++) {
-            // Account for OUT-only parameters.  Would be more thorough to look at targetOperation
-            // and ensure it has the same parameter mode, but we'll let that go for now.
-            ParameterMode mode = sourceOperation.getParameterModes().get(i);
-            if (!mode.equals(ParameterMode.OUT)) {
-                Object arg = data[nextIndex];
-                if (arg == null) {
-                    copy[nextIndex] = null;
+        
+        // OUT-only parameters have already been filtered out of the inputTypes List.
+        for (int i = 0; i < inputTypes.size(); i++) {
+            Object arg = data[i];
+            if (arg == null) {
+                copy[i] = null;
+            } else {
+                Object copiedArg = map.get(arg);
+                if (copiedArg != null) {
+                    copy[i] = copiedArg;
                 } else {
-                    Object copiedArg = map.get(arg);
-                    if (copiedArg != null) {
-                        copy[nextIndex] = copiedArg;
-                    } else {
-                        copiedArg =
-                            copy(arg,
-                                 inputTypes.get(i),
-                                 inputTypesTarget == null ? null : inputTypesTarget.get(i),
-                                     sourceOperation,
-                                     targetOperation);
-                        map.put(arg, copiedArg);
-                        copy[nextIndex] = copiedArg;
-                    }
+                    copiedArg =
+                        copy(arg,
+                             inputTypes.get(i),
+                             inputTypesTarget == null ? null : inputTypesTarget.get(i),
+                                 sourceOperation,
+                                 targetOperation);
+                    map.put(arg, copiedArg);
+                    copy[i] = copiedArg;
                 }
-                nextIndex++;
             }
         }
         return copy;

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java Wed Jan 26 01:18:02 2011
@@ -132,14 +132,13 @@ public class JavaImplementationInvoker i
             // Holder pattern. Any payload parameters <T> which are should be in holders are placed in Holder<T>.
             // Only check Holder for remotable interfaces
             if (imethod != null && op.getInterface().isRemotable()) {
-                List<DataType> inputTypes = op.getInputType().getLogical();
                 Object[] payloadArray = (Object[])payload;
                 List<Object> payloadList = new ArrayList<Object>();
-                for (int i = 0, nextIndex = 0; i < inputTypes.size(); i++) {
-                    ParameterMode mode = op.getParameterModes().get(i);
-                    if (ParameterMode.IN == mode ) {
+                int nextIndex = 0;
+                for (ParameterMode mode : op.getParameterModes()) {                    
+                    if (mode.equals(ParameterMode.IN)) {
                         payloadList.add(payloadArray[nextIndex++]);
-                    } else if (ParameterMode.INOUT == mode ) {
+                    } else if (mode.equals(ParameterMode.INOUT)) {
                         // Promote array params from [<T>] to [Holder<T>]                  
                         Object item = payloadArray[nextIndex++];                           
                         Holder itemHolder = new Holder(item);

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java Wed Jan 26 01:18:02 2011
@@ -186,11 +186,7 @@ public class JAXWSJavaInterfaceProcessor
                     }
                     ParameterMode mode = operation.getParameterModes().get(i);
                 }
-                
-                // 
-                // Note for BARE mapping this will NOT be WS-I compliant, but let's assume this is not the place to 
-                // worry about non-compliance, and keep on going. 
-                //                 
+        
                 WebResult result = method.getAnnotation(WebResult.class);
                 if (result != null) {
                     String ns = getValue(result.targetNamespace(), tns);
@@ -351,6 +347,19 @@ public class JAXWSJavaInterfaceProcessor
 
                 operation.setWrapper(wrapperInfo);
             }
+            
+            // In both bare and wrapped cases, remove OUT-only parameters from input DataType.
+            // This is a key point then because it's the last time in which the number of parameters in 
+            // Java matches the number of logical inputs.  After this, things will be out of synch, for
+            // example the number of parameter modes won't match the number of inputs.
+            List<ParameterMode> parmModes = operation.getParameterModes();
+            List<DataType> inputDTs = operation.getInputType().getLogical();
+            for (int i = parmModes.size() - 1; i>=0; i--) {
+                if (parmModes.get(i).equals(ParameterMode.OUT)) {
+                    inputDTs.remove(i);
+                }
+            }
+            
         }
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java Wed Jan 26 01:18:02 2011
@@ -259,6 +259,8 @@ public class JavaInterfaceIntrospectorIm
             JavaOperation operation = new JavaOperationImpl();
             operation.setName(name);
 
+            // Given details of Holder mapping, it's easier to handle output first.                
+            List<DataType> outputDataTypes = new ArrayList<DataType>();
             XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null);            
             DataType<XMLType> returnDataType = null;
             if (returnType == void.class) {
@@ -267,12 +269,11 @@ public class JavaInterfaceIntrospectorIm
                  returnDataType = new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, returnType, 
                      method.getGenericReturnType(), xmlReturnType);
                  operation.setReturnTypeVoid(false);
+                 outputDataTypes.add(returnDataType);
             }
 
             // Handle Input Types
             List<DataType> paramDataTypes = new ArrayList<DataType>(parameterTypes.length);
-            List<Type> genericHolderTypes = new ArrayList<Type>();
-            List<Class<?>> physicalHolderTypes = new ArrayList<Class<?>>();
             Type[] genericParamTypes = method.getGenericParameterTypes();
             for (int i = 0; i < parameterTypes.length; i++) {
                 Class<?> paramType = parameterTypes[i];
@@ -284,35 +285,17 @@ public class JavaInterfaceIntrospectorIm
                 // Holder pattern. Physical types of Holder<T> classes are updated to <T> to aid in transformations.
                 if ( Holder.class == paramType) {
                     hasMultipleOutputs = true;
-                    genericHolderTypes.add(genericParamTypes[i]);
                     Type firstActual = getFirstActualType( genericParamTypes[ i ] );
                     if ( firstActual != null ) {
-                        physicalHolderTypes.add((Class<?>)firstActual);
                         xmlDataType.setPhysical( (Class<?>)firstActual );
                         mode = ParameterMode.INOUT;
-                    } else {
-                        physicalHolderTypes.add(xmlDataType.getPhysical());
-                    }
+                    } 
+                    outputDataTypes.add(xmlDataType);
                 }
                 paramDataTypes.add( xmlDataType);
                 operation.getParameterModes().add(mode);
             }
 
-            // Get Output Types, but skip over void return type                
-            List<DataType> outputDataTypes = new ArrayList<DataType>();
-            if (!operation.hasReturnTypeVoid()) {
-                outputDataTypes.add(returnDataType);
-            }
-
-            // Start at 1, for the first holder, since we already accounted for the return type itself
-            for ( int i=1; i < allOutputTypes.length; i++ ) {
-                Class<?> paramType = allOutputTypes[i];
-                XMLType xmlOutputType = new XMLType(new QName(ns, "out" + i), null);
-                DataTypeImpl<XMLType> xmlDataType = xmlDataType = new DataTypeImpl<XMLType>(
-                    UNKNOWN_DATABINDING, physicalHolderTypes.get(i-1), genericHolderTypes.get(i-1), xmlOutputType);
-                outputDataTypes.add(xmlDataType);
-            }
-
             // Fault types                                                          
             List<DataType> faultDataTypes = new ArrayList<DataType>(faultTypes.length);
             Type[] genericFaultTypes = method.getGenericExceptionTypes();

Modified: tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java?rev=1063548&r1=1063547&r2=1063548&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java Wed Jan 26 01:18:02 2011
@@ -27,6 +27,7 @@ import java.util.List;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.ParameterMode;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
 
@@ -64,6 +65,17 @@ public final class JavaInterfaceUtil {
         }
         Interface interface1 = operation.getInterface();
         int numParams = operation.getInputType().getLogical().size();
+        
+        // Account for OUT-only in matching. (Should we cache this number in JavaOperation?) 
+        List<ParameterMode> parmModes = operation.getParameterModes();
+        int numOutOnlyHolders = 0;
+        for (ParameterMode mode : parmModes) {
+            if (mode.equals(ParameterMode.OUT)) {
+                numOutOnlyHolders++;
+            }
+        }
+        numParams += numOutOnlyHolders;
+        
         if (interface1 != null && interface1.isRemotable()) {
             List<Method> matchingMethods = new ArrayList<Method>();
             for (Method m : implClass.getMethods()) {
@@ -138,6 +150,7 @@ public final class JavaInterfaceUtil {
     /**
      * @Deprecated
      */
+    //TODO - account for Holder(s)
     private static Class<?>[] getPhysicalTypes(Operation operation) {
         DataType<List<DataType>> inputType = operation.getInputType();
         if (inputType == null) {
@@ -178,6 +191,7 @@ public final class JavaInterfaceUtil {
      * 
      * @return true if the operation matches, false if does not
      */
+    //TODO - account for Holder(s)    
     private static boolean match(Operation operation, Method method) {
         Class<?>[] params = method.getParameterTypes();
         DataType<List<DataType>> inputType = operation.getInputType();