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 --- .../interfacedef/java/JavaInterfaceFactory.java | 10 ++++++++- .../java/impl/JavaInterfaceFactoryImpl.java | 26 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 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/JavaInterfaceFactory.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java index 4f4e9d8268..55d694d7f8 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java @@ -45,7 +45,15 @@ public interface JavaInterfaceFactory { * @return */ JavaInterface createJavaInterface(Class interfaceClass) throws InvalidInterfaceException; - + + /** + * Creates a new Java interface model from an interface class. + * @param interfaceClass the interface class to introspect. + * @param forceRemotable allows the caller to force the interface remotable to be remotable. + * @return + */ + JavaInterface createJavaInterface(Class interfaceClass, boolean forceRemotable) throws InvalidInterfaceException; + /** * Creates the contents of a Java interface model from an interface class. * @param javaInterface the Java interface model diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java index dbedf1d55a..8229c7812d 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java @@ -41,8 +41,9 @@ public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory { private List visitors = new ArrayList(); private JavaInterfaceIntrospectorImpl introspector; - private Map, JavaInterface> cache = Collections.synchronizedMap(new WeakHashMap, JavaInterface>()); - + private Map, JavaInterface> normalCache = Collections.synchronizedMap(new WeakHashMap, JavaInterface>()); + private Map, JavaInterface> forceRemotableCache = Collections.synchronizedMap(new WeakHashMap, JavaInterface>()); + public JavaInterfaceFactoryImpl() { introspector = new JavaInterfaceIntrospectorImpl(this); } @@ -50,13 +51,32 @@ public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory { public JavaInterface createJavaInterface() { return new JavaInterfaceImpl(); } - + public JavaInterface createJavaInterface(Class interfaceClass) throws InvalidInterfaceException { + return createJavaInterface(interfaceClass, false); + } + + /** + * Creates a new Java interface model from an interface class. + * + * The forceRemotable argument allows the caller to force the interface to be remotable. + * The ServiceProcessor and ReferenceProcessor introspectors use this argument to + * propagate a @Remotable annotation on an implementation class, field, or setter method + * to the corresponding service or reference interface. The remotable flag must be set + * on the interface model prior to instrospection since some introspectors build + * different models for remotable vs local interfaces. This also means separate caches + * must be kept for interfaces that are processed normally vs. those forced to be remotable. + */ + public JavaInterface createJavaInterface(Class interfaceClass, boolean forceRemotable) throws InvalidInterfaceException { // TODO: Review if the sharing of JavaInterface is ok synchronized (interfaceClass) { + Map, JavaInterface> cache = (forceRemotable ? forceRemotableCache : normalCache); JavaInterface javaInterface = cache.get(interfaceClass); if (javaInterface == null) { javaInterface = createJavaInterface(); + if (forceRemotable) { + javaInterface.setRemotable(true); + } introspector.introspectInterface(javaInterface, interfaceClass); // Now that all introspection is complete we can mark the interface resolved javaInterface.setUnresolved(false); -- cgit v1.2.3