From a9efdb471e6d1cdb32776fa12a459f076bab7419 Mon Sep 17 00:00:00 2001 From: scottkurz Date: Tue, 25 Jan 2011 03:38:57 +0000 Subject: Fix bare+JAXB wsdlgen case. Fix Holder+void_return_type case. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1063125 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/interfacedef/java/JavaOperation.java | 12 ++ .../java/impl/JavaInterfaceIntrospectorImpl.java | 169 +++++++++++---------- .../interfacedef/java/impl/JavaOperationImpl.java | 13 +- 3 files changed, 110 insertions(+), 84 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/JavaOperation.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java index e894ac279b..ee8cea8740 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java @@ -66,5 +66,17 @@ public interface JavaOperation extends Operation { * @return - true if the operation is async server style */ public boolean isAsyncServer(); + + /** + * Indicates whether the underlying Java method has void return type. + * @return - true if the Java method has void return type. + */ + public boolean hasReturnTypeVoid(); + + /** + * Sets whether the underlying Java method has void return type. + * @param flag - "true" marks this operation as having void return type. + */ + public void setReturnTypeVoid(boolean flag); } 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 0d1325e6a8..0d1e832faf 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 @@ -77,11 +77,11 @@ public class JavaInterfaceIntrospectorImpl { } public void introspectInterface(JavaInterface javaInterface, Class clazz) throws InvalidInterfaceException { - + if(!loadedVisitors) { this.visitors = javaFactory.getInterfaceVisitors(); } - + javaInterface.setJavaClass(clazz); boolean remotable = clazz.isAnnotationPresent(Remotable.class); @@ -104,7 +104,7 @@ public class JavaInterfaceIntrospectorImpl { } } } - + if (remotable) { if (javaInterface.isRemotableSet() && javaInterface.isRemotable() == false) { throw new InvalidAnnotationException("[JCA30005] @Remotable annotation present in a interface marked as not remotable in the SCDL", Remotable.class); @@ -123,11 +123,11 @@ public class JavaInterfaceIntrospectorImpl { callbackClass = callback.value(); if (remotable && !callbackClass.isAnnotationPresent(Remotable.class)) { throw new InvalidCallbackException("Callback " + callbackClass.getName() + - " must be remotable on remotable interface " + clazz.getName()); + " must be remotable on remotable interface " + clazz.getName()); } if (!remotable && callbackClass.isAnnotationPresent(Remotable.class)) { throw new InvalidCallbackException("Callback" + callbackClass.getName() + - " must not be remotable on local interface " + clazz.getName()); + " must not be remotable on local interface " + clazz.getName()); } } else if (callback != null && Void.class.equals(callback.value())) { throw new InvalidCallbackException("No callback interface specified on callback annotation in " + clazz.getName()); @@ -141,7 +141,7 @@ public class JavaInterfaceIntrospectorImpl { for (JavaInterfaceVisitor extension : visitors) { extension.visitInterface(javaInterface); } // end for - + // Check if any methods have disallowed annotations // Check if any private methods have illegal annotations that should be raised as errors Set methods = JavaIntrospectionHelper.getMethods(clazz); @@ -151,29 +151,29 @@ public class JavaInterfaceIntrospectorImpl { } // end method introspectInterface private void checkMethodAnnotations(Method method, JavaInterface javaInterface) throws InvalidAnnotationException { - for ( Annotation a : method.getAnnotations() ) { - if( a instanceof Remotable ) { - // [JCA90053] @Remotable annotation cannot be on a method that is not a setter method - if( !JavaIntrospectionHelper.isSetter(method) ) { - throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + - " which is not a Setter method: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); - } // end if - } // end if - } // end for - - // Parameter annotations - for (Annotation[] parmAnnotations : method.getParameterAnnotations()) { - for (Annotation annotation : parmAnnotations) { - if (annotation instanceof Remotable ) { - throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + - " parameter: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); - } // end if - } // end for - } // end for - method.getParameterAnnotations(); - } // end method checkMethodAnnotations - - private Class[] getActualTypes(Type[] types, Class[] rawTypes, Map typeBindings) { + for ( Annotation a : method.getAnnotations() ) { + if( a instanceof Remotable ) { + // [JCA90053] @Remotable annotation cannot be on a method that is not a setter method + if( !JavaIntrospectionHelper.isSetter(method) ) { + throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + + " which is not a Setter method: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); + } // end if + } // end if + } // end for + + // Parameter annotations + for (Annotation[] parmAnnotations : method.getParameterAnnotations()) { + for (Annotation annotation : parmAnnotations) { + if (annotation instanceof Remotable ) { + throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + + " parameter: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); + } // end if + } // end for + } // end for + method.getParameterAnnotations(); + } // end method checkMethodAnnotations + + private Class[] getActualTypes(Type[] types, Class[] rawTypes, Map typeBindings) { Class[] actualTypes = new Class[types.length]; for (int i = 0; i < actualTypes.length; i++) { actualTypes[i] = getActualType(types[i], rawTypes[i], typeBindings); @@ -193,7 +193,7 @@ public class JavaInterfaceIntrospectorImpl { } @SuppressWarnings("rawtypes") - private List getOperations(Class clazz, + private List getOperations(Class clazz, boolean remotable, String ns) throws InvalidInterfaceException { @@ -217,7 +217,7 @@ public class JavaInterfaceIntrospectorImpl { List operations = new ArrayList(methods.length); Set names = remotable ? new HashSet() : null; for (Method method : methods) { - boolean hasMultipleOutputs = false; + boolean hasMultipleOutputs = false; if (method.getDeclaringClass() == Object.class) { // Skip the methods on the Object.class continue; @@ -236,10 +236,10 @@ public class JavaInterfaceIntrospectorImpl { Class[] faultTypes = getActualTypes(method.getGenericExceptionTypes(), method.getExceptionTypes(), typeBindings); Class[] allOutputTypes = getOutputTypes(returnType, parameterTypes); - + // For async server interfaces, faults are described using the @AsyncFaults annotation if( method.isAnnotationPresent(AsyncFault.class) ) { - faultTypes = readAsyncFaultTypes( method ); + faultTypes = readAsyncFaultTypes( method ); } // end if boolean nonBlocking = method.isAnnotationPresent(OneWay.class); @@ -258,46 +258,49 @@ 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 = - returnType == void.class ? null : new DataTypeImpl(UNKNOWN_DATABINDING, returnType, method - .getGenericReturnType(), xmlReturnType); - - + + XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null); + DataType returnDataType = null; + if (returnType == void.class) { + operation.setReturnTypeVoid(true); + } else { + returnDataType = new DataTypeImpl(UNKNOWN_DATABINDING, returnType, + method.getGenericReturnType(), xmlReturnType); + operation.setReturnTypeVoid(false); + } + // Handle Input Types - List paramDataTypes = new ArrayList(parameterTypes.length); - List genericHolderTypes = new ArrayList(); - List> physicalHolderTypes = new ArrayList>(); + List paramDataTypes = new ArrayList(parameterTypes.length); + List genericHolderTypes = new ArrayList(); + List> physicalHolderTypes = new ArrayList>(); 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); - + DataTypeImpl xmlDataType = new DataTypeImpl( - UNKNOWN_DATABINDING, paramType, genericParamTypes[i],xmlParamType); + 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) { - 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()); - } + 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()); + } } paramDataTypes.add( xmlDataType); operation.getParameterModes().add(mode); } - + // Get Output Types, but skip over void return type List outputDataTypes = new ArrayList(); - if (returnDataType != null) { + if (!operation.hasReturnTypeVoid()) { outputDataTypes.add(returnDataType); } @@ -314,7 +317,7 @@ public class JavaInterfaceIntrospectorImpl { List faultDataTypes = new ArrayList(faultTypes.length); Type[] genericFaultTypes = method.getGenericExceptionTypes(); if( method.isAnnotationPresent(AsyncFault.class) ) { - genericFaultTypes = readAsyncGenericFaultTypes( method ); + genericFaultTypes = readAsyncGenericFaultTypes( method ); } // end if for (int i = 0; i < faultTypes.length; i++) { Class faultType = faultTypes[i]; @@ -326,17 +329,17 @@ public class JavaInterfaceIntrospectorImpl { DataType faultDataType = new DataTypeImpl(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i], xmlFaultType); faultDataTypes.add(new DataTypeImpl(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i], - faultDataType)); + faultDataType)); } } DataType> inputType = new DataTypeImpl>(IDL_INPUT, Object[].class, paramDataTypes); DataType> outputType = - new DataTypeImpl>(IDL_OUTPUT, Object[].class, outputDataTypes); + new DataTypeImpl>(IDL_OUTPUT, Object[].class, outputDataTypes); operation.setOutputType(outputType); - + operation.setInputType(inputType); operation.setFaultTypes(faultDataTypes); operation.setNonBlocking(nonBlocking); @@ -346,42 +349,42 @@ public class JavaInterfaceIntrospectorImpl { } return operations; } - - private Class[] getOutputTypes(Class returnType, Class[] parameterTypes) { - - ArrayList> returnTypes = new ArrayList>(); - returnTypes.add(returnType); - for ( Class clazz : parameterTypes ) { - if ( Holder.class == clazz ) - returnTypes.add(clazz); - } - Class[] arrayType = new Class[0]; - return returnTypes.toArray(arrayType); - } + private Class[] getOutputTypes(Class returnType, Class[] parameterTypes) { + ArrayList> returnTypes = new ArrayList>(); + returnTypes.add(returnType); + for ( Class clazz : parameterTypes ) { + if ( Holder.class == clazz ) + returnTypes.add(clazz); + } + Class[] arrayType = new Class[0]; + return returnTypes.toArray(arrayType); + } - /** + + + /** * Reads the fault types declared in an @AsyncFault annotation on an async server method * @param method - the Method * @return - an array of fault/exception classes */ private Class[] readAsyncFaultTypes( Method method ) { - AsyncFault theFaults = method.getAnnotation(AsyncFault.class); - if ( theFaults == null ) return null; - return theFaults.value(); + AsyncFault theFaults = method.getAnnotation(AsyncFault.class); + if ( theFaults == null ) return null; + return theFaults.value(); } // end method readAsyncFaultTypes - + /** * Reads the generic fault types declared in an @AsyncFault annotation on an async server method * @param method - the Method * @return - an array of fault/exception classes */ private Type[] readAsyncGenericFaultTypes( Method method ) { - AsyncFault theFaults = method.getAnnotation(AsyncFault.class); - if ( theFaults == null ) return null; - return theFaults.value(); + AsyncFault theFaults = method.getAnnotation(AsyncFault.class); + if ( theFaults == null ) return null; + return theFaults.value(); } // end method readAsyncFaultTypes private boolean jaxwsAsyncMethod(Method method) { @@ -399,7 +402,7 @@ public class JavaInterfaceIntrospectorImpl { } return false; } - + /** * Given a Class, returns T, otherwise null. diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java index 7169cc164d..0aa0cfb3ee 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java @@ -34,7 +34,8 @@ public class JavaOperationImpl extends OperationImpl implements JavaOperation { private Method method; private String action; private boolean isAsyncServer = false; - + private boolean hasReturnTypeVoid = false; + public Method getJavaMethod() { return method; } @@ -97,4 +98,14 @@ public class JavaOperationImpl extends OperationImpl implements JavaOperation { return method == null ? "null" : method.toGenericString(); } + @Override + public boolean hasReturnTypeVoid() { + return hasReturnTypeVoid; + } + + @Override + public void setReturnTypeVoid(boolean flag) { + hasReturnTypeVoid = flag; + } + } -- cgit v1.2.3