tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r547883 - in /incubator/tuscany/java/sca/modules/binding-rmi: ./ src/main/java/org/apache/tuscany/sca/binding/rmi/ src/main/java/org/apache/tuscany/sca/binding/rmi/xml/ src/main/resources/META-INF/services/ src/test/java/org/apache/tuscany/...
Date Sat, 16 Jun 2007 08:04:53 GMT
Author: antelder
Date: Sat Jun 16 01:04:51 2007
New Revision: 547883

URL: http://svn.apache.org/viewvc?view=rev&rev=547883
Log:
Move rmi binding to binding spi

Added:
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
  (with props)
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
  (with props)
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
  (with props)
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator
      - copied, changed from r547588, incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
Removed:
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/DefaultRMIBindingFactory.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/NoRemoteMethodException.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/NoRemoteServiceException.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingConstants.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingFactory.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingImpl.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingProvider.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingProviderFactory.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIModuleActivator.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIRuntimeException.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/xml/
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
    incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/NoRemoteMethodExceptionTestCase.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/NoRemoteServiceExceptionTestCase.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/META-INF/
Modified:
    incubator/tuscany/java/sca/modules/binding-rmi/pom.xml
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingInvoker.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
    incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/RMIBindingTest.composite

Modified: incubator/tuscany/java/sca/modules/binding-rmi/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/pom.xml?view=diff&rev=547883&r1=547882&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/pom.xml Sat Jun 16 01:04:51 2007
@@ -29,28 +29,10 @@
     <name>Apache Tuscany Java RMI Binding</name>
 
     <dependencies>
-        <!-- FIXME: The MessageFactoryImpl is in tuscany-core -->
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-core</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-            
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-assembly-xml</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-interface-java</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-core-spi</artifactId>
+            <artifactId>tuscany-extension-helper</artifactId>
             <version>1.0-incubating-SNAPSHOT</version>
         </dependency>
 
@@ -73,10 +55,5 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-host-embedded</artifactId>
-            <version>1.0-incubating-SNAPSHOT</version>
-        </dependency>
     </dependencies>
 </project>

