Author: nash
Date: Mon Feb 18 08:50:37 2008
New Revision: 628809

URL: http://svn.apache.org/viewvc?rev=628809&view=rev
Log:
Fix for TUSCANY-2035

Modified:
    
incubator/tuscany/java/sca/itest/callback-multiple-wires/src/main/java/org/apache/tuscany/sca/test/callback/MyServiceImpl.java
    
incubator/tuscany/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java
    
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
    
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java

Modified: 
incubator/tuscany/java/sca/itest/callback-multiple-wires/src/main/java/org/apache/tuscany/sca/test/callback/MyServiceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/callback-multiple-wires/src/main/java/org/apache/tuscany/sca/test/callback/MyServiceImpl.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/itest/callback-multiple-wires/src/main/java/org/apache/tuscany/sca/test/callback/MyServiceImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/itest/callback-multiple-wires/src/main/java/org/apache/tuscany/sca/test/callback/MyServiceImpl.java
 Mon Feb 18 08:50:37 2008
@@ -19,8 +19,10 @@
 package org.apache.tuscany.sca.test.callback;
 
 import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Context;
 import org.osoa.sca.annotations.Scope;
 import org.osoa.sca.annotations.Service;
+import org.osoa.sca.RequestContext;
 
 /**
  * This class implements MyService and uses a callback.
@@ -31,18 +33,13 @@
 
     private MyServiceCallback myServiceCallback;
 
-    /**
-     * The setter used by the runtime to set the callback reference 
-     * @param myServiceCallback
-     */
-    @Callback
-    public void setMyServiceCallback(MyServiceCallback myServiceCallback) {
-        this.myServiceCallback = myServiceCallback;
-    }
+    @Context
+       protected RequestContext requestContext;
     
     public void someMethod(String arg) {
         // invoke the callback
         try {
+            myServiceCallback = requestContext.getCallback();
             myServiceCallback.receiveResult(arg + " -> receiveResult");
         } catch(RuntimeException e) {
             System.out.println("RuntimeException invoking receiveResult: " + 
e.toString());

Modified: 
incubator/tuscany/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java
 Mon Feb 18 08:50:37 2008
@@ -30,6 +30,7 @@
 
 public class DWRService implements ComponentLifecycle {
 
+    private RuntimeComponent rc;
     private RuntimeComponentService rcs;
     private Binding binding;
     private ServletHost servletHost;
@@ -37,6 +38,7 @@
     static final String SERVLET_PATH = "/SCADomain/*";
 
     public DWRService(RuntimeComponent rc, RuntimeComponentService rcs, 
Binding binding, DWRBinding ab, ServletHost servletHost) {
+        this.rc = rc;
         this.rcs = rcs;
         this.binding = binding;
         this.servletHost = servletHost;
@@ -53,8 +55,7 @@
         Class<?> type = 
((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass();
 
         // Create a Java proxy to the target service
-        ProxyFactory proxyFactory = new JDKProxyFactory();
-        Object proxy = proxyFactory.createProxy(type, 
rcs.getRuntimeWire(binding));
+               Object proxy = 
rc.getComponentContext().createSelfReference(type, rcs).getService();
 
         servlet.addService(binding.getName(), type, proxy);
     }

Modified: 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
 Mon Feb 18 08:50:37 2008
@@ -54,6 +54,7 @@
     //       the same for clients using either the ajax or jsonrpc binding
     private static final String SCA_DOMAIN_SCRIPT = "/SCADomain/scaDomain.js";
     
+    private RuntimeComponent component;
     private RuntimeComponentService service;
     private InterfaceContract serviceContract;
     private JSONRPCBinding binding;
@@ -65,6 +66,7 @@
                                          RuntimeComponentService service,
                                          JSONRPCBinding binding,
                                          ServletHost servletHost) {
+        this.component = component;
         this.service = service;
         this.binding = binding;
         this.servletHost = servletHost;
@@ -88,8 +90,6 @@
     }
     
     public void start() {
-        RuntimeComponentService componentService = 
(RuntimeComponentService)service;
-
         // Set default databinding to json
         
serviceContract.getInterface().setDefaultDataBinding(JSONDataBinding.NAME);
 
@@ -97,12 +97,11 @@
         Class<?> serviceInterface = 
getTargetJavaClass(serviceContract.getInterface());
 
         // Create a Java proxy to the target service
-        ProxyFactory proxyFactory = new JDKProxyFactory();
-        Object proxy = proxyFactory.createProxy(serviceInterface, 
service.getRuntimeWire(binding));
+               Object proxy = 
component.getComponentContext().createSelfReference(serviceInterface, 
service).getService();
 
         // Create and register a servlet for this service
         JSONRPCServiceServlet serviceServlet =
-            new JSONRPCServiceServlet(binding, componentService, 
serviceContract, serviceInterface, proxy);
+            new JSONRPCServiceServlet(binding, service, serviceContract, 
serviceInterface, proxy);
         String mapping = binding.getURI();
         if (!mapping.endsWith("/")) {
             mapping += "/";

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
 Mon Feb 18 08:50:37 2008
@@ -62,8 +62,8 @@
     static final long serialVersionUID = -521548304761848325L;
     protected transient CompositeActivator compositeActivator;
     protected transient ProxyFactory proxyFactory;
-
     protected transient Class<B> businessInterface;
+    protected transient Object proxy;
 
     // if the wire targets a conversational service this holds the 
conversation state 
     protected transient ConversationManager conversationManager;
@@ -141,6 +141,7 @@
         if (wire != null) {
             this.component = wire.getSource().getComponent();
             this.reference = 
(RuntimeComponentReference)wire.getSource().getContract();
+                       System.out.println("$$$ reference = " + this.reference);
             this.binding = wire.getSource().getBinding();
             this.compositeActivator = 
((ComponentContextImpl)component.getComponentContext()).getCompositeActivator();
             this.conversationManager = 
this.compositeActivator.getConversationManager();
@@ -149,25 +150,6 @@
         }
     }
 
-    /**
-     * This method has bugs in it and has been replaced by the initCallbackID
-     * method below.  It is no longer called and will be removed soon.
-     */
-    protected void init(RuntimeWire wire) {
-        EndpointReference target = wire.getTarget();
-
-        // look to see if the target is conversational and if so create a 
conversation
-        InterfaceContract contract = target.getInterfaceContract();
-        if (contract == null) {
-            contract = reference.getInterfaceContract();
-        }
-        Interface contractInterface = contract.getInterface();
-
-        if (contract.getCallbackInterface() != null) {
-            this.callbackID = createCallbackID();
-        }
-    }
-
     protected void initCallbackID() {
         if (reference.getInterfaceContract().getCallbackInterface() != null) {
             this.callbackID = createCallbackID();
@@ -176,16 +158,26 @@
 
     public B getProxy() throws ObjectCreationException {
         try {
-            resolve();
-            //FIXME Can't we just return a single proxy
-            return businessInterface.cast(proxyFactory.createProxy(this));
+                       if (proxy == null) {
+                proxy = createProxy(); 
+                       }
+            return businessInterface.cast(proxy);
         } catch (Exception e) {
             throw new ObjectCreationException(e);
         }
     }
 
+       public void setProxy(Object proxy) {
+           this.proxy = proxy;
+       }
+
+    protected Object createProxy() throws Exception {
+        return proxyFactory.createProxy(this);
+       }
+
     public B getService() {
         try {
+            resolve();
             return getProxy();
         } catch (Exception e) {
             throw new ServiceRuntimeException(e);

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
 Mon Feb 18 08:50:37 2008
@@ -94,7 +94,7 @@
         Class<CB> javaClass = (Class<CB>)javaInterface.getJavaClass();
         List<RuntimeWire> wires = callbackReference.getRuntimeWires();
         CallbackReferenceImpl ref = new CallbackReferenceImpl(javaClass, 
proxyFactory, wires);
-        ref.resolveTarget();
+        //ref.resolveTarget();
         ReferenceParameters parameters = 
msgContext.getFrom().getReferenceParameters();
         ref.attachCallbackID(parameters.getCallbackID());
         if (ref.getConversation() != null) {

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
 Mon Feb 18 08:50:37 2008
@@ -43,61 +43,49 @@
     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 resolveTarget() {
+    public void init() {
         Message msgContext = ThreadMessageContext.getMessageContext();
         wire = selectCallbackWire(msgContext);
         if (wire == null) {
             //FIXME: need better exception
-            throw new RuntimeException("No callback wire found for " + 
msgContext.getFrom().getURI());
+            throw new RuntimeException("No callback binding found for " + 
msgContext.getTo().getURI());
         }
-        this.resolvedEndpoint = getCallbackEndpoint(msgContext);
-        bind(wire);
+        resolvedEndpoint = getCallbackEndpoint(msgContext);
+        convID = 
msgContext.getFrom().getReferenceParameters().getConversationID();
+        callbackID = 
msgContext.getFrom().getReferenceParameters().getCallbackID();
     }
 
     @Override
-    public B getProxy() throws ObjectCreationException {
-        if (wire != null) {
-            // wire and endpoint already resolved, so return a pre-wired proxy
-            wire.setTarget(resolvedEndpoint);
-            wire.rebuild();
-            return super.getProxy();
+    protected Object createProxy() throws Exception {
+        return proxyFactory.createCallbackProxy(this);
+       }
+
+    protected RuntimeWire getCallbackWire() {
+        if (resolvedEndpoint == null) {
+            return null;
         } else {
-            // wire not yet selected, so return a proxy that resolves the 
target dynamically
-            //FIXME: the following call creates a new instance of 
CallbackReferenceImpl
-            return proxyFactory.createCallbackProxy(businessInterface, wires);
-        }
+            return cloneAndBind(wire);
+               }
     }
 
-    public RuntimeWire selectCallbackWire(Message msgContext) {
-        EndpointReference callbackEPR = getCallbackEndpoint(msgContext);
-        if (callbackEPR == null) {
-            return null;
-        }
+    protected Object getConvID() {
+           return convID;
+       }
 
-        // first choice is wire with matching destination endpoint
-        for (RuntimeWire wire : wires) {
-            if (callbackEPR.getURI().equals(wire.getTarget().getURI())) {
-                RuntimeWire clonedWire = 
((RuntimeWireImpl)wire).lookupCache(callbackEPR);
-                if (clonedWire != null) {
-                    return clonedWire;
-                }
-                try {
-                    clonedWire = (RuntimeWire)wire.clone();
-                    ((RuntimeWireImpl)wire).addToCache(callbackEPR, 
clonedWire);
-                    return clonedWire;
-                } catch (CloneNotSupportedException e) {
-                    throw new ServiceRuntimeException(e);
-                }
-            }
-        }
+    protected EndpointReference getResolvedEndpoint() {
+           return resolvedEndpoint;
+       }
 
-        // no exact match, so find callback binding with same name as service 
binding
+    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
@@ -105,24 +93,14 @@
         }
         for (RuntimeWire wire : wires) {
             if 
(wire.getSource().getBinding().getName().equals(to.getBinding().getName())) {
-                //FIXME: need better way to represent dynamic wire
-                if (wire.getTarget().getURI().equals("/")) { // dynamic wire
-                    //FIXME: avoid doing this for genuine dynamic wires
-                    return cloneAndBind(msgContext, wire);
-                }
-                //FIXME: no dynamic wire, so should attempt to create a static 
wire 
+                           return wire;
             }
         }
 
-        // no match so far, so find callback binding with same type as service 
binding
+        // 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()) {
-                //FIXME: need better way to represent dynamic wire
-                if (wire.getTarget().getURI().equals("/")) { // dynamic wire
-                    //FIXME: avoid doing this for genuine dynamic wires
-                    return cloneAndBind(msgContext, wire);
-                }
-                //FIXME: no dynamic wire, so should attempt to create a static 
wire 
+                           return wire;
             }
         }
 
@@ -141,32 +119,31 @@
         return from.getReferenceParameters().getCallbackReference();
     }
 
-    private RuntimeWire cloneAndBind(Message msgContext, RuntimeWire wire) {
-        EndpointReference callback = getCallbackEndpoint(msgContext);
+    private RuntimeWire cloneAndBind(RuntimeWire wire) {
         RuntimeWire boundWire = null;
-        if (callback != null) {
-            boundWire = ((RuntimeWireImpl)wire).lookupCache(callback);
+        if (resolvedEndpoint != null) {
+            boundWire = ((RuntimeWireImpl)wire).lookupCache(resolvedEndpoint);
             if (boundWire != null) {
                 return boundWire;
             }
             try {
-                Contract contract = callback.getContract();
+                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(callback.getBinding());
+                    boundWire = 
ref.getRuntimeWire(resolvedEndpoint.getBinding());
 
                 } else {  // contract instanceof RuntimeComponentService
                     ref = 
bind((RuntimeComponentReference)wire.getSource().getContract(),
-                               callback.getComponent(),
+                               resolvedEndpoint.getComponent(),
                                (RuntimeComponentService)contract);
                     boundWire = ref.getRuntimeWires().get(0);
                 }
-                configureWire(boundWire, msgContext);
-                ((RuntimeWireImpl)wire).addToCache(callback, boundWire);
+                configureWire(boundWire);
+                ((RuntimeWireImpl)wire).addToCache(resolvedEndpoint, 
boundWire);
             } catch (CloneNotSupportedException e) {
                 // will not happen
             }
@@ -194,20 +171,19 @@
         return ref;
     }
 
-    private void configureWire(RuntimeWire wire, Message msgContext) {
+    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
-        EndpointReference epr = 
msgContext.getFrom().getReferenceParameters().getCallbackReference();
-        wire.getSource().getBinding().setURI(epr.getURI());
+        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();
-        Binding binding = wire.getSource().getBinding();
         
wire.getTarget().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
     }
 }

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
 Mon Feb 18 08:50:37 2008
@@ -28,6 +28,7 @@
 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;
@@ -55,11 +56,8 @@
     }
 
     public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws 
ProxyCreationException {
-        Enhancer enhancer = new Enhancer();
-        enhancer.setSuperclass(interfaze);
-        enhancer.setCallback(new CglibMethodInterceptor<T>(interfaze, wire));
-        Object proxy = enhancer.create();
-        return interfaze.cast(proxy);
+        ServiceReference<T> serviceReference = new 
ServiceReferenceImpl(interfaze, wire, this);
+        return createProxy(serviceReference);
     }
 
     /**
@@ -72,6 +70,7 @@
         enhancer.setSuperclass(interfaze);
         enhancer.setCallback(new CglibMethodInterceptor<T>(callableReference));
         Object proxy = enhancer.create();
+               ((CallableReferenceImpl)callableReference).setProxy(proxy);
         return interfaze.cast(proxy);
     }
 
@@ -80,10 +79,21 @@
      * 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>(interfaze, wires));
+        enhancer.setCallback(new CglibMethodInterceptor<T>(callbackReference));
         Object proxy = enhancer.create();
+               callbackReference.setProxy(proxy);
         return interfaze.cast(proxy);
     }
 
@@ -116,6 +126,11 @@
             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);
@@ -125,6 +140,7 @@
             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)

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
 Mon Feb 18 08:50:37 2008
@@ -108,6 +108,14 @@
         }
     }
 
+    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)

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
 Mon Feb 18 08:50:37 2008
@@ -55,17 +55,16 @@
             return invokeObjectMethod(method, args);
         }
 
-        // wire not pre-selected, so select a wire now to be used for the 
callback
-        Message msgContext = ThreadMessageContext.getMessageContext();
-        RuntimeWire wire = 
((CallbackReferenceImpl)callableReference).selectCallbackWire(msgContext);
+        // 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 for " + 
msgContext.getFrom().getURI());
+            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
-        init(wire);
+        initConversational(wire);
 
         // set the conversation id into the conversation object. This is
         // a special case for callbacks as, unless otherwise set manually,
@@ -81,7 +80,7 @@
             // create a conversation id if one doesn't exist 
             // already, i.e. the conversation is just starting
             if (convID == null) {
-                convID = 
msgContext.getFrom().getReferenceParameters().getConversationID();
+                convID = 
((CallbackReferenceImpl)callableReference).getConvID();
                 if (convID != null) {
                     conversation = 
((RuntimeWireImpl)wire).getConversationManager().getConversation(convID);
                     if (callableReference != null) {
@@ -91,15 +90,8 @@
             }
         }
 
-        Object callbackID = 
msgContext.getFrom().getReferenceParameters().getCallbackID();
-        
((CallbackReferenceImpl)callableReference).attachCallbackID(callbackID);
+        
setEndpoint(((CallbackReferenceImpl)callableReference).getResolvedEndpoint());
 
-        EndpointReference epr = 
msgContext.getFrom().getReferenceParameters().getCallbackReference();
-        setEndpoint(epr);
-
-        // code that was previously here has been moved to 
CallbackReferenceImpl.configureWire()
-
-        //FIXME: can we use the same code as JDKInvocationHandler to select 
the chain? 
         InvocationChain chain = getInvocationChain(method, wire);
         if (chain == null) {
             throw new IllegalArgumentException("No matching operation is 
found: " + method);

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
 Mon Feb 18 08:50:37 2008
@@ -98,13 +98,19 @@
 
     protected void init(RuntimeWire wire) {
         if (wire != null) {
+                   /* [scn] no need to clone because the wire doesn't get 
modified
             try {
                 // Clone the wire so that reference parameters can be changed
                 this.wire = (RuntimeWire)wire.clone();
             } catch (CloneNotSupportedException e) {
                 throw new ServiceRuntimeException(e);
             }
+                       [scn] */
+            initConversational(wire);
         }
+    }
+
+    protected void initConversational(RuntimeWire wire) {
         InterfaceContract contract = wire.getSource().getInterfaceContract();
         this.conversational = contract.getInterface().isConversational();
     }

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
 Mon Feb 18 08:50:37 2008
@@ -22,11 +22,14 @@
 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
@@ -49,27 +52,36 @@
 
     /** 
      * The original createProxy method assumes that the proxy doesn't want to 
-     * share conversation state so sets the conversaton object to null
+     * share conversation state so sets the conversation object to null
      */
     public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws 
ProxyCreationException {
-        JDKInvocationHandler handler = new 
JDKInvocationHandler(messageFactory, interfaze, wire);
-        ClassLoader cl = interfaze.getClassLoader();
-        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] 
{interfaze}, handler));
+        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();
-        JDKInvocationHandler handler = new 
JDKInvocationHandler(messageFactory, callableReference);
+        InvocationHandler handler = new JDKInvocationHandler(messageFactory, 
callableReference);
         ClassLoader cl = interfaze.getClassLoader();
-        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] 
{interfaze}, handler));
+               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();
-        CallbackReferenceImpl ref = new CallbackReferenceImpl(interfaze, this, 
wires);
-        JDKCallbackInvocationHandler handler = new 
JDKCallbackInvocationHandler(messageFactory, ref);
-        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] 
{interfaze}, handler));
+               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 {

Modified: 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java?rev=628809&r1=628808&r2=628809&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
 Mon Feb 18 08:50:37 2008
@@ -60,6 +60,15 @@
     <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) 
throws ProxyCreationException;
 
     /**
+     * Creates a Java proxy for the given callback reference
+     *
+     * @param callableReference The callable reference
+     * @return the proxy
+     * @throws ProxyCreationException
+     */
+    <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) 
throws ProxyCreationException;
+
+    /**
      * Cast a proxy to a CallableReference.
      *
      * @param target a proxy generated by this implementation



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

Reply via email to