From e32b64d161654e654012f343e795d069bcf40ff8 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 19 Sep 2011 11:45:40 +0000 Subject: TUSCANY-3948: Apply patch from Greg Dritschler to support @Remotable on implementation class, reference field, or reference setter method git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1172577 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/introspect/impl/ReferenceProcessor.java | 21 +++++++++++++++++++-- .../java/introspect/impl/ServiceProcessor.java | 20 ++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) (limited to 'sca-java-2.x/trunk/modules/implementation-java/src/main/java/org') diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java index 225099758d..cb612bd224 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java @@ -45,6 +45,7 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.oasisopen.sca.ServiceReference; import org.oasisopen.sca.annotation.AllowsPassByReference; import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Remotable; /** * Processes an {@link @Reference} annotation, updating the component type with @@ -219,11 +220,27 @@ public class ReferenceProcessor extends BaseJavaClassVisitor { } baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, genericType); } + // The reference can have a Remotable annotation. This forces the interface to be + // remotable even if the interface doesn't have a Remotable annotation. + boolean forceRemotable = element.getAnnotation(Remotable.class) != null; + // If the reference element is a setter method, element.getAnnotation() looks at + // the method-level annotations only. Compliance test POJO_8017 puts the + // Remotable annotation on the setter method's argument, so we need some special + // logic to look at the argument. + if (!forceRemotable && element.getElementType() == ElementType.PARAMETER && (element.getAnchor() instanceof Method)) { + Annotation argAnnotations[] = ((Method)element.getAnchor()).getParameterAnnotations()[0]; + for (int j = 0; j < argAnnotations.length; j++) { + if (argAnnotations[j].annotationType() == Remotable.class) { + forceRemotable = true; + break; + } + } + } try { - JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(baseType); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(baseType, forceRemotable); reference.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass(), forceRemotable); reference.getInterfaceContract().setCallbackInterface(callbackInterface); } } catch (InvalidInterfaceException e) { diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java index 6ad2140304..b2aa01ab92 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java @@ -195,8 +195,12 @@ public class ServiceProcessor extends BaseJavaClassVisitor { Service service = assemblyFactory.createService(); JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); service.setInterfaceContract(interfaceContract); - - JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze); + + // The implementation class can have a Remotable annotation. This forces all service + // interfaces to be remotable even if the interfaces do not have a Remotable annotation. + boolean forceRemotable = clazz.getAnnotation(Remotable.class) != null; + + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze, forceRemotable); if (name == null) { String serviceName = interfaze.getSimpleName(); @@ -212,19 +216,11 @@ public class ServiceProcessor extends BaseJavaClassVisitor { } else { service.setName(name); } - - - boolean remotable = clazz.getAnnotation(Remotable.class) != null; - if (remotable){ - callInterface.setRemotable(true); - } + service.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); - if (remotable){ - callbackInterface.setRemotable(true); - } + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass(), forceRemotable); service.getInterfaceContract().setCallbackInterface(callbackInterface); } return service; -- cgit v1.2.3