Modified: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java?view=diff&rev=547883&r1=547882&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java
(original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java
Sat Jun 16 01:04:51 2007
@@ -16,40 +16,58 @@
  */
 package org.apache.tuscany.sca.binding.rmi;
 
-import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.spi.utils.AbstractBinding;
 
 /**
  * Represents a binding to an RMI service.
  */
-public interface RMIBinding extends Binding {
+public class RMIBinding extends AbstractBinding {
+
+    private String host;
+    private String port;
+    private String serviceName;
+
     /**
      * @return the host name of the RMI Service
      */
-    String getRmiHostName();
+    public String getHost() {
+        return host;
+    }
 
     /**
      * @param rmiHostName the hostname of the RMI Service
      */
-    void setRmiHostName(String rmiHostName);
+    public void setHost(String rmiHostName) {
+        this.host = rmiHostName;
+    }
 
     /**
      * @return the port number for the RMI Service
      */
-    String getRmiPort();
+    public String getPort() {
+        return port;
+    }
 
     /**
      * @param rmiPort the port number for the RMI Service
      */
-    void setRmiPort(String rmiPort);
+    public void setPort(String rmiPort) {
+        this.port = rmiPort;
+    }
 
     /**
      * @return returns the RMI Service Name
      */
-    String getRmiServiceName();
+    public String getServiceName() {
+        return serviceName;
+    }
 
     /**
      * Sets the service name for the RMI Server
+     * 
      * @param rmiServiceName the name of the RMI service
      */
-    void setRmiServiceName(String rmiServiceName);
+    public void setServiceName(String rmiServiceName) {
+        this.serviceName = rmiServiceName;
+    }
 }

Added: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java?view=auto&rev=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
(added)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
Sat Jun 16 01:04:51 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.binding.rmi;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.rmi.RMIHost;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.spi.BindingActivator;
+import org.apache.tuscany.sca.spi.ReferenceInvokerFactory;
+import org.apache.tuscany.sca.spi.ServiceListener;
+
+public class RMIBindingActivator implements BindingActivator<RMIBinding> {
+
+    private RMIHost rmiHost;
+
+    private QName BINDING_RMI_QNAME = new QName(Constants.SCA10_NS, "binding.rmi");
+
+    public RMIBindingActivator(RMIHost rmiHost) {
+        this.rmiHost = rmiHost;
+    }
+
+    public QName getSCDLQName() {
+        return BINDING_RMI_QNAME;
+    }
+
+    public Class<RMIBinding> getBindingClass() {
+        return RMIBinding.class;
+    }
+
+    public ReferenceInvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference
rcr, RMIBinding binding) {
+        return new RMIReferenceInvokerFactory(rc, rcr, binding, rmiHost);
+    }
+
+    public ServiceListener createServiceListener(RuntimeComponent rc, RuntimeComponentService
rcs, RMIBinding binding) {
+        return new RMIServiceListener(rc, rcs, binding, rmiHost);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingInvoker.java?view=diff&rev=547883&r1=547882&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingInvoker.java
(original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingInvoker.java
Sat Jun 16 01:04:51 2007
@@ -22,16 +22,16 @@
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.rmi.RMIHost;
-import org.apache.tuscany.sca.rmi.RMIHostException;
 
 public class RMIBindingInvoker implements Invoker {
+
     private RMIHost rmiHost;
     private String host;
     private String port;
     private String svcName;
     private Method remoteMethod;
     private Remote proxy;
-    
+
     public RMIBindingInvoker(RMIHost rmiHost, String host, String port, String svcName, Method
remoteMethod) {
         this.rmiHost = rmiHost;
         this.remoteMethod = remoteMethod;
@@ -39,45 +39,36 @@
         this.port = port;
         this.svcName = svcName;
     }
-    
+
     public Message invoke(Message msg) {
         try {
+
             Object[] args = msg.getBody();
             Object resp = invokeTarget(args);
             msg.setBody(resp);
+    
         } catch (InvocationTargetException e) {
             msg.setFaultBody(e.getCause());
         } catch (Throwable e) {
             msg.setFaultBody(e);
         }
+
         return msg;
-    }  
-    
-    
-    public Object invokeTarget(final Object payload) throws InvocationTargetException {
-        try {
-            if (proxy == null) {
-                proxy = rmiHost.findService(host, port, svcName);
-                // proxy = Naming.lookup(serviceURI);
-            }
-            remoteMethod = proxy.getClass().getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes());
-            
-            if (payload != null && !payload.getClass().isArray()) {
-                return remoteMethod.invoke(proxy, payload);
-            } else {
-                return remoteMethod.invoke(proxy, (Object[])payload);
-                
-            }
-        } catch (RMIHostException e) {
-            // the method we are passed must be accessible
-            throw new AssertionError(e);
-        } catch (IllegalAccessException e) {
-            // the method we are passed must be accessible
-            throw new AssertionError(e);
-        } catch (NoSuchMethodException e) {
-            throw new AssertionError(e);
+    }
+
+    public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
+        if (proxy == null) {
+            proxy = rmiHost.findService(host, port, svcName);
+            // proxy = Naming.lookup(serviceURI);
         }
 
+        remoteMethod = proxy.getClass().getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes());
+
+        if (payload != null && !payload.getClass().isArray()) {
+            return remoteMethod.invoke(proxy, payload);
+        } else {
+            return remoteMethod.invoke(proxy, (Object[])payload);
+        }
     }
-    
+
 }

Added: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java?view=auto&rev=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
(added)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
Sat Jun 16 01:04:51 2007
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.binding.rmi;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.rmi.RMIHost;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.spi.ReferenceInvokerFactory;
+import org.osoa.sca.ServiceRuntimeException;
+
+public class RMIReferenceInvokerFactory implements ReferenceInvokerFactory {
+
+    RuntimeComponentReference reference;
+    RMIHost rmiHost;
+    RMIBinding binding;
+
+    public RMIReferenceInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr,
RMIBinding binding, RMIHost rmiHost) {
+        this.reference = rcr;
+        this.rmiHost = rmiHost;
+        this.binding = binding;
+    }
+
+    public Invoker createInvoker(Operation operation) {
+        try {
+
+            Class<?> iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass();
+            Method remoteMethod = JavaInterfaceUtil.findMethod(iface, operation);
+
+            return new RMIBindingInvoker(rmiHost, binding.getHost(), binding.getPort(), binding.getServiceName(),
remoteMethod);
+
+        } catch (NoSuchMethodException e) {
+            throw new ServiceRuntimeException(operation.toString(), e);
+        }
+    }
+
+    public void start() {
+    }
+
+    public void stop() {
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java?view=auto&rev=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
(added)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
Sat Jun 16 01:04:51 2007
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.binding.rmi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.Remote;
+import java.rmi.server.UnicastRemoteObject;
+
+import net.sf.cglib.asm.ClassWriter;
+import net.sf.cglib.asm.Constants;
+import net.sf.cglib.asm.Type;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.tuscany.sca.core.invocation.MessageImpl;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.rmi.RMIHost;
+import org.apache.tuscany.sca.rmi.RMIHostException;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.spi.ServiceListener;
+import org.osoa.sca.ServiceRuntimeException;
+
+public class RMIServiceListener implements ServiceListener {
+
+    RuntimeComponent component;
+    RuntimeComponentService service;
+    private RMIBinding binding;
+    RMIHost rmiHost;
+
+    public RMIServiceListener(RuntimeComponent rc, RuntimeComponentService rcs, RMIBinding
binding, RMIHost rmiHost) {
+        this.component = rc;
+        this.service = rcs;
+        this.binding = binding;
+        this.rmiHost = rmiHost;
+    }
+
+    public void start() {
+        // URI uri = URI.create(component.getURI() + "/" + binding.getName());
+        // binding.setURI(uri.toString());
+
+        Interface serviceInterface = service.getInterfaceContract().getInterface();
+
+        Remote rmiProxy = createRmiService(serviceInterface);
+
+        try {
+
+            rmiHost.registerService(binding.getServiceName(), getPort(binding.getPort()),
rmiProxy);
+
+        } catch (RMIHostException e) {
+            throw new ServiceRuntimeException(e);
+        }
+    }
+
+    public void stop() {
+    }
+
+    protected int getPort(String port) {
+        int portNumber = RMIHost.RMI_DEFAULT_PORT;
+        if (port != null && port.length() > 0) {
+            portNumber = Integer.decode(port);
+        }
+        return portNumber;
+    }
+
+    protected Remote createRmiService(final Interface serviceInterface) {
+        Enhancer enhancer = new Enhancer();
+        enhancer.setSuperclass(UnicastRemoteObject.class);
+        enhancer.setCallback(new MethodInterceptor() {
+            public Object intercept(Object arg0, Method method, Object[] args, MethodProxy
arg3) throws Throwable {
+                return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()),
args);
+            }
+        });
+        Class targetJavaInterface = getTargetJavaClass(serviceInterface);
+        if (!Remote.class.isAssignableFrom(targetJavaInterface)) {
+            RMIServiceClassLoader classloader = new RMIServiceClassLoader(getClass().getClassLoader());
+            final byte[] byteCode = generateRemoteInterface(targetJavaInterface);
+            targetJavaInterface = classloader.defineClass(byteCode);
+            enhancer.setClassLoader(classloader);
+        }
+        enhancer.setInterfaces(new Class[] {targetJavaInterface});
+        return (Remote)enhancer.create();
+    }
+
+    protected Object invokeTarget(Operation op, Object[] args) throws InvocationTargetException
{
+
+        Message requestMsg = new MessageImpl();
+        ThreadMessageContext.setMessageContext(requestMsg);
+        requestMsg.setBody(args);
+
+        Message responseMsg = service.getInvoker(binding, op).invoke(requestMsg);
+
+        if (responseMsg.isFault()) {
+            throw new InvocationTargetException((Throwable)responseMsg.getBody());
+        }
+        return responseMsg.getBody();
+    }
+
+
+    /**
+     * if the interface of the component whose serviceBindings must be exposed as RMI Service,
does not
+     * implement java.rmi.Remote, then generate such an interface. This method will stop
with just 
+     * generating the bytecode. Defining the class from the byte code must be the responsibility
of the 
+     * caller of this method, since it requires a classloader to be created to define and
load this interface.
+     */
+    protected byte[] generateRemoteInterface(Class serviceInterface) {
+        String interfazeName = serviceInterface.getCanonicalName();
+        ClassWriter cw = new ClassWriter(false);
+
+        String simpleName = serviceInterface.getSimpleName();
+        cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE,
interfazeName
+            .replace('.', '/'), "java/lang/Object", new String[] {"java/rmi/Remote"}, simpleName
+ ".java");
+
+        StringBuffer argsAndReturn = null;
+        Method[] methods = serviceInterface.getMethods();
+        for (Method method : methods) {
+            argsAndReturn = new StringBuffer("(");
+            Class[] paramTypes = method.getParameterTypes();
+            Class returnType = method.getReturnType();
+
+            for (Class paramType : paramTypes) {
+                argsAndReturn.append(Type.getType(paramType));
+            }
+            argsAndReturn.append(")");
+            argsAndReturn.append(Type.getType(returnType));
+
+            cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT,
+                           method.getName(),
+                           argsAndReturn.toString(),
+                           new String[] {"java/rmi/RemoteException"},
+                           null);
+        }
+        cw.visitEnd();
+        return cw.toByteArray();
+    }
+
+    protected Class<?> getTargetJavaClass(Interface targetInterface) {
+        // TODO: right now assume that the target is always a Java
+        // Implementation. Need to figure out
+        // how to generate Java Interface in cases where the target is not a
+        // Java Implementation
+        return ((JavaInterface)targetInterface).getJavaClass();
+    }
+
+    protected class RMIServiceClassLoader extends ClassLoader {
+        public RMIServiceClassLoader(ClassLoader parent) {
+            super(parent);
+        }
+
+        public Class defineClass(byte[] byteArray) {
+            return defineClass(null, byteArray, 0, byteArray.length);
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIServiceListener.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator
(from r547588, incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator?view=diff&rev=547883&p1=incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator&r1=547588&p2=incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
(original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator
Sat Jun 16 01:04:51 2007
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.    
 # Implementation class for the ExtensionActivator
-org.apache.tuscany.sca.binding.rmi.RMIModuleActivator
+org.apache.tuscany.sca.binding.rmi.RMIBindingActivator

Modified: incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java?view=diff&rev=547883&r1=547882&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java
Sat Jun 16 01:04:51 2007
@@ -46,9 +46,13 @@
     
     @BeforeClass
     public static void init() throws Exception {
+try {
         domain = SCADomain.newInstance("RMIBindingTest.composite");
         helloWorldRmiService = 
             domain.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent");
+} catch (Exception e) {
+    e.printStackTrace();
+}
   }
     
     @AfterClass

Modified: incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/RMIBindingTest.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/RMIBindingTest.composite?view=diff&rev=547883&r1=547882&r2=547883
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/RMIBindingTest.composite
(original)
+++ incubator/tuscany/java/sca/modules/binding-rmi/src/test/resources/RMIBindingTest.composite
Sat Jun 16 01:04:51 2007
@@ -18,7 +18,6 @@
  * under the License.    
  -->
 <composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
-           xmlns:rmi="http://tuscany.apache.org/xmlns/binding/rmi/1.0-SNAPSHOT"
            name="HelloWorldRmiComposite">
 
 	<service name="HelloWorldRmiService" promote="HelloWorldServiceComponent">



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message