From 51e5ca754d3d79393793fddcfd6079f3b0c70d8a Mon Sep 17 00:00:00 2001 From: bdaniel Date: Fri, 17 Sep 2010 18:10:18 +0000 Subject: TUSCANY-3664 Migrate 1.x Holder support to 2.x and add support for non-void methods and multiple Holders git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@998232 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/impl/JavaInterfaceIntrospectorImpl.java | 45 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'sca-java-2.x/trunk/modules/interface-java/src/main/java') diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java index de32136abc..12b312ffb7 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java @@ -35,6 +35,7 @@ import java.util.concurrent.Future; import javax.xml.namespace.QName; import javax.xml.ws.AsyncHandler; +import javax.xml.ws.Holder; import javax.xml.ws.Response; import org.apache.tuscany.sca.interfacedef.DataType; @@ -44,6 +45,7 @@ import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.InvalidOperationException; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.OverloadedOperationException; +import org.apache.tuscany.sca.interfacedef.ParameterMode; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; @@ -220,6 +222,9 @@ public class JavaInterfaceIntrospectorImpl { } } + JavaOperation operation = new JavaOperationImpl(); + operation.setName(name); + // Set outputType to null for void XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null); DataType returnDataType = @@ -229,10 +234,24 @@ public class JavaInterfaceIntrospectorImpl { Type[] genericParamTypes = method.getGenericParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { Class paramType = parameterTypes[i]; - XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i), null); - paramDataTypes.add(new DataTypeImpl(UNKNOWN_DATABINDING, paramType, genericParamTypes[i], - xmlParamType)); + XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i), null); + + DataTypeImpl xmlDataType = new DataTypeImpl( + UNKNOWN_DATABINDING, paramType, genericParamTypes[i],xmlParamType); + ParameterMode mode = ParameterMode.IN; + // Holder pattern. Physical types of Holder classes are updated to to aid in transformations. + if ( Holder.class == paramType) { + Type firstActual = getFirstActualType( genericParamTypes[ i ] ); + if ( firstActual != null ) { + xmlDataType.setPhysical( (Class)firstActual ); + mode = ParameterMode.INOUT; + } + } + paramDataTypes.add( xmlDataType); + operation.getParameterModes().add(mode); } + + // Fault types List faultDataTypes = new ArrayList(faultTypes.length); Type[] genericFaultTypes = method.getGenericExceptionTypes(); if( method.isAnnotationPresent(AsyncFault.class) ) { @@ -254,8 +273,7 @@ public class JavaInterfaceIntrospectorImpl { DataType> inputType = new DataTypeImpl>(IDL_INPUT, Object[].class, paramDataTypes); - JavaOperation operation = new JavaOperationImpl(); - operation.setName(name); + operation.setInputType(inputType); operation.setOutputType(returnDataType); operation.setFaultTypes(faultDataTypes); @@ -305,5 +323,22 @@ public class JavaInterfaceIntrospectorImpl { } return false; } + + + /** + * Given a Class, returns T, otherwise null. + * @param testClass + * @return + */ + protected static Type getFirstActualType(Type genericType) { + if (genericType instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)genericType; + Type[] actualTypes = pType.getActualTypeArguments(); + if ((actualTypes != null) && (actualTypes.length > 0)) { + return actualTypes[0]; + } + } + return null; + } } -- cgit v1.2.3