tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1132904 - in /tuscany/sca-java-2.x/trunk/modules/sca-client-impl: pom.xml src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
Date Tue, 07 Jun 2011 08:27:32 GMT
Author: antelder
Date: Tue Jun  7 08:27:31 2011
New Revision: 1132904

URL: http://svn.apache.org/viewvc?rev=1132904&view=rev
Log:
Sync up the sca client to match the domain node getService. Just temporary so they both work
the same to make it easier to work out how to refactor this into one bit of code

Modified:
    tuscany/sca-java-2.x/trunk/modules/sca-client-impl/pom.xml
    tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
    tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/sca-client-impl/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/pom.xml?rev=1132904&r1=1132903&r2=1132904&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/sca-client-impl/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/sca-client-impl/pom.xml Tue Jun  7 08:27:31 2011
@@ -41,6 +41,12 @@
             <artifactId>tuscany-core</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-domain-node</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>

Modified: tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java?rev=1132904&r1=1132903&r2=1132904&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
Tue Jun  7 08:27:31 2011
@@ -22,6 +22,9 @@ package org.apache.tuscany.sca.client.im
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.List;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -44,6 +47,7 @@ import org.apache.tuscany.sca.interfaced
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.runtime.DomainRegistry;
+import org.apache.tuscany.sca.runtime.ContributionDescription;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
 import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
@@ -61,7 +65,7 @@ public class RemoteServiceInvocationHand
 
     private String domainURI;
     private String serviceName;
-    private Class<?> serviceInterface;
+    public Class<?> serviceInterface;
     
     private ExtensionPointRegistry extensionsRegistry;
     private DomainRegistry domainRegistry;
@@ -85,14 +89,18 @@ public class RemoteServiceInvocationHand
      * Constructor for when there is no existing Tuscany runtime for the domain
      * @param endpointRegistry2 
      * @param extensionPointRegistry 
+     * @throws NoSuchServiceException 
      */
-    public RemoteServiceInvocationHandler(ExtensionPointRegistry extensionsRegistry, DomainRegistry
domainRegistry, String domainURI, String serviceName, Class<?> serviceInterface) throws
NoSuchDomainException {
+    public RemoteServiceInvocationHandler(ExtensionPointRegistry extensionsRegistry, DomainRegistry
domainRegistry, String domainURI, String serviceName, Class<?> serviceInterface) throws
NoSuchDomainException, NoSuchServiceException {
         this.extensionsRegistry = extensionsRegistry;
         this.domainRegistry = domainRegistry;
         this.domainURI = domainURI;
         this.serviceName = serviceName;
         this.serviceInterface = serviceInterface;
         this.reuse = false;
+        if (serviceInterface == null) {
+            getHandler();
+        }
     }
 
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -131,6 +139,14 @@ public class RemoteServiceInvocationHand
             }
             Endpoint endpoint = eps.get(0); // TODO: what should be done with multiple endpoints?
              
+            if (serviceInterface == null) {
+                try {
+                    findInterface(endpoint);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            
             RuntimeEndpointReference epr;
             try {
                 epr = createEndpointReference(javaInterfaceFactory, compositeContext, assemblyFactory,
endpoint, serviceInterface);
@@ -143,6 +159,18 @@ public class RemoteServiceInvocationHand
         return handler;
     }
 
+    private void findInterface(Endpoint endpoint) throws MalformedURLException, ClassNotFoundException
{
+        Interface iface = endpoint.getService().getInterfaceContract().getInterface();
+        if (iface instanceof JavaInterface) {
+            String curi = domainRegistry.getContainingCompositesContributionURI(endpoint.getComponent().getName());
+            if (curi != null) {
+                ContributionDescription ic = domainRegistry.getInstalledContribution(curi);
+                ClassLoader cl = new URLClassLoader(new URL[]{new URL(ic.getURL())});
+                serviceInterface = cl.loadClass(((JavaInterface)iface).getName());
+            }
+        }
+    }
+
     private RuntimeEndpointReference createEndpointReference(JavaInterfaceFactory javaInterfaceFactory,
CompositeContext compositeContext, AssemblyFactory assemblyFactory, Endpoint endpoint, Class<?>
businessInterface) throws CloneNotSupportedException, InvalidInterfaceException {
         Component component = endpoint.getComponent();
         ComponentService service = endpoint.getService();

Modified: tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java?rev=1132904&r1=1132903&r2=1132904&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
Tue Jun  7 08:27:31 2011
@@ -99,6 +99,9 @@ public class SCAClientFactoryImpl extend
             // no local runtime
             handler = new RemoteServiceInvocationHandler(extensionPointRegistry, domainRegistry,
getDomainURI().toString(), serviceURI, serviceInterface);
         }
+        if (serviceInterface == null) {
+            serviceInterface = (Class<T>)((RemoteServiceInvocationHandler)handler).serviceInterface;
+        }
 
         return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[]{serviceInterface},
handler);
     }



Mime
View raw message