summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/interface-java
diff options
context:
space:
mode:
authorscottkurz <scottkurz@13f79535-47bb-0310-9956-ffa450edef68>2011-01-25 03:38:57 +0000
committerscottkurz <scottkurz@13f79535-47bb-0310-9956-ffa450edef68>2011-01-25 03:38:57 +0000
commita9efdb471e6d1cdb32776fa12a459f076bab7419 (patch)
treeb4b6f0a5a86c2694d9edadf13a0bdaf27e0cedda /sca-java-2.x/trunk/modules/interface-java
parent08a9cd21f56f16bba739d6a3ec1c4f0c6887d37d (diff)
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
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-java')
-rw-r--r--sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java12
-rw-r--r--sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java169
-rw-r--r--sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java13
3 files changed, 110 insertions, 84 deletions
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<Method> 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<String, Type> 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<String, Type> 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 <T> List<Operation> getOperations(Class<T> clazz,
+ private <T> List<Operation> getOperations(Class<T> clazz,
boolean remotable,
String ns) throws InvalidInterfaceException {
@@ -217,7 +217,7 @@ public class JavaInterfaceIntrospectorImpl {
List<Operation> operations = new ArrayList<Operation>(methods.length);
Set<String> names = remotable ? new HashSet<String>() : 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<XMLType> returnDataType =
- returnType == void.class ? null : new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, returnType, method
- .getGenericReturnType(), xmlReturnType);
-
-
+
+ XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null);
+ DataType<XMLType> returnDataType = null;
+ if (returnType == void.class) {
+ operation.setReturnTypeVoid(true);
+ } else {
+ returnDataType = new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, returnType,
+ method.getGenericReturnType(), xmlReturnType);
+ operation.setReturnTypeVoid(false);
+ }
+
// Handle Input Types
- List<DataType> paramDataTypes = new ArrayList<DataType>(parameterTypes.length);
- List<Type> genericHolderTypes = new ArrayList<Type>();
- List<Class<?>> physicalHolderTypes = new ArrayList<Class<?>>();
+ 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];
XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i), null);
-
+
DataTypeImpl<XMLType> xmlDataType = new DataTypeImpl<XMLType>(
- UNKNOWN_DATABINDING, paramType, genericParamTypes[i],xmlParamType);
+ UNKNOWN_DATABINDING, paramType, genericParamTypes[i],xmlParamType);
ParameterMode mode = ParameterMode.IN;
// 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());
- }
+ 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<DataType> outputDataTypes = new ArrayList<DataType>();
- if (returnDataType != null) {
+ if (!operation.hasReturnTypeVoid()) {
outputDataTypes.add(returnDataType);
}
@@ -314,7 +317,7 @@ public class JavaInterfaceIntrospectorImpl {
List<DataType> faultDataTypes = new ArrayList<DataType>(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<XMLType> faultDataType =
new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i], xmlFaultType);
faultDataTypes.add(new DataTypeImpl<DataType>(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i],
- faultDataType));
+ faultDataType));
}
}
DataType<List<DataType>> inputType =
new DataTypeImpl<List<DataType>>(IDL_INPUT, Object[].class, paramDataTypes);
DataType<List<DataType>> outputType =
- new DataTypeImpl<List<DataType>>(IDL_OUTPUT, Object[].class, outputDataTypes);
+ new DataTypeImpl<List<DataType>>(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<Class<?>> returnTypes = new ArrayList<Class<?>>();
- 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<Class<?>> returnTypes = new ArrayList<Class<?>>();
+ 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<T>, 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;
+ }
+
}