Author: jboynes
Date: Sun Jul 23 11:14:09 2006
New Revision: 424773

URL: http://svn.apache.org/viewvc?rev=424773&view=rev
Log:
port RMI binding - not yet tested

Added:
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java
   (contents, props changed)
      - copied, changed from r424595, 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/loader/RMIBindingLoader.java
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java
   (with props)
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java
   (with props)
    
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
   (with props)
Removed:
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/assembly/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/builder/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/config/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/entrypoint/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/externalservice/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/loader/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/util/
    
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/resources/system.fragment
Modified:
    incubator/tuscany/java/sca/bindings/binding.rmi/pom.xml
    incubator/tuscany/java/sca/bindings/pom.xml

Modified: incubator/tuscany/java/sca/bindings/binding.rmi/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/pom.xml?rev=424773&r1=424772&r2=424773&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.rmi/pom.xml (original)
+++ incubator/tuscany/java/sca/bindings/binding.rmi/pom.xml Sun Jul 23 11:14:09 
2006
@@ -26,13 +26,13 @@
 
     <modelVersion>4.0.0</modelVersion>
     <artifactId>rmi</artifactId>
-    <name>Tuscany RMI Binding</name>
+    <name>Apache Tuscany RMI Binding</name>
     <description>Implementation of the SCA RMI Binding</description>
 
     <dependencies>
         <dependency>
             <groupId>org.apache.tuscany</groupId>
