You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2008/03/21 04:42:46 UTC

svn commit: r639535 [4/7] - in /incubator/tuscany/sandbox/mobile-android: core-android/ core-android/src/ core-android/src/main/ core-android/src/main/java/ core-android/src/main/java/org/ core-android/src/main/java/org/apache/ core-android/src/main/ja...

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.core.factory;
+
+
+/**
+ * Denotes an error creating a new object instance
+ *
+ * @version $Rev: 567617 $ $Date: 2007-08-20 02:29:15 -0700 (Mon, 20 Aug 2007) $
+ */
+public class ObjectCreationException extends RuntimeException {
+    private static final long serialVersionUID = -6423113430265944499L;
+
+    public ObjectCreationException() {
+        super();
+    }
+
+    public ObjectCreationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ObjectCreationException(String message) {
+        super(message);
+    }
+
+    public ObjectCreationException(Throwable cause) {
+        super(cause);
+    }
+
+}
+

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.core.factory;
+
+/**
+ * Implementations create new instances of a particular type
+ *
+ * @version $Rev: 567617 $ $Date: 2007-08-20 02:29:15 -0700 (Mon, 20 Aug 2007) $
+ */
+public interface ObjectFactory<T> {
+
+    /**
+     * Return a instance of the type that this factory creates.
+     *
+     * @return a instance from this factory
+     */
+    T getInstance() throws ObjectCreationException;
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.core.invocation;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Uses a wire to return a CallableReference
+ * 
+ * @version $Rev: 639271 $ $Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $
+ */
+public class CallableReferenceObjectFactory implements ObjectFactory<CallableReference<?>> {
+    private Class<?> businessInterface;
+    private RuntimeComponent component;
+    private RuntimeComponentReference reference;
+    private Binding binding;
+
+    /**
+     * Constructor.
+     * 
+     * To support the @Reference protected CallableReference<MyService> ref;
+     * 
+     * @param businessInterface the interface to inject
+     * @param component the component defining the reference to be injected
+     * @param reference the reference to be injected
+     * @param binding the binding for the reference
+     */
+    public CallableReferenceObjectFactory(Class<?> businessInterface,
+                                          RuntimeComponent component,
+                                          RuntimeComponentReference reference,
+                                          Binding binding) {
+        this.businessInterface = businessInterface;
+        this.component = component;
+        this.reference = reference;
+        this.binding = binding;
+    }
+
+    public CallableReference<?> getInstance() throws ObjectCreationException {
+        return component.getComponentContext().getServiceReference(businessInterface, reference, binding);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.core.invocation;
+
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.osoa.sca.NoRegisteredCallbackException;
+
+/**
+ * An interceptor applied to the forward direction of a wire that ensures the callback target implements the required
+ * service contract. This is required as callback targets may be set dynamically by service implementations.
+ *
+ * @version $Rev: 608822 $ $Date: 2008-01-04 04:59:56 -0800 (Fri, 04 Jan 2008) $
+ */
+public class CallbackInterfaceInterceptor implements Interceptor {
+    private Invoker next;
+
+    public CallbackInterfaceInterceptor() {
+    }
+
+    public Message invoke(Message msg) {
+        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+        if (parameters.getCallbackObjectID() != null || parameters.getCallbackReference() != msg.getFrom()
+            .getCallbackEndpoint()) {
+            return next.invoke(msg);
+        } else {
+            throw new NoRegisteredCallbackException("Callback target does not implement the callback interface");
+        }
+    }
+
+    public void setNext(Invoker next) {
+        this.next = next;
+    }
+
+    public Invoker getNext() {
+        return next;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,187 @@
+/*
+ * 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.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+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.runtime.RuntimeWire;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev: 576055 $ $Date: 2007-09-16 08:11:45 +0100 (Sun, 16 Sep 2007) $
+ */
+public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> {
+    private RuntimeWire wire;
+    private List<RuntimeWire> wires;
+    private EndpointReference resolvedEndpoint;
+	private Object convID;
+
+    public CallbackReferenceImpl(Class<B> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+        super(interfaze, null, proxyFactory);
+        this.wires = wires;
+		init();
+    }
+
+    public void init() {
+        Message msgContext = ThreadMessageContext.getMessageContext();
+        wire = selectCallbackWire(msgContext);
+        if (wire == null) {
+            //FIXME: need better exception
+            throw new RuntimeException("No callback binding found for " + msgContext.getTo().getURI());
+        }
+        resolvedEndpoint = getCallbackEndpoint(msgContext);
+        convID = msgContext.getFrom().getReferenceParameters().getConversationID();
+        callbackID = msgContext.getFrom().getReferenceParameters().getCallbackID();
+    }
+
+    @Override
+    protected Object createProxy() throws Exception {
+        return proxyFactory.createCallbackProxy(this);
+	}
+
+    protected RuntimeWire getCallbackWire() {
+        if (resolvedEndpoint == null) {
+            return null;
+        } else {
+            return cloneAndBind(wire);
+		}
+    }
+
+    protected Object getConvID() {
+	    return convID;
+	}
+
+    protected EndpointReference getResolvedEndpoint() {
+	    return resolvedEndpoint;
+	}
+
+    private RuntimeWire selectCallbackWire(Message msgContext) {
+        // look for callback binding with same name as service binding
+        EndpointReference to = msgContext.getTo();
+        if (to == null) {
+            //FIXME: need better exception
+            throw new RuntimeException("Destination for forward call is not available");
+        }
+        for (RuntimeWire wire : wires) {
+            if (wire.getSource().getBinding().getName().equals(to.getBinding().getName())) {
+			    return wire;
+            }
+        }
+
+        // if no match, look for callback binding with same type as service binding
+        for (RuntimeWire wire : wires) {
+            if (wire.getSource().getBinding().getClass() == to.getBinding().getClass()) {
+			    return wire;
+            }
+        }
+
+        // no suitable callback wire was found
+        return null;
+    }
+
+    /**
+     * @param msgContext
+     */
+    private static EndpointReference getCallbackEndpoint(Message msgContext) {
+        EndpointReference from = msgContext.getFrom();
+        if (from == null) {
+            return null;
+        }
+        return from.getReferenceParameters().getCallbackReference();
+    }
+
+    private RuntimeWire cloneAndBind(RuntimeWire wire) {
+        RuntimeWire boundWire = null;
+        if (resolvedEndpoint != null) {
+            boundWire = ((RuntimeWireImpl)wire).lookupCache(resolvedEndpoint);
+            if (boundWire != null) {
+                return boundWire;
+            }
+            try {
+                Contract contract = resolvedEndpoint.getContract();
+                RuntimeComponentReference ref = null;
+                if (contract == null) {
+                    boundWire = (RuntimeWire)wire.clone();
+
+                } else if (contract instanceof RuntimeComponentReference) {
+                    ref = (RuntimeComponentReference)contract;
+                    boundWire = ref.getRuntimeWire(resolvedEndpoint.getBinding());
+
+                } else {  // contract instanceof RuntimeComponentService
+                    ref = bind((RuntimeComponentReference)wire.getSource().getContract(),
+                               resolvedEndpoint.getComponent(),
+                               (RuntimeComponentService)contract);
+                    boundWire = ref.getRuntimeWires().get(0);
+                }
+                configureWire(boundWire);
+                ((RuntimeWireImpl)wire).addToCache(resolvedEndpoint, boundWire);
+            } catch (CloneNotSupportedException e) {
+                // will not happen
+            }
+        }
+        return boundWire;
+    }
+
+    private static RuntimeComponentReference bind(RuntimeComponentReference reference,
+                                                  RuntimeComponent component,
+                                                  RuntimeComponentService service) throws CloneNotSupportedException {
+        RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
+        ref.getTargets().add(service);
+        ref.getBindings().clear();
+        for (Binding binding : service.getBindings()) {
+            if (binding instanceof OptimizableBinding) {
+                OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+                optimizableBinding.setTargetBinding(binding);
+                optimizableBinding.setTargetComponent(component);
+                optimizableBinding.setTargetComponentService(service);
+                ref.getBindings().add(optimizableBinding);
+            } else {
+                ref.getBindings().add(binding);
+            }
+        }
+        return ref;
+    }
+
+    private void configureWire(RuntimeWire wire) {
+        // need to set the endpoint on the binding also so that when the chains are created next
+        // the sca binding can decide whether to provide local or remote invokers. 
+        // TODO - there is a problem here though in that I'm setting a target on a 
+        //        binding that may possibly be trying to point at two things in the multi threaded 
+        //        case. Need to confirm the general model here and how the clone and bind part
+        //        is intended to work
+        Binding binding = wire.getSource().getBinding();
+        binding.setURI(resolvedEndpoint.getURI());
+
+        // also need to set the target contract as it varies for the sca binding depending on 
+        // whether it is local or remote
+        RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract();
+        wire.getTarget().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Uses a wire to return a CallableReference
+ * 
+ * @version $Rev: 574648 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $
+ */
+public class CallbackReferenceObjectFactory implements ObjectFactory<CallableReference<?>> {
+    private Class<?> businessInterface;
+    private ProxyFactory proxyFactory;
+    private List<RuntimeWire> wires;
+
+    public CallbackReferenceObjectFactory(Class<?> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+        this.businessInterface = interfaze;
+        this.proxyFactory = proxyFactory;
+        this.wires = wires;
+    }
+
+    public CallableReference<?> getInstance() throws ObjectCreationException {
+        return new CallbackReferenceImpl(businessInterface, proxyFactory, wires);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev: 596162 $ $Date: 2007-11-18 15:50:50 -0800 (Sun, 18 Nov 2007) $
+ */
+public class CallbackWireObjectFactory<B> implements ObjectFactory<B> {
+    private Class<B> businessInterface;
+    private ProxyFactory proxyFactory;
+    private List<RuntimeWire> wires;
+
+    public CallbackWireObjectFactory(Class<B> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+        this.businessInterface = interfaze;
+        this.proxyFactory = proxyFactory;
+        this.wires = wires;
+    }
+
+    public B getInstance() throws ObjectCreationException {
+        return proxyFactory.createCallbackProxy(businessInterface, wires);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.core.invocation;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.Factory;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * The implementation of a wire service that uses cglib dynamic proxies
+ * 
+ * @version $Rev: 628809 $ $Date: 2008-02-18 08:50:37 -0800 (Mon, 18 Feb 2008) $
+ */
+@SuppressWarnings("unused")
+public class CglibProxyFactory implements ProxyFactory {
+    private MessageFactory messageFactory;
+
+    public CglibProxyFactory() {
+        this(new MessageFactoryImpl(), new InterfaceContractMapperImpl());
+    }
+
+    public CglibProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+        this.messageFactory = messageFactory;
+
+    }
+
+    public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+        ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, wire, this);
+        return createProxy(serviceReference);
+    }
+
+    /**
+     * create the proxy with cglib. use the same JDKInvocationHandler as
+     * JDKProxyService.
+     */
+    public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+        Enhancer enhancer = new Enhancer();
+        Class<T> interfaze = callableReference.getBusinessInterface();
+        enhancer.setSuperclass(interfaze);
+        enhancer.setCallback(new CglibMethodInterceptor<T>(callableReference));
+        Object proxy = enhancer.create();
+		((CallableReferenceImpl)callableReference).setProxy(proxy);
+        return interfaze.cast(proxy);
+    }
+
+    /**
+     * create the callback proxy with cglib. use the same
+     * JDKCallbackInvocationHandler as JDKProxyService.
+     */
+    public <T> T createCallbackProxy(Class<T> interfaze, final List<RuntimeWire> wires) throws ProxyCreationException {
+        CallbackReferenceImpl<T> callbackReference = new CallbackReferenceImpl(interfaze, this, wires);
+        return createCallbackProxy(callbackReference);
+    }
+
+    /**
+     * create the callback proxy with cglib. use the same
+     * JDKCallbackInvocationHandler as JDKProxyService.
+     */
+    public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+        Enhancer enhancer = new Enhancer();
+        Class<T> interfaze = callbackReference.getBusinessInterface();
+        enhancer.setSuperclass(interfaze);
+        enhancer.setCallback(new CglibMethodInterceptor<T>(callbackReference));
+        Object proxy = enhancer.create();
+		callbackReference.setProxy(proxy);
+        return interfaze.cast(proxy);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+        if (isProxyClass(target.getClass())) {
+            Factory factory = (Factory)target;
+            Callback[] callbacks = factory.getCallbacks();
+            if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
+                throw new IllegalArgumentException("The object is not a known proxy.");
+            }
+            CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
+            return (R)interceptor.invocationHandler.getCallableReference();
+        } else {
+            throw new IllegalArgumentException("The object is not a known proxy.");
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+     */
+    public boolean isProxyClass(Class<?> clazz) {
+        return Factory.class.isAssignableFrom(clazz);
+    }
+
+    private class CglibMethodInterceptor<T> implements MethodInterceptor {
+        private JDKInvocationHandler invocationHandler;
+
+        public CglibMethodInterceptor(CallableReference<T> callableReference) {
+            invocationHandler = new JDKInvocationHandler(messageFactory, callableReference);
+        }
+
+        public CglibMethodInterceptor(CallbackReferenceImpl<T> callbackReference) {
+            invocationHandler = new JDKCallbackInvocationHandler(messageFactory, callbackReference);
+        }
+
+        /*
+        public CglibMethodInterceptor(Class<T> interfaze, RuntimeWire wire) {
+            ServiceReference<T> serviceRef = new ServiceReferenceImpl<T>(interfaze, wire, CglibProxyFactory.this);
+            invocationHandler = new JDKInvocationHandler(messageFactory, serviceRef);
+        }
+
+        public CglibMethodInterceptor(Class<T> interfaze, List<RuntimeWire> wires) {
+            CallbackReferenceImpl ref = new CallbackReferenceImpl(interfaze, CglibProxyFactory.this, wires);
+            invocationHandler = new JDKCallbackInvocationHandler(messageFactory, ref);
+        }
+		*/
+
+        /**
+         * @see net.sf.cglib.proxy.MethodInterceptor#intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], net.sf.cglib.proxy.MethodProxy)
+         */
+        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+            Object result = invocationHandler.invoke(proxy, method, args);
+            return result;
+        }
+
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,152 @@
+/*
+ * 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.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+public class DefaultProxyFactoryExtensionPoint implements ProxyFactoryExtensionPoint {
+    private InterfaceContractMapper interfaceContractMapper;
+    private MessageFactory messageFactory;
+
+    private ProxyFactory interfaceFactory;
+    private ProxyFactory classFactory;
+
+    public DefaultProxyFactoryExtensionPoint() {
+        this(new MessageFactoryImpl(), new InterfaceContractMapperImpl());
+    }
+
+    public DefaultProxyFactoryExtensionPoint(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+        this.interfaceContractMapper = mapper;
+        this.messageFactory = messageFactory;
+        interfaceFactory = new JDKProxyFactory(messageFactory, mapper);
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#getClassProxyFactory()
+     */
+    public ProxyFactory getClassProxyFactory() {
+        return classFactory;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#getInterfaceProxyFactory()
+     */
+    public ProxyFactory getInterfaceProxyFactory() {
+        return interfaceFactory;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#setClassProxyFactory(org.apache.tuscany.sca.core.invocation.ProxyFactory)
+     */
+    public void setClassProxyFactory(ProxyFactory factory) {
+        this.classFactory = factory;
+
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#setInterfaceProxyFactory(org.apache.tuscany.sca.core.invocation.ProxyFactory)
+     */
+    public void setInterfaceProxyFactory(ProxyFactory factory) {
+        this.interfaceFactory = factory;
+
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#cast(java.lang.Object)
+     */
+    @SuppressWarnings("unchecked")
+    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+        if (interfaceFactory.isProxyClass(target.getClass())) {
+            return (R)interfaceFactory.cast(target);
+        } else if (classFactory != null && classFactory.isProxyClass(target.getClass())) {
+            return (R)classFactory.cast(target);
+        } else {
+            throw new IllegalArgumentException("The target is not a callable proxy");
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createCallbackProxy(java.lang.Class,
+     *      java.util.List)
+     */
+    public <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException {
+        if (interfaze.isInterface()) {
+            return interfaceFactory.createCallbackProxy(interfaze, wires);
+        } else {
+            return classFactory.createCallbackProxy(interfaze, wires);
+        }
+    }
+
+    public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+        if (callableReference.getBusinessInterface().isInterface()) {
+            return interfaceFactory.createProxy(callableReference);
+        } else {
+            return classFactory.createProxy(callableReference);
+        }
+    }
+
+    public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+        if (callbackReference.getBusinessInterface().isInterface()) {
+            return interfaceFactory.createCallbackProxy(callbackReference);
+        } else {
+            return classFactory.createCallbackProxy(callbackReference);
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createProxy(java.lang.Class,
+     *      org.apache.tuscany.sca.runtime.RuntimeWire)
+     */
+    public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+        if (interfaze.isInterface()) {
+            return interfaceFactory.createProxy(interfaze, wire);
+        } else {
+            return classFactory.createProxy(interfaze, wire);
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+     */
+    public boolean isProxyClass(Class<?> clazz) {
+        return interfaceFactory.isProxyClass(clazz) || (classFactory != null && classFactory.isProxyClass(clazz));
+    }
+
+    /**
+     * @return the interfaceContractMapper
+     */
+    public InterfaceContractMapper getInterfaceContractMapper() {
+        return interfaceContractMapper;
+    }
+
+    /**
+     * @return the messageFactory
+     */
+    public MessageFactory getMessageFactory() {
+        return messageFactory;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.core.invocation;
+
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+
+/**
+ * The default implementation of an extensible <code>WireProcessor</code>
+ *
+ * @version $Rev: 538423 $ $Date: 2007-05-15 21:11:06 -0700 (Tue, 15 May 2007) $
+ */
+public class ExtensibleWireProcessor implements RuntimeWireProcessor {
+    
+    private RuntimeWireProcessorExtensionPoint processors;
+
+    public ExtensibleWireProcessor(RuntimeWireProcessorExtensionPoint processors) {
+        this.processors = processors;
+    }
+    
+    public void process(RuntimeWire wire) {
+        for (RuntimeWireProcessor processor : processors.getWireProcessors()) {
+            processor.process(wire);
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,189 @@
+/*
+ * 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.core.invocation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Phase;
+
+/**
+ * Default implementation of an invocation chain
+ * 
+ * @version $Rev: 634778 $ $Date: 2008-03-07 10:58:16 -0800 (Fri, 07 Mar 2008) $
+ */
+public class InvocationChainImpl implements InvocationChain {
+    private Operation sourceOperation;
+    private Operation targetOperation;
+    private List<Node> nodes = new ArrayList<Node>();
+
+    // FIXME: Not a good practice to use static reference
+    private final static PhaseManager phaseManager = new PhaseManager();
+    private boolean forReference;
+    private boolean allowsPassByReference;
+
+    public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) {
+        assert sourceOperation != null;
+        assert targetOperation != null;
+        this.targetOperation = targetOperation;
+        this.sourceOperation = sourceOperation;
+        this.forReference = forReference;
+    }
+
+    public Operation getTargetOperation() {
+        return targetOperation;
+    }
+
+    public void setTargetOperation(Operation operation) {
+        this.targetOperation = operation;
+    }
+
+    public void addInterceptor(Interceptor interceptor) {
+        String phase = forReference ? Phase.REFERENCE : Phase.SERVICE;
+        addInterceptor(phase, interceptor);
+    }
+
+    public void addInvoker(Invoker invoker) {
+        String phase = forReference ? Phase.REFERENCE_BINDING : Phase.IMPLEMENTATION;
+        addInvoker(phase, invoker);
+    }
+
+    public Invoker getHeadInvoker() {
+        return nodes.isEmpty() ? null : nodes.get(0).getInvoker();
+    }
+
+    public Invoker getTailInvoker() {
+        return nodes.isEmpty() ? null : nodes.get(nodes.size() - 1).getInvoker();
+    }
+
+    /**
+     * @return the sourceOperation
+     */
+    public Operation getSourceOperation() {
+        return sourceOperation;
+    }
+
+    /**
+     * @param sourceOperation the sourceOperation to set
+     */
+    public void setSourceOperation(Operation sourceOperation) {
+        this.sourceOperation = sourceOperation;
+    }
+
+    public void addInterceptor(int index, Interceptor interceptor) {
+        addInterceptor(interceptor);
+    }
+
+    public void addInterceptor(String phase, Interceptor interceptor) {
+        addInvoker(phase, interceptor);
+    }
+
+    private void addInvoker(String phase, Invoker invoker) {
+        int index = phaseManager.getAllPhases().indexOf(phase);
+        if (index == -1) {
+            throw new IllegalArgumentException("Invalid phase name: " + phase);
+        }
+        Node node = new Node(index, invoker);
+        ListIterator<Node> li = nodes.listIterator();
+        Node before = null, after = null;
+        boolean found = false;
+        while (li.hasNext()) {
+            before = after;
+            after = li.next();
+            if (after.getPhaseIndex() > index) {
+                // Move back
+                li.previous();
+                li.add(node);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            // Add to the end
+            nodes.add(node);
+            before = after;
+            after = null;
+        }
+
+        // Relink the interceptors
+        if (before != null) {
+            if (before.getInvoker() instanceof Interceptor) {
+                ((Interceptor)before.getInvoker()).setNext(invoker);
+            }
+        }
+        if (after != null) {
+            if (invoker instanceof Interceptor) {
+                ((Interceptor)invoker).setNext(after.getInvoker());
+            }
+        }
+
+    }
+
+    public boolean allowsPassByReference() {
+        if (allowsPassByReference) {
+            // No need to check the invokers
+            return true;
+        }
+        // Check if any of the invokers allows pass-by-reference
+        boolean allowsPBR = false;
+        for (Node i : nodes) {
+            if (i.getInvoker() instanceof DataExchangeSemantics) {
+                if (((DataExchangeSemantics)i.getInvoker()).allowsPassByReference()) {
+                    allowsPBR = true;
+                    break;
+                }
+            }
+        }
+        return allowsPBR;
+    }
+
+    public void setAllowsPassByReference(boolean allowsPBR) {
+        this.allowsPassByReference = allowsPBR;
+    }
+
+    private static class Node {
+        private int phaseIndex;
+        private Invoker invoker;
+
+        public Node(int phaseIndex, Invoker invoker) {
+            super();
+            this.phaseIndex = phaseIndex;
+            this.invoker = invoker;
+        }
+
+        public int getPhaseIndex() {
+            return phaseIndex;
+        }
+
+        public Invoker getInvoker() {
+            return invoker;
+        }
+
+        public String toString() {
+            return "(" + phaseIndex + ")" + invoker;
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.core.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Responsible for dispatching to a callback through a wire. <p/> TODO cache
+ * target invoker
+ * 
+ * @version $Rev: 638875 $ $Date: 2008-03-19 08:32:44 -0700 (Wed, 19 Mar 2008) $
+ */
+public class JDKCallbackInvocationHandler extends JDKInvocationHandler {
+    private static final long serialVersionUID = -3350283555825935609L;
+
+    public JDKCallbackInvocationHandler(MessageFactory messageFactory, CallbackReferenceImpl ref) {
+        super(messageFactory, ref);
+        this.fixedWire = false;
+    }
+
+    @Override
+    @SuppressWarnings( {"unchecked"})
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if (Object.class == method.getDeclaringClass()) {
+            return invokeObjectMethod(method, args);
+        }
+
+        // obtain a dedicated wire to be used for this callback invocation
+        RuntimeWire wire = ((CallbackReferenceImpl)callableReference).getCallbackWire();
+        if (wire == null) {
+            //FIXME: need better exception
+            throw new ServiceRuntimeException("No callback wire found");
+        }
+
+        // set the conversational state based on the interface that
+        // is specified for the reference that this wire belongs to
+        initConversational(wire);
+
+        // set the conversation id into the conversation object. This is
+        // a special case for callbacks as, unless otherwise set manually,
+        // the callback should use the same conversation id as was received
+        // on the incoming call to this component
+        if (conversational) {
+
+            if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+                conversation = null;
+            }
+            Object convID = conversation == null ? null : conversation.getConversationID();
+
+            // create a conversation id if one doesn't exist 
+            // already, i.e. the conversation is just starting
+            if (convID == null) {
+                convID = ((CallbackReferenceImpl)callableReference).getConvID();
+                if (convID != null) {
+                    conversation = ((RuntimeWireImpl)wire).getConversationManager().getConversation(convID);
+                    if (callableReference != null) {
+                        ((CallableReferenceImpl)callableReference).attachConversation(conversation);
+                    }
+                }
+            }
+        }
+
+        setEndpoint(((CallbackReferenceImpl)callableReference).getResolvedEndpoint());
+
+        InvocationChain chain = getInvocationChain(method, wire);
+        if (chain == null) {
+            throw new IllegalArgumentException("No matching operation is found: " + method);
+        }
+
+        try {
+            return invoke(chain, args, wire, wire.getSource());
+        } catch (InvocationTargetException e) {
+            Throwable t = e.getCause();
+            if (t instanceof NoRegisteredCallbackException) {
+                throw t;
+            }
+            throw e;
+        } finally {
+            // allow the cloned wire to be reused by subsequent callbacks
+            ((RuntimeWireImpl)wire).releaseWire();
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,489 @@
+/*
+ * 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.core.invocation;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetResolutionException;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ConversationEndedException;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev: 639271 $ $Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $
+ */
+public class JDKInvocationHandler implements InvocationHandler, Serializable {
+    private static final long serialVersionUID = -3366410500152201371L;
+
+    protected boolean conversational;
+    protected ExtendedConversation conversation;
+    protected MessageFactory messageFactory;
+    protected EndpointReference source;
+    protected EndpointReference target;
+    protected RuntimeWire wire;
+    protected CallableReference<?> callableReference;
+    protected Class<?> businessInterface;
+
+    protected boolean fixedWire = true;
+
+    protected transient Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>();
+
+    public JDKInvocationHandler(MessageFactory messageFactory, Class<?> businessInterface, RuntimeWire wire) {
+        this.messageFactory = messageFactory;
+        this.wire = wire;
+        this.businessInterface = businessInterface;
+        init(this.wire);
+    }
+
+    public JDKInvocationHandler(MessageFactory messageFactory, CallableReference<?> callableReference) {
+        this.messageFactory = messageFactory;
+        this.callableReference = callableReference;
+        if (callableReference != null) {
+            this.businessInterface = callableReference.getBusinessInterface();
+            this.conversation = (ExtendedConversation)callableReference.getConversation();
+            this.wire = ((CallableReferenceImpl<?>)callableReference).getRuntimeWire();
+            if (wire != null) {
+                init(wire);
+            }
+        }
+    }
+
+    protected void init(RuntimeWire wire) {
+        if (wire != null) {
+            try {
+                // Clone the endpoint reference so that reference parameters can be changed
+                source = (EndpointReference)wire.getSource().clone();
+            } catch (CloneNotSupportedException e) {
+                throw new ServiceRuntimeException(e);
+            }
+            initConversational(wire);
+        }
+    }
+
+    protected void initConversational(RuntimeWire wire) {
+        InterfaceContract contract = wire.getSource().getInterfaceContract();
+        this.conversational = contract.getInterface().isConversational();
+    }
+
+    protected Object getCallbackID() {
+        if (callableReference != null) {
+            return callableReference.getCallbackID();
+        } else {
+            return null;
+        }
+    }
+
+    protected Object getConversationID() {
+        if (callableReference != null && callableReference instanceof ServiceReference) {
+            return ((ServiceReference)callableReference).getConversationID();
+        } else {
+            return null;
+        }
+    }
+
+    protected Object getCallbackObject() {
+        if (callableReference != null && callableReference instanceof ServiceReference) {
+            return ((ServiceReference)callableReference).getCallback();
+        } else {
+            return null;
+        }
+    }
+
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if (Object.class == method.getDeclaringClass()) {
+            return invokeObjectMethod(method, args);
+        }
+        if (wire == null) {
+            throw new ServiceRuntimeException("No runtime wire is available");
+        }
+        InvocationChain chain = getInvocationChain(method, wire);
+        if (chain == null) {
+            throw new IllegalArgumentException("No matching operation is found: " + method);
+        }
+
+        // send the invocation down the wire
+        Object result = invoke(chain, args, wire, source);
+
+        return result;
+    }
+
+    /**
+     * Handle the methods on the Object.class
+     * @param method
+     * @param args
+     */
+    protected Object invokeObjectMethod(Method method, Object[] args) throws Throwable {
+        String name = method.getName();
+        if ("toString".equals(name)) {
+            return "[Proxy - " + toString() + "]";
+        } else if ("equals".equals(name)) {
+            Object obj = args[0];
+            if (obj == null) {
+                return false;
+            }
+            if (!Proxy.isProxyClass(obj.getClass())) {
+                return false;
+            }
+            return equals(Proxy.getInvocationHandler(obj));
+        } else if ("hashCode".equals(name)) {
+            return hashCode();
+        } else {
+            return method.invoke(this);
+        }
+    }
+
+    /**
+     * Determines if the given operation matches the given method
+     * 
+     * @return true if the operation matches, false if does not
+     */
+    // FIXME: Should it be in the InterfaceContractMapper?
+    @SuppressWarnings("unchecked")
+    private static boolean match(Operation operation, Method method) {
+        if (operation instanceof JavaOperation) {
+            JavaOperation javaOp = (JavaOperation)operation;
+            Method m = javaOp.getJavaMethod();
+            if (!method.getName().equals(m.getName())) {
+                return false;
+            }
+            if (method.equals(m)) {
+                return true;
+            }
+        } else {
+            if (!method.getName().equals(operation.getName())) {
+                return false;
+            }
+        }
+
+        // For remotable interface, operation is not overloaded. 
+        if (operation.getInterface().isRemotable()) {
+            return true;
+        }
+
+        Class<?>[] params = method.getParameterTypes();
+
+        DataType<List<DataType>> inputType = null;
+        if (operation.isWrapperStyle()) {
+            inputType = operation.getWrapper().getUnwrappedInputType();
+        } else {
+            inputType = operation.getInputType();
+        }
+        List<DataType> types = inputType.getLogical();
+        boolean matched = true;
+        if (types.size() == params.length && method.getName().equals(operation.getName())) {
+            for (int i = 0; i < params.length; i++) {
+                Class<?> clazz = params[i];
+                Class<?> type = types.get(i).getPhysical();
+                // Object.class.isAssignableFrom(int.class) returns false
+                if (type != Object.class && (!type.isAssignableFrom(clazz))) {
+                    matched = false;
+                }
+            }
+        } else {
+            matched = false;
+        }
+        return matched;
+
+    }
+
+    protected synchronized InvocationChain getInvocationChain(Method method, RuntimeWire wire) {
+        if (fixedWire && chains.containsKey(method)) {
+            return chains.get(method);
+        }
+        InvocationChain found = null;
+        for (InvocationChain chain : wire.getInvocationChains()) {
+            Operation operation = chain.getSourceOperation();
+            if (operation.isDynamic()) {
+                operation.setName(method.getName());
+                found = chain;
+                break;
+            } else if (match(operation, method)) {
+                found = chain;
+                break;
+            }
+        }
+        if (fixedWire) {
+            chains.put(method, found);
+        }
+        return found;
+    }
+
+    protected void setEndpoint(EndpointReference endpoint) {
+        this.target = endpoint;
+    }
+
+    protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire, EndpointReference source)
+                         throws Throwable {
+        Message msg = messageFactory.createMessage();
+        msg.setFrom(source);
+        if (target != null) {
+            msg.setTo(target);
+        } else {
+            msg.setTo(wire.getTarget());
+        }
+        Invoker headInvoker = chain.getHeadInvoker();
+        Operation operation = chain.getTargetOperation();
+        msg.setOperation(operation);
+        msg.setBody(args);
+
+        Message msgContext = ThreadMessageContext.getMessageContext();
+        Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();
+
+        conversationPreinvoke(msg, wire);
+        handleCallback(msg, wire, currentConversationID);
+        ThreadMessageContext.setMessageContext(msg);
+        try {
+            // dispatch the wire down the chain and get the response
+            Message resp = headInvoker.invoke(msg);
+            Object body = resp.getBody();
+            if (resp.isFault()) {
+                throw (Throwable)body;
+            }
+            return body;
+        } finally {
+            conversationPostInvoke(msg, wire);
+            ThreadMessageContext.setMessageContext(msgContext);
+        }
+    }
+
+    /**
+     * @param msg
+     * @param wire
+     * @param interfaze
+     * @throws TargetResolutionException
+     */
+    private void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID)
+        throws TargetResolutionException {
+        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+        parameters.setCallbackID(getCallbackID());
+        if (msg.getFrom() == null || msg.getFrom().getCallbackEndpoint() == null) {
+            return;
+        }
+
+        parameters.setCallbackReference(msg.getFrom().getCallbackEndpoint());
+
+        // If we are passing out a callback target
+        // register the calling component instance against this 
+        // new conversation id so that stateful callbacks will be
+        // able to find it
+        Object callbackObject = getCallbackObject();
+        if (conversational && callbackObject == null) {
+            // the component instance is already registered
+            // so add another registration
+            ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
+
+            if (scopeContainer != null && currentConversationID != null) {
+                scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID());
+            }
+        }
+
+        Interface interfaze = msg.getOperation().getInterface();
+        if (callbackObject != null) {
+            if (callbackObject instanceof ServiceReference) {
+                EndpointReference callbackRef = ((CallableReferenceImpl)callbackObject).getEndpointReference();
+                parameters.setCallbackReference(callbackRef);
+            } else {
+                if (interfaze != null) {
+                    if (!interfaze.isConversational()) {
+                        throw new IllegalArgumentException(
+                                                           "Callback object for stateless callback is not a ServiceReference");
+                    } else {
+                        ScopeContainer scopeContainer = getConversationalScopeContainer(wire);
+                        if (scopeContainer != null) {
+                            InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject);
+                            scopeContainer.registerWrapper(wrapper, conversation.getConversationID());
+                        }
+                        parameters.setCallbackObjectID(callbackObject);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Pre-invoke for the conversation handling
+     * @param msg
+     * @throws TargetResolutionException
+     */
+    private void conversationPreinvoke(Message msg, RuntimeWire wire) {
+        if (!conversational) {
+            // Not conversational or the conversation has been started
+            return;
+        }
+
+        ConversationManager conversationManager = ((RuntimeWireImpl)wire).getConversationManager();
+
+        if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+
+            conversation = conversationManager.startConversation(getConversationID());
+            
+            // if this is a local wire then set up the conversation timeouts here based on the 
+            // parameters from the component
+            if (wire.getTarget().getComponent() != null){
+                conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+            }
+            
+            // connect the conversation to the CallableReference so it can be retrieve in the future
+            if (callableReference != null) {
+                ((CallableReferenceImpl)callableReference).attachConversation(conversation);
+            }
+        } else if (conversation.isExpired()) {
+            throw new ConversationEndedException("Conversation " +  conversation.getConversationID() + " has expired.");
+        }
+
+        // if this is a local wire then schedule conversation timeouts based on the timeout
+        // parameters from the service implementation. If this isn't a local wire then
+        // the RuntimeWireInvker will take care of this
+        if (wire.getTarget().getComponent() != null){
+            conversation.updateLastReferencedTime();
+        }
+
+        msg.getFrom().getReferenceParameters().setConversationID(conversation.getConversationID());
+
+    }
+
+    /**
+     * Post-invoke for the conversation handling
+     * @param wire
+     * @param operation
+     * @throws TargetDestructionException
+     */
+    @SuppressWarnings("unchecked")
+    private void conversationPostInvoke(Message msg, RuntimeWire wire) throws TargetDestructionException {
+        Operation operation = msg.getOperation();
+        ConversationSequence sequence = operation.getConversationSequence();
+        // We check that conversation has not already ended as there is only one
+        // conversation manager in the runtime and so, in the case of remote bindings, 
+        // the conversation will already have been stopped when we get back to the client
+        if ((sequence == ConversationSequence.CONVERSATION_END) && (conversation.getState() != ConversationState.ENDED)) {
+
+            // remove conversation id from scope container
+            ScopeContainer scopeContainer = getConversationalScopeContainer(wire);
+
+            if (scopeContainer != null) {
+                scopeContainer.remove(conversation.getConversationID());
+            }
+
+            conversation.end();
+        }
+    }
+
+    private ScopeContainer<Object> getConversationalScopeContainer(RuntimeWire wire) {
+        ScopeContainer<Object> scopeContainer = null;
+
+        RuntimeComponent runtimeComponent = wire.getSource().getComponent();
+
+        if (runtimeComponent instanceof ScopedRuntimeComponent) {
+            ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)runtimeComponent;
+            ScopeContainer<Object> tmpScopeContainer = scopedRuntimeComponent.getScopeContainer();
+
+            if ((tmpScopeContainer != null) && (tmpScopeContainer.getScope() == Scope.CONVERSATION)) {
+                scopeContainer = tmpScopeContainer;
+            }
+        }
+
+        return scopeContainer;
+    }
+
+    /**
+     * Creates a new conversation id
+     * 
+     * @return the conversation id
+     */
+    private Object createConversationID() {
+        if (getConversationID() != null) {
+            return getConversationID();
+        } else {
+            return UUID.randomUUID().toString();
+        }
+    }
+
+    /**
+     * @return the callableReference
+     */
+    public CallableReference<?> getCallableReference() {
+        return callableReference;
+    }
+
+    /**
+     * @param callableReference the callableReference to set
+     */
+    public void setCallableReference(CallableReference<?> callableReference) {
+        this.callableReference = callableReference;
+    }
+
+    /**
+     * Minimal wrapper for a callback object contained in a ServiceReference
+     */
+    private static class CallbackObjectWrapper<T> implements InstanceWrapper<T> {
+
+        private T instance;
+
+        private CallbackObjectWrapper(T instance) {
+            this.instance = instance;
+        }
+
+        public T getInstance() {
+            return instance;
+        }
+
+        public void start() {
+            // do nothing
+        }
+
+        public void stop() {
+            // do nothing
+        }
+
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.core.invocation;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * the default implementation of a wire service that uses JDK dynamic proxies
+ * 
+ * @version $$Rev: 628809 $$ $$Date: 2007-04-11 18:59:43 -0700 (Wed, 11 Apr
+ *          2007) $$
+ */
+public class JDKProxyFactory implements ProxyFactory {
+    protected InterfaceContractMapper contractMapper;
+    private MessageFactory messageFactory;
+
+    public JDKProxyFactory() {
+        this(new MessageFactoryImpl(), new InterfaceContractMapperImpl());
+    }
+
+    public JDKProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+        this.contractMapper = mapper;
+        this.messageFactory = messageFactory;
+    }
+
+    /** 
+     * The original createProxy method assumes that the proxy doesn't want to 
+     * share conversation state so sets the conversation object to null
+     */
+    public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+        ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, wire, this);
+        return createProxy(serviceReference);
+    }
+
+    public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+        assert callableReference != null;
+        Class<T> interfaze = callableReference.getBusinessInterface();
+        InvocationHandler handler = new JDKInvocationHandler(messageFactory, callableReference);
+        ClassLoader cl = interfaze.getClassLoader();
+		Object proxy = Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler);
+		((CallableReferenceImpl)callableReference).setProxy(proxy);
+        return interfaze.cast(proxy);
+    }
+
+    public <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException {
+        CallbackReferenceImpl<T> callbackReference = new CallbackReferenceImpl(interfaze, this, wires);
+        return createCallbackProxy(callbackReference);
+    }
+
+    public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+        assert callbackReference != null;
+        Class<T> interfaze = callbackReference.getBusinessInterface();
+        InvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, callbackReference);
+        ClassLoader cl = interfaze.getClassLoader();
+		Object proxy = Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler);
+		callbackReference.setProxy(proxy);
+        return interfaze.cast(proxy);
+    }
+
+    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+        InvocationHandler handler = Proxy.getInvocationHandler(target);
+        if (handler instanceof JDKInvocationHandler) {
+            return (R)((JDKInvocationHandler)handler).getCallableReference();
+        } else {
+            throw new IllegalArgumentException("The object is not a known proxy.");
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+     */
+    public boolean isProxyClass(Class<?> clazz) {
+        return Proxy.isProxyClass(clazz);
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.core.invocation;
+
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+
+/**
+ * Implementation of MessageFactory.
+ *
+ * @version $Rev: 537327 $ $Date: 2007-05-11 20:18:05 -0700 (Fri, 11 May 2007) $
+ */
+public class MessageFactoryImpl implements MessageFactory {
+
+    public Message createMessage() {
+        return new MessageImpl();
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,104 @@
+/*
+ * 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.core.invocation;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+
+/**
+ * The default implementation of a message flowed through a wire during an invocation
+ *
+ * @version $Rev $Date
+ */
+public class MessageImpl implements Message { 
+    private Object body;
+    private Object messageID;
+    private boolean isFault;
+    private Operation operation;
+    private Map<String, Object> qosContext = new Hashtable<String, Object>();
+
+    private EndpointReference from;
+    private EndpointReference to;
+
+    public MessageImpl() {
+        this.from = new EndpointReferenceImpl("/");
+        this.to = new EndpointReferenceImpl("/");
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> T getBody() {
+        return (T)body;
+    }
+
+    public <T> void setBody(T body) {
+        this.isFault = false;
+        this.body = body;
+    }
+
+    public Object getMessageID() {
+        return messageID;
+    }
+
+    public void setMessageID(Object messageId) {
+        this.messageID = messageId;
+    }
+
+    public boolean isFault() {
+        return isFault;
+    }
+
+    public void setFaultBody(Object fault) {
+        this.isFault = true;
+        this.body = fault;
+    }
+
+    public EndpointReference getFrom() {
+        return from;
+    }
+
+    public void setFrom(EndpointReference from) {
+        this.from = from;
+    }
+
+    public EndpointReference getTo() {
+        return to;
+    }
+
+    public void setTo(EndpointReference to) {
+        this.to = to;
+    }
+
+    public Operation getOperation() {
+        return operation;
+    }
+
+    public void setOperation(Operation op) {
+        this.operation = op;
+    }
+
+    public Map<String, Object> getQoSContext() {
+        return qosContext;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.core.invocation;
+
+
+/**
+ * Thrown when an {@link org.apache.tuscany.sca.core.factory.model.Operation} cannot be mapped to a method on an interface 
+ * @version $Rev: 567617 $ $Date: 2007-08-20 02:29:15 -0700 (Mon, 20 Aug 2007) $
+ */
+public class NoMethodForOperationException extends ProxyCreationException {
+    private static final long serialVersionUID = 5116536602309483679L;
+
+    public NoMethodForOperationException() {
+    }
+
+    public NoMethodForOperationException(String message) {
+        super(message);
+    }
+
+    public NoMethodForOperationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoMethodForOperationException(Throwable cause) {
+        super(cause);
+    }
+}



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