-            <artifactId>core</artifactId>
+            <artifactId>spi</artifactId>
             <version>${sca.version}</version>
             <scope>compile</scope>
         </dependency>

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteMethodException.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,37 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoRemoteMethodException extends RMIRuntimeException {
+    public NoRemoteMethodException() {
+    }
+
+    public NoRemoteMethodException(String message) {
+        super(message);
+    }
+
+    public NoRemoteMethodException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoRemoteMethodException(Throwable cause) {
+        super(cause);
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/NoRemoteServiceException.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,37 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoRemoteServiceException extends RMIRuntimeException {
+    public NoRemoteServiceException() {
+    }
+
+    public NoRemoteServiceException(String message) {
+        super(message);
+    }
+
+    public NoRemoteServiceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoRemoteServiceException(Throwable cause) {
+        super(cause);
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBinding.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,36 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import org.apache.tuscany.spi.model.Binding;
+
+/**
+ * Represents a binding to an RMI service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RMIBinding extends Binding {
+    private String uri;
+
+    public String getURI() {
+        return uri;
+    }
+
+    public void setURI(String uri) {
+        this.uri = uri;
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingBuilder.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import java.rmi.Remote;
+
+import org.apache.tuscany.spi.builder.InvalidServiceInterfaceException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.BindingBuilderExtension;
+import org.apache.tuscany.spi.model.BoundReferenceDefinition;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+
+/**
+ * Builds a Service or Reference for an RMI binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RMIBindingBuilder extends BindingBuilderExtension<RMIBinding> {
+    protected Class<RMIBinding> getBindingType() {
+        return RMIBinding.class;
+    }
+
+    public SCAObject build(CompositeComponent parent,
+                           BoundServiceDefinition<RMIBinding> 
boundServiceDefinition,
+                           DeploymentContext deploymentContext) {
+        String name = boundServiceDefinition.getName();
+        Class<? extends Remote> service = 
getServiceInterface(boundServiceDefinition);
+        String uri = boundServiceDefinition.getBinding().getURI();
+        return new RMIService(name, parent, wireService, uri, service);
+    }
+
+    @SuppressWarnings({"unchecked"})
+    protected Class<? extends Remote> 
getServiceInterface(BoundServiceDefinition<RMIBinding> boundServiceDefinition) {
+        Class<?> intf = 
boundServiceDefinition.getServiceContract().getInterfaceClass();
+        if (!Remote.class.isAssignableFrom(intf)) {
+            throw new InvalidServiceInterfaceException("RMI requires interface 
extend Remote", intf);
+        }
+        return (Class<? extends Remote>) intf;
+    }
+
+    public RMIReference build(CompositeComponent parent,
+                              BoundReferenceDefinition<RMIBinding> 
boundReferenceDefinition,
+                              DeploymentContext deploymentContext) {
+        String name = boundReferenceDefinition.getName();
+        String uri = boundReferenceDefinition.getBinding().getURI();
+        return new RMIReference(name, parent, wireService, uri);
+    }
+}

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

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

Copied: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java
 (from r424595, 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/loader/RMIBindingLoader.java)
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java?p2=incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java&p1=incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/loader/RMIBindingLoader.java&r1=424595&r2=424773&rev=424773&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/loader/RMIBindingLoader.java
 (original)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java
 Sun Jul 23 11:14:09 2006
@@ -14,59 +14,49 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.tuscany.binding.rmi.loader;
+package org.apache.tuscany.binding.rmi;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.tuscany.binding.rmi.assembly.RMIAssemblyFactory;
-import org.apache.tuscany.binding.rmi.assembly.RMIBinding;
-import org.apache.tuscany.binding.rmi.assembly.impl.RMIAssemblyFactoryImpl;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.loader.LoaderContext;
-import org.apache.tuscany.core.loader.StAXElementLoader;
-import org.apache.tuscany.core.loader.StAXLoaderRegistry;
-import org.apache.tuscany.core.system.annotation.Autowire;
-import org.osoa.sca.annotations.Destroy;
-import org.osoa.sca.annotations.Init;
 import org.osoa.sca.annotations.Scope;
 
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+
 /**
+ * Loader for handling <binding.rmi> elements.
+ *
  * @version $Rev$ $Date$
  */
 @Scope("MODULE")
-public class RMIBindingLoader implements StAXElementLoader<RMIBinding> {
-    public static final QName BINDING_RMI = new 
QName("http://www.osoa.org/xmlns/sca/0.9";, "binding.rmi");
-
-    private static final RMIAssemblyFactory RMI_FACTORY = new 
RMIAssemblyFactoryImpl();
-
-    protected StAXLoaderRegistry registry;
-
-    @Autowire
-    public void setRegistry(StAXLoaderRegistry registry) {
-        this.registry = registry;
-    }
+public class RMIBindingLoader extends LoaderExtension<RMIBinding> {
+    public static final QName BINDING_RMI = new 
QName("http://tuscany.apache.org/xmlns/binding/rmi/1.0-SNAPSHOT";,
+                                                      "binding.rmi");
 
-    @Init(eager = true)
-    public void start() {
-        registry.registerLoader(BINDING_RMI, this);
+    public RMIBindingLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
     }
 
-    @Destroy
-    public void stop() {
-        registry.unregisterLoader(BINDING_RMI, this);
+    public QName getXMLType() {
+        return BINDING_RMI;
     }
 
-    @SuppressWarnings("deprecation")
-    public RMIBinding load(XMLStreamReader reader, LoaderContext 
loaderContext) throws XMLStreamException, ConfigurationLoadException {
+    public RMIBinding load(CompositeComponent parent,
+                           XMLStreamReader reader,
+                           DeploymentContext deploymentContext)
+        throws XMLStreamException, LoaderException {
+        String uri = reader.getAttributeValue(null, "uri");
+        LoaderUtil.skipToEndElement(reader);
 
-        RMIBinding binding = RMI_FACTORY.createRMIBinding();
-        binding.setRMIHostName(reader.getAttributeValue(null, "host"));
-        binding.setRMIServerName(reader.getAttributeValue(null, "server"));
-        binding.setRMIPort(reader.getAttributeValue(null, "port"));
-        binding.setTypeHelper(registry.getContext().getTypeHelper());
-        binding.setResourceLoader(loaderContext.getResourceLoader());
+        RMIBinding binding = new RMIBinding();
+        binding.setURI(uri);
         return binding;
     }
 }

Propchange: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIBindingLoader.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIInvoker.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,79 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.Remote;
+
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Invoke an RMI reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RMIInvoker implements TargetInvoker {
+    private final Method remoteMethod;
+    private final Remote proxy;
+
+    RMIInvoker(Remote proxy, Method remoteMethod) {
+        assert remoteMethod.isAccessible();
+        this.remoteMethod = remoteMethod;
+        this.proxy = proxy;
+    }
+
+    public Message invoke(Message msg) throws InvocationRuntimeException {
+        try {
+            Object resp = invokeTarget(msg.getBody());
+            msg.setBody(resp);
+        } catch (InvocationTargetException e) {
+            msg.setBody(e.getCause());
+        }
+        return msg;
+    }
+
+    public Object invokeTarget(Object payload) throws 
InvocationTargetException {
+        try {
+            return remoteMethod.invoke(proxy, (Object[]) payload);
+        } catch (IllegalAccessException e) {
+            // the method we are passed must be accessible
+            throw new AssertionError(e);
+        }
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    public boolean isOptimizable() {
+        return false;
+    }
+
+    public boolean isCacheable() {
+        return false;
+    }
+
+    public void setCacheable(boolean cacheable) {
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIReference.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ReferenceExtension;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RMIReference extends ReferenceExtension<RMIBinding> {
+    private final String uri;
+
+    public RMIReference(String name, CompositeComponent<?> parent, WireService 
wireService, String uri) {
+        super(name, parent, wireService);
+        this.uri = uri;
+    }
+
+    public TargetInvoker createTargetInvoker(String serviceName, Method 
operation) {
+        try {
+            Remote proxy = getProxy();
+            Method remoteMethod = 
proxy.getClass().getMethod(operation.getName(), operation.getParameterTypes());
+            return new RMIInvoker(proxy, remoteMethod);
+        } catch (NoSuchMethodException e) {
+            throw new NoRemoteMethodException(operation.toString(), e);
+        }
+    }
+
+    protected Remote getProxy() {
+        try {
+            // todo do we need to cache this result?
+            return Naming.lookup(uri);
+        } catch (NotBoundException e) {
+            throw new NoRemoteServiceException(uri);
+        } catch (MalformedURLException e) {
+            throw new NoRemoteServiceException(uri);
+        } catch (RemoteException e) {
+            throw new NoRemoteServiceException(uri);
+        }
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIRuntimeException.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,39 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import org.apache.tuscany.spi.TuscanyRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class RMIRuntimeException extends TuscanyRuntimeException {
+    protected RMIRuntimeException() {
+    }
+
+    protected RMIRuntimeException(String message) {
+        super(message);
+    }
+
+    protected RMIRuntimeException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    protected RMIRuntimeException(Throwable cause) {
+        super(cause);
+    }
+}

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

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

Added: 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java
 (added)
+++ 
incubator/tuscany/java/sca/bindings/binding.rmi/src/main/java/org/apache/tuscany/binding/rmi/RMIService.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,91 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.binding.rmi;
+
+import java.net.MalformedURLException;
+import java.rmi.AlreadyBoundException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ServiceExtension;
+import org.apache.tuscany.spi.wire.WireService;
+import org.apache.tuscany.spi.wire.WireInvocationHandler;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RMIService extends ServiceExtension {
+    private final String uri;
+    private final Class<? extends Remote> service;
+
+    public RMIService(String name, CompositeComponent parent, WireService 
wireService, String uri, Class<? extends Remote> service) {
+        super(name, parent, wireService);
+        this.uri = uri;
+        this.service = service;
+    }
+
+    public void start() {
+        super.start();
+        Remote rmiProxy = createProxy();
+
+        try {
+            Naming.bind(uri, rmiProxy);
+        } catch (AlreadyBoundException e) {
+            throw new NoRemoteServiceException(e);
+        } catch (RemoteException e) {
+            throw new NoRemoteServiceException(e);
+        } catch (MalformedURLException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    public void stop() {
+        try {
+            Naming.unbind(uri);
+        } catch (NotBoundException e) {
+            // ignore
+        } catch (RemoteException e) {
+            throw new NoRemoteServiceException(e);
+        } catch (MalformedURLException e) {
+            throw new AssertionError(e);
+        }
+        super.stop();
+    }
+
+    protected Remote createProxy() {
+        InvocationHandler handler = new RMIInvocationHandler(getHandler());
+        return service.cast(Proxy.newProxyInstance(service.getClassLoader(), 
new Class[]{service}, handler));
+    }
+
+    private static class RMIInvocationHandler implements InvocationHandler {
+        private final WireInvocationHandler wireHandler;
+
+        public RMIInvocationHandler(WireInvocationHandler wireHandler) {
+            this.wireHandler = wireHandler;
+        }
+
+        public Object invoke(Object object, Method method, Object[] objects) 
throws Throwable {
+            return wireHandler.invoke(method, objects);
+        }
+    }
+}

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

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

Modified: incubator/tuscany/java/sca/bindings/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/pom.xml?rev=424773&r1=424772&r2=424773&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/pom.xml (original)
+++ incubator/tuscany/java/sca/bindings/pom.xml Sun Jul 23 11:14:09 2006
@@ -34,6 +34,7 @@
          
         <module>sunjars</module>
         <module>binding.celtix</module>
+        <module>binding.rmi</module>
     </modules>
 
 </project>

Added: 
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java?rev=424773&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
 (added)
+++ 
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
 Sun Jul 23 11:14:09 2006
@@ -0,0 +1,33 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed 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.spi.builder;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidServiceInterfaceException extends BuilderConfigException {
+    private final Class<?> interfaceClass;
+
+    public InvalidServiceInterfaceException(String message, Class<?> 
interfaceClass) {
+        super(message);
+        this.interfaceClass = interfaceClass;
+    }
+
+    public Class<?> getInterfaceClass() {
+        return interfaceClass;
+    }
+}

Propchange: 
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to