You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2007/02/17 09:35:25 UTC

svn commit: r508732 [3/8] - in /incubator/tuscany/java/sca: kernel/core/src/main/java/org/apache/tuscany/core/binding/local/ kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/ kernel/core/src/main/java/org/apache/tuscany/core/builder/ kernel/...

Copied: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java (from r507339, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java?view=diff&rev=508732&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java&r1=507339&p2=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java Sat Feb 17 00:35:19 2007
@@ -18,26 +18,24 @@
  */
 package org.apache.tuscany.core.wire;
 
-import java.util.LinkedList;
 import java.net.URI;
+import java.util.LinkedList;
 
 import org.osoa.sca.ServiceRuntimeException;
 
 import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
 import org.apache.tuscany.spi.services.work.WorkScheduler;
 import org.apache.tuscany.spi.wire.Interceptor;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.model.Scope;
 
 /**
- * Bridges interceptors in a non-blocking fashion between an {@link org.apache.tuscany.spi.wire.InboundInvocationChain}
- * and an {@link org.apache.tuscany.spi.wire.OutboundInvocationChain} by using a {@link
- * org.apache.tuscany.spi.component.WorkContext}.
+ * Adds non-blocking behavior to an invocation chain
  *
  * @version $$Rev$$ $$Date$$
  */
-public class NonBlockingBridgingInterceptor implements BridgingInterceptor {
+public class NonBlockingInterceptor implements Interceptor {
 
     private static final Message RESPONSE = new ImmutableMessage();
 
@@ -45,12 +43,12 @@
     private WorkContext workContext;
     private Interceptor next;
 
-    public NonBlockingBridgingInterceptor(WorkScheduler workScheduler, WorkContext workContext) {
+    public NonBlockingInterceptor(WorkScheduler workScheduler, WorkContext workContext) {
         this.workScheduler = workScheduler;
         this.workContext = workContext;
     }
 
-    public NonBlockingBridgingInterceptor(WorkScheduler workScheduler, WorkContext workContext, Interceptor next) {
+    public NonBlockingInterceptor(WorkScheduler workScheduler, WorkContext workContext, Interceptor next) {
         this.workScheduler = workScheduler;
         this.workContext = workContext;
         this.next = next;
@@ -125,19 +123,15 @@
             throw new UnsupportedOperationException();
         }
 
-        public URI popFromAddress() {
-            return null;
-        }
-
-        public void pushFromAddress(URI fromAddress) {
+        public void pushCallbackUri(URI fromAddress) {
             throw new UnsupportedOperationException();
         }
 
-        public LinkedList<URI> getCallbackRoutingChain() {
+        public LinkedList<URI> getCallbackUris() {
             return null;
         }
 
-        public void setCallbackRoutingChain(LinkedList<URI> fromAddresses) {
+        public void setCallbackUris(LinkedList<URI> uris) {
             throw new UnsupportedOperationException();
         }
 

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java Sat Feb 17 00:35:19 2007
@@ -21,7 +21,7 @@
 import org.apache.tuscany.spi.ObjectCreationException;
 import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.Wire;
 
 /**
  * Returns a target instance directly from a wire
@@ -30,16 +30,16 @@
  */
 public class OptimizedWireObjectFactory<B> implements ObjectFactory<B> {
     private final Class<B> type;
-    private final OutboundWire wire;
+    private Wire wire;
 
-    public OptimizedWireObjectFactory(Class<B> type, OutboundWire factory) {
+    public OptimizedWireObjectFactory(Class<B> type, Wire factory) {
         this.wire = factory;
         this.type = type;
     }
 
     public B getInstance() throws ObjectCreationException {
         try {
-            return type.cast(wire.getTargetService());
+            return type.cast(wire.getTargetInstance());
         } catch (TargetResolutionException e) {
             throw new ObjectCreationException(e);
         }

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java Sat Feb 17 00:35:19 2007
@@ -24,6 +24,7 @@
 import java.util.Map;
 import javax.xml.namespace.QName;
 
+import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.spi.component.TargetResolutionException;
 import org.apache.tuscany.spi.model.Operation;
 import org.apache.tuscany.spi.model.ServiceContract;
@@ -40,10 +41,12 @@
     private URI targetUri;
     private String callbackReferenceName;
     private QName bindingType;
-    private ServiceContract serviceContract;
+    private ServiceContract sourceContract;
+    private ServiceContract targetContract;
     private boolean optimizable;
     private Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
     private Map<Operation<?>, InvocationChain> callbackChains = new HashMap<Operation<?>, InvocationChain>();
+    private AtomicComponent target;
 
     /**
      * Creates a wire with a local binding
@@ -80,8 +83,8 @@
         return callbackReferenceName;
     }
 
-    public void setCallbackReferenceName(String callbackReferenceName) {
-        this.callbackReferenceName = callbackReferenceName;
+    public void setCallbackReferenceName(String name) {
+        this.callbackReferenceName = name;
     }
 
     public QName getBindingType() {
@@ -89,12 +92,21 @@
     }
 
 
-    public ServiceContract getServiceContract() {
-        return serviceContract;
+    public ServiceContract getSourceContract() {
+        return sourceContract;
     }
 
-    public void setServiceContract(ServiceContract serviceContract) {
-        this.serviceContract = serviceContract;
+    public void setSourceContract(ServiceContract contract) {
+        this.sourceContract = contract;
+    }
+
+
+    public ServiceContract getTargetContract() {
+        return targetContract;
+    }
+
+    public void setTargetContract(ServiceContract contract) {
+        this.targetContract = contract;
     }
 
     public boolean isOptimizable() {
@@ -105,8 +117,15 @@
         this.optimizable = optimizable;
     }
 
-    public Object getTargetService() throws TargetResolutionException {
-        return null;
+    public Object getTargetInstance() throws TargetResolutionException {
+        if (target == null) {
+            return null;
+        }
+        return target.getTargetInstance();
+    }
+
+    public void setTarget(AtomicComponent target) {
+        this.target = target;
     }
 
     public Map<Operation<?>, InvocationChain> getInvocationChains() {

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java Sat Feb 17 00:35:19 2007
@@ -25,8 +25,8 @@
 import org.apache.tuscany.spi.ObjectCreationException;
 import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.Wire;
 import org.apache.tuscany.spi.wire.WireService;
 
 /**
@@ -36,10 +36,10 @@
  */
 public class WireObjectFactory<T> implements ObjectFactory<T> {
     private Class<T> interfaze;
-    private OutboundWire wire;
+    private Wire wire;
     private WireService wireService;
     // the cache of proxy interface method to operation mappings
-    private Map<Method, OutboundChainHolder> mappings;
+    private Map<Method, ChainHolder> mappings;
     private boolean optimizable;
 
     /**
@@ -50,34 +50,34 @@
      * @param wireService the wire service to create the proxy
      * @throws NoMethodForOperationException
      */
-    public WireObjectFactory(Class<T> interfaze, OutboundWire wire, WireService wireService)
+    public WireObjectFactory(Class<T> interfaze, Wire wire, WireService wireService)
         throws NoMethodForOperationException {
         this.interfaze = interfaze;
         this.wire = wire;
         this.wireService = wireService;
         this.mappings = WireUtils.createInterfaceToWireMapping(interfaze, wire);
+        if (wire.isOptimizable()
+            && wire.getSourceContract().getInterfaceClass() != null
+            && interfaze.isAssignableFrom(wire.getSourceContract().getInterfaceClass())) {
+            optimizable = true;
+        }
     }
 
     public T getInstance() throws ObjectCreationException {
-        // note optimization must be done lazily as wire object factories are created during the build phase prior
-        // to the outbound and inbound wires being connected
-        if ((optimizable
-            || wire.isOptimizable())
-            && wire.getServiceContract().getInterfaceClass() != null
-            && interfaze.isAssignableFrom(wire.getServiceContract().getInterfaceClass())) {
-            optimizable = true;
+        if (optimizable) {
             try {
-                return interfaze.cast(wire.getTargetService());
+                return interfaze.cast(wire.getTargetInstance());
             } catch (TargetResolutionException e) {
                 throw new ObjectCreationException(e);
             }
+        } else {
+            // clone the cached mappings
+            Map<Method, ChainHolder> newChains = new HashMap<Method, ChainHolder>(mappings.size());
+            for (Map.Entry<Method, ChainHolder> entry : mappings.entrySet()) {
+                newChains.put(entry.getKey(), entry.getValue().clone());
+            }
+            return interfaze.cast(wireService.createProxy(interfaze, wire, newChains));
         }
-        // clone the cached mappings
-        Map<Method, OutboundChainHolder> newChains = new HashMap<Method, OutboundChainHolder>(mappings.size());
-        for (Map.Entry<Method, OutboundChainHolder> entry : mappings.entrySet()) {
-            newChains.put(entry.getKey(), entry.getValue().clone());
-        }
-        return interfaze.cast(wireService.createProxy(interfaze, wire, newChains));
     }
 
 

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java Sat Feb 17 00:35:19 2007
@@ -18,34 +18,13 @@
  */
 package org.apache.tuscany.core.wire;
 
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ReferenceBinding;
-import org.apache.tuscany.spi.component.ServiceBinding;
 import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.model.ComponentType;
-import org.apache.tuscany.spi.model.Implementation;
-import org.apache.tuscany.spi.model.Multiplicity;
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.model.ReferenceDefinition;
-import org.apache.tuscany.spi.model.ReferenceTarget;
 import org.apache.tuscany.spi.model.ServiceContract;
-import org.apache.tuscany.spi.model.ServiceDefinition;
 import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.WireService;
 
-import org.apache.tuscany.core.binding.local.LocalReferenceBinding;
-
 /**
  * Base class for wire service extensions
  *
@@ -60,138 +39,6 @@
         this.context = context;
     }
 
-    public OutboundInvocationChain createOutboundChain(Operation<?> operation) {
-        return new OutboundInvocationChainImpl(operation);
-    }
-
-    public InboundInvocationChain createInboundChain(Operation<?> operation) {
-        return new InboundInvocationChainImpl(operation);
-    }
-
-    public InboundWire createWire(ServiceDefinition service) {
-        InboundWire wire = new InboundWireImpl();
-        ServiceContract<?> contract = service.getServiceContract();
-        wire.setServiceContract(contract);
-        wire.setSourceUri(service.getUri());
-        for (Operation<?> operation : contract.getOperations().values()) {
-            InboundInvocationChain chain = createInboundChain(operation);
-            chain.addInterceptor(new InvokerInterceptor());
-            wire.addInboundInvocationChain(operation, chain);
-        }
-        if (contract.getCallbackName() != null) {
-            wire.setCallbackReferenceName(service.getCallbackReferenceName());
-        }
-        return wire;
-    }
-
-    public void createWires(AtomicComponent component, ComponentDefinition<?> definition) {
-        Implementation<?> implementation = definition.getImplementation();
-        ComponentType<?, ?, ?> componentType = implementation.getComponentType();
-        // create incoming service wires
-        for (ServiceDefinition service : componentType.getServices().values()) {
-            InboundWire wire = createWire(service);
-            // JFM TODO refactor
-            wire.setComponent(component);
-            component.addInboundWire(wire);
-        }
-        // create outgoing reference wires
-        for (ReferenceTarget referenceTarget : definition.getReferenceTargets().values()) {
-            Map<String, ? extends ReferenceDefinition> references = componentType.getReferences();
-            ReferenceDefinition mappedReference = references.get(referenceTarget.getReferenceName().getFragment());
-            assert mappedReference != null;
-            List<OutboundWire> wires = createWire(referenceTarget, mappedReference);
-            Multiplicity multiplicity = mappedReference.getMultiplicity();
-            if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) {
-                // 0..1 or 1..1
-                for (OutboundWire wire : wires) {
-                    component.addOutboundWire(wire);
-                }
-            } else {
-                // 0..N or 1..N
-                component.addOutboundWires(wires);
-            }
-        }
-    }
-
-    public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract, URI target) {
-        InboundWire inboundWire = new InboundWireImpl(referenceBinding.getBindingType());
-        inboundWire.setServiceContract(contract);
-        inboundWire.setSourceUri(referenceBinding.getUri());
-        for (Operation<?> operation : contract.getOperations().values()) {
-            InboundInvocationChain chain = createInboundChain(operation);
-            inboundWire.addInboundInvocationChain(operation, chain);
-        }
-        OutboundWire outboundWire = new OutboundWireImpl(referenceBinding.getBindingType());
-        outboundWire.setSourceUri(referenceBinding.getUri());
-        outboundWire.setTargetUri(target);
-        // [rfeng] Check if the Reference has the binding contract
-        ServiceContract<?> bindingContract = referenceBinding.getBindingServiceContract();
-        if (bindingContract == null) {
-            bindingContract = contract;
-        }
-        outboundWire.setServiceContract(bindingContract);
-        for (Operation<?> operation : bindingContract.getOperations().values()) {
-            OutboundInvocationChain chain = createOutboundChain(operation);
-            if (referenceBinding instanceof LocalReferenceBinding) {
-                // Not ideal but the local binding case is special as its inbound and outbound wires are connected
-                // before the outbound wire is connected to the reference target. This requires the binding outbound
-                // chain to have an interceptor to connect to from the binding inbound chain. This outbound
-                // interceptor will then be bridged to the head target interceptor
-                chain.addInterceptor(new SynchronousBridgingInterceptor());
-            } else {
-                chain.addInterceptor(new InvokerInterceptor());
-            }
-            outboundWire.addOutboundInvocationChain(operation, chain);
-        }
-        // Add target callback chain to outbound wire
-        if (contract.getCallbackName() != null) {
-            for (Operation<?> operation : contract.getCallbackOperations().values()) {
-                InboundInvocationChain callbackTargetChain = createInboundChain(operation);
-                callbackTargetChain.addInterceptor(new InvokerInterceptor());
-                outboundWire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
-            }
-        }
-        referenceBinding.setInboundWire(inboundWire);
-        referenceBinding.setOutboundWire(outboundWire);
-    }
-
-    public void createWires(ServiceBinding serviceBinding, ServiceContract<?> contract, String targetName) {
-        InboundWire inboundWire = new InboundWireImpl(serviceBinding.getBindingType());
-        // [rfeng] Check if the Reference has the serviceBinding contract
-        ServiceContract<?> bindingContract = serviceBinding.getBindingServiceContract();
-        if (bindingContract == null) {
-            bindingContract = contract;
-        }
-        inboundWire.setServiceContract(bindingContract);
-        inboundWire.setSourceUri(serviceBinding.getUri());
-        for (Operation<?> operation : bindingContract.getOperations().values()) {
-            InboundInvocationChain inboundChain = createInboundChain(operation);
-            inboundChain.addInterceptor(new SynchronousBridgingInterceptor());
-            inboundWire.addInboundInvocationChain(operation, inboundChain);
-        }
-
-        OutboundWire outboundWire = new OutboundWireImpl(serviceBinding.getBindingType());
-        outboundWire.setServiceContract(contract);
-        outboundWire.setSourceUri(serviceBinding.getUri());
-        outboundWire.setTargetUri(URI.create(targetName));
-
-        for (Operation<?> operation : contract.getOperations().values()) {
-            OutboundInvocationChain outboundChain = createOutboundChain(operation);
-            outboundWire.addOutboundInvocationChain(operation, outboundChain);
-        }
-
-        // Add target callback chain to outbound wire
-        if (contract.getCallbackName() != null) {
-            for (Operation<?> operation : contract.getCallbackOperations().values()) {
-                InboundInvocationChain callbackTargetChain = createInboundChain(operation);
-                callbackTargetChain.addInterceptor(new InvokerInterceptor());
-                outboundWire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
-            }
-        }
-        serviceBinding.setInboundWire(inboundWire);
-        serviceBinding.setOutboundWire(outboundWire);
-    }
-
     public boolean checkCompatibility(ServiceContract<?> source,
                                       ServiceContract<?> target,
                                       boolean ignoreCallback,
@@ -267,39 +114,5 @@
         return true;
     }
 
-
-    /**
-     * Creates a wire for flowing outbound invocations from a reference
-     *
-     * @param target     the reference definition
-     * @param definition the reference target configuration
-     * @return the wire the outbound wire
-     */
-    protected List<OutboundWire> createWire(ReferenceTarget target, ReferenceDefinition definition) {
-        ServiceContract<?> contract = definition.getServiceContract();
-        List<OutboundWire> outboundWires = new ArrayList<OutboundWire>();
-        // NOTE: it is possible that targets are empty (e.g. when a reference is not required). 
-        // Return without creating wires
-        for (URI uri : target.getTargets()) {
-            OutboundWire wire = new OutboundWireImpl();
-            wire.setServiceContract(contract);
-            wire.setSourceUri(target.getReferenceName());
-            wire.setTargetUri(uri);
-            for (Operation<?> operation : contract.getOperations().values()) {
-                OutboundInvocationChain chain = createOutboundChain(operation);
-                wire.addOutboundInvocationChain(operation, chain);
-
-            }
-            if (contract.getCallbackName() != null) {
-                for (Operation<?> operation : contract.getCallbackOperations().values()) {
-                    InboundInvocationChain callbackTargetChain = createInboundChain(operation);
-                    callbackTargetChain.addInterceptor(new InvokerInterceptor());
-                    wire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
-                }
-            }
-            outboundWires.add(wire);
-        }
-        return outboundWires;
-    }
 
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java Sat Feb 17 00:35:19 2007
@@ -22,16 +22,12 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.tuscany.spi.component.Component;
-import org.apache.tuscany.spi.component.SCAObject;
 import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.ChainHolder;
 import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
 
 /**
  * Utilities for operating on wires
@@ -51,12 +47,12 @@
      * @return a collection containing the method to invocation chain mapping
      * @throws NoMethodForOperationException
      */
-    public static Map<Method, InboundInvocationChain> createInboundMapping(InboundWire wire, Method[] methods)
+    public static Map<Method, InvocationChain> createInboundMapping(Wire wire, Method[] methods)
         throws NoMethodForOperationException {
-        Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
-        for (Map.Entry<Operation<?>, InboundInvocationChain> entry : wire.getInboundInvocationChains().entrySet()) {
+        Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>();
+        for (Map.Entry<Operation<?>, InvocationChain> entry : wire.getInvocationChains().entrySet()) {
             Operation<?> operation = entry.getKey();
-            InboundInvocationChain chain = entry.getValue();
+            InvocationChain chain = entry.getValue();
             Method method = findMethod(operation, methods);
             if (method == null) {
                 throw new NoMethodForOperationException(operation.getName());
@@ -75,18 +71,18 @@
      * @return a collection of method to operation mappings
      * @throws NoMethodForOperationException
      */
-    public static Map<Method, OutboundChainHolder> createInterfaceToWireMapping(Class<?> interfaze, OutboundWire wire)
+    public static Map<Method, ChainHolder> createInterfaceToWireMapping(Class<?> interfaze, Wire wire)
         throws NoMethodForOperationException {
-        Map<Operation<?>, OutboundInvocationChain> invocationChains = wire.getOutboundInvocationChains();
-        Map<Method, OutboundChainHolder> chains = new HashMap<Method, OutboundChainHolder>(invocationChains.size());
+        Map<Operation<?>, InvocationChain> invocationChains = wire.getInvocationChains();
+        Map<Method, ChainHolder> chains = new HashMap<Method, ChainHolder>(invocationChains.size());
         Method[] methods = interfaze.getMethods();
-        for (Map.Entry<Operation<?>, OutboundInvocationChain> entry : invocationChains.entrySet()) {
+        for (Map.Entry<Operation<?>, InvocationChain> entry : invocationChains.entrySet()) {
             Operation operation = entry.getKey();
             Method method = findMethod(operation, methods);
             if (method == null) {
                 throw new NoMethodForOperationException(operation.getName());
             }
-            chains.put(method, new OutboundChainHolder(entry.getValue()));
+            chains.put(method, new ChainHolder(entry.getValue()));
         }
         return chains;
     }
@@ -98,8 +94,8 @@
      * @param wire the wire
      * @return true if the wire is optimizable
      */
-    public static boolean isOptimizable(OutboundWire wire) {
-        for (OutboundInvocationChain chain : wire.getOutboundInvocationChains().values()) {
+    public static boolean isOptimizable(Wire wire) {
+        for (InvocationChain chain : wire.getInvocationChains().values()) {
             if (chain.getHeadInterceptor() != null) {
                 Interceptor current = chain.getHeadInterceptor();
                 if (current == null) {
@@ -114,33 +110,6 @@
             }
         }
         // if there is a callback, the wire is never optimizable since the callback target needs to be disambiguated
-        return wire.getTargetCallbackInvocationChains().isEmpty();
+        return wire.getCallbackInvocationChains().isEmpty();
     }
-
-    /**
-     * Determines if the given wire is optimizable, i.e. its invocation chains may be bypassed during an invocation.
-     * This is typically calculated during the connect phase to optimize away invocation chains.
-     *
-     * @param container the wire container
-     * @param wire the wire
-     * @return true if the wire is optimizable
-     */
-    public static boolean isOptimizable(SCAObject container, InboundWire wire) {
-        if (!(container instanceof Component) || !((Component) container).isOptimizable()) {
-            return false;
-        }
-        for (InboundInvocationChain chain : wire.getInboundInvocationChains().values()) {
-            if (chain.getHeadInterceptor() != null) {
-                Interceptor current = chain.getHeadInterceptor();
-                while (current != null) {
-                    if (!current.isOptimizable()) {
-                        return false;
-                    }
-                    current = current.getNext();
-                }
-            }
-        }
-        return true;
-    }
-
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java Sat Feb 17 00:35:19 2007
@@ -25,9 +25,12 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
-import java.net.URI;
 
 import org.osoa.sca.NoRegisteredCallbackException;
 
@@ -37,37 +40,44 @@
 import org.apache.tuscany.spi.component.WorkContext;
 import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 import org.apache.tuscany.spi.wire.WireInvocationHandler;
 
 
 /**
- * Responsible for invoking on an outbound wire associated with a callback. The handler retrieves the correct outbound
- * callback wire from the work context.
+ * Responsible for dispatching to a callback through a wire.
  * <p/>
  * TODO cache target invoker
  *
  * @version $Rev$ $Date$
  */
-public class JDKCallbackInvocationHandler extends AbstractOutboundInvocationHandler
+public class JDKCallbackInvocationHandler extends AbstractInvocationHandler
     implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
     private transient WorkContext context;
-    private transient InboundWire wire;
-    private String serviceName;
+    private transient Map<URI, Wire> wires;
+    private List<String> sourceWireNames;
 
     /**
      * Constructor used for deserialization only
      */
     public JDKCallbackInvocationHandler() {
+        sourceWireNames = new ArrayList<String>();
+        wires = new HashMap<URI, Wire>();
     }
 
-    public JDKCallbackInvocationHandler(InboundWire wire, WorkContext context) {
+    public JDKCallbackInvocationHandler(List<Wire> wireList, WorkContext context) {
         this.context = context;
-        this.wire = wire;
-        this.serviceName = wire.getSourceUri().getFragment();
+        this.wires = new HashMap<URI, Wire>();
+        for (Wire wire : wireList) {
+            wires.put(wire.getSourceUri(), wire);
+        }
+        sourceWireNames = new ArrayList<String>();
+        for (URI uri : wires.keySet()) {
+            sourceWireNames.add(uri.getFragment());
+        }
     }
 
     @SuppressWarnings({"unchecked"})
@@ -85,23 +95,19 @@
         }
         Object correlationId = context.getCurrentCorrelationId();
         context.setCurrentCorrelationId(null);
-        LinkedList<URI> callbackRoutingChain = (LinkedList<URI>) context.getCurrentCallbackRoutingChain().clone();
-        if (callbackRoutingChain == null) {
-            throw new AssertionError("Missing stack of from addresses");
-        }
-        URI targetAddress = callbackRoutingChain.removeFirst();
-        if (targetAddress == null) {
-            throw new AssertionError("Popped a null from address from stack");
-        }
-        //TODO optimize as this is slow in local invocations
-        Map<Operation<?>, OutboundInvocationChain> sourceCallbackInvocationChains =
-            wire.getSourceCallbackInvocationChains(targetAddress);
-        Operation operation = findOperation(method, sourceCallbackInvocationChains.keySet());
-        OutboundInvocationChain chain = sourceCallbackInvocationChains.get(operation);
+        LinkedList<URI> callbackUris = context.getCurrentCallbackUris();
+        assert callbackUris != null;
+        URI targetAddress = callbackUris.getLast();
+        assert targetAddress != null;
+        Wire wire = wires.get(targetAddress);
+        assert wire != null;
+        Map<Operation<?>, InvocationChain> chains = wire.getCallbackInvocationChains();
+        Operation operation = findOperation(method, chains.keySet());
+        InvocationChain chain = chains.get(operation);
         TargetInvoker invoker = chain.getTargetInvoker();
 
         try {
-            return invoke(chain, invoker, args, correlationId, callbackRoutingChain);
+            return invoke(chain, invoker, args, correlationId, callbackUris);
         } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             if (t instanceof NoRegisteredCallbackException) {
@@ -117,11 +123,18 @@
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(serviceName);
+        int i = sourceWireNames.size() - 1;
+        out.writeInt(i);
+        for (String name : sourceWireNames) {
+            out.writeObject(name);
+        }
     }
 
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        serviceName = (String) in.readObject();
+        int num = in.readInt();
+        for (int i = 0; i <= num; i++) {
+            sourceWireNames.add((String) in.readObject());
+        }
     }
 
     public void setWorkContext(WorkContext context) {
@@ -133,6 +146,11 @@
         if (owner == null) {
             throw new ReactivationException("Current atomic component not set on work context");
         }
-        wire = owner.getInboundWire(serviceName);
+        for (String name : sourceWireNames) {
+            // TODO JFM support multiplicity, remove get(0)
+            Wire wire = owner.getWires(name).get(0);
+            wires.put(wire.getSourceUri(), wire);
+
+        }
     }
 }

Copied: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java (from r507339, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java?view=diff&rev=508732&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java&r1=507339&p2=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java Sat Feb 17 00:35:19 2007
@@ -25,12 +25,11 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import org.osoa.sca.NoRegisteredCallbackException;
-
 import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.spi.component.ReactivationException;
 import org.apache.tuscany.spi.component.SCAExternalizable;
@@ -39,12 +38,11 @@
 import static org.apache.tuscany.spi.model.InteractionScope.CONVERSATIONAL;
 import org.apache.tuscany.spi.model.Scope;
 import org.apache.tuscany.spi.model.ServiceContract;
-import org.apache.tuscany.spi.util.UriHelper;
-import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 import org.apache.tuscany.spi.wire.WireInvocationHandler;
 
 import org.apache.tuscany.core.wire.NoMethodForOperationException;
@@ -52,12 +50,11 @@
 
 
 /**
- * Receives a request from a proxy and performs an invocation on an {@link org.apache.tuscany.spi.wire.OutboundWire} via
- * an {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}
+ * Dispatches to a target through a wire.
  *
  * @version $Rev$ $Date$
  */
-public final class JDKOutboundInvocationHandler extends AbstractOutboundInvocationHandler
+public final class JDKInvocationHandler extends AbstractInvocationHandler
     implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
     private static final long serialVersionUID = -6155278451964527325L;
 
@@ -68,37 +65,39 @@
      * to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
      * is not cacheable, the master associated with the wire chains will be used.
      */
-    private transient Map<Method, OutboundChainHolder> chains;
+    private transient Map<Method, ChainHolder> chains;
     private transient WorkContext workContext;
-    private transient URI fromAddress;
-    private transient boolean wireContainerIsAtomicComponent;
+    //private transient URI fromAddress;
+    //private transient boolean wireContainerIsAtomicComponent;
     private transient boolean contractHasCallback;
-    private transient boolean callbackIsImplemented;
-    private transient String callbackClassName;
+    //private transient boolean callbackIsImplemented;
+    //private transient String callbackClassName;
     private transient boolean contractIsRemotable;
     private transient boolean contractIsConversational;
     private transient String convIdForRemotableTarget;
     private transient String convIdFromThread;
+    private transient Wire wire;
     private String referenceName;
     private Class<?> interfaze;
 
     /**
      * Constructor used for deserialization only
      */
-    public JDKOutboundInvocationHandler() {
+    public JDKInvocationHandler() {
     }
 
-    public JDKOutboundInvocationHandler(Class<?> interfaze, OutboundWire wire, WorkContext workContext)
+    public JDKInvocationHandler(Class<?> interfaze, Wire wire, WorkContext workContext)
         throws NoMethodForOperationException {
         this.workContext = workContext;
         this.interfaze = interfaze;
+        this.wire = wire;
         init(interfaze, wire, null);
     }
 
-    public JDKOutboundInvocationHandler(Class<?> interfaze,
-                                        OutboundWire wire,
-                                        Map<Method, OutboundChainHolder> mapping,
-                                        WorkContext workContext)
+    public JDKInvocationHandler(Class<?> interfaze,
+                                Wire wire,
+                                Map<Method, ChainHolder> mapping,
+                                WorkContext workContext)
         throws NoMethodForOperationException {
         this.workContext = workContext;
         this.interfaze = interfaze;
@@ -106,7 +105,7 @@
     }
 
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        OutboundChainHolder holder = chains.get(method);
+        ChainHolder holder = chains.get(method);
         if (holder == null) {
             if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) {
                 return "[Proxy - " + Integer.toHexString(hashCode()) + "]";
@@ -121,7 +120,7 @@
             }
             throw new TargetInvocationException("Operation not configured", method.getName());
         }
-        OutboundInvocationChain chain = holder.getChain();
+        InvocationChain chain = holder.getChain();
         TargetInvoker invoker;
 
         if (holder.getCachedInvoker() == null) {
@@ -141,14 +140,13 @@
             assert chain != null;
             invoker = chain.getTargetInvoker();
         }
-
-        if (wireContainerIsAtomicComponent && contractHasCallback && !callbackIsImplemented) {
-            throw new NoRegisteredCallbackException("Instance is does not implement callback: "
-                + callbackClassName);
-        }
+// JFM commonting out temporarily
+//        if (wireContainerIsAtomicComponent && contractHasCallback && !callbackIsImplemented) {
+//            throw new NoRegisteredCallbackException("Instance is does not implement callback: "
+//                + callbackClassName);
+//        }
 
         if (contractIsConversational) {
-            assert workContext != null : "Work context cannot be null for conversational invocation";
             // Check for a conv id on thread and remember it
             convIdFromThread = (String) workContext.getIdentifier(Scope.CONVERSATION);
             if (contractIsRemotable) {
@@ -162,12 +160,27 @@
                 workContext.setIdentifier(Scope.CONVERSATION, newConvId);
             }
         }
+        LinkedList<URI> list = null;
+        if (contractHasCallback) {
+            list = workContext.getCurrentCallbackUris();
+            if (list == null) {
+                list = new LinkedList<URI>();
+                workContext.setCurrentCallbackUris(list);
+            }
+            list.add(wire.getSourceUri());
+        }
 
-        Object result = invoke(chain, invoker, args, null, null);
+        Object result = invoke(chain, invoker, args, null, list);
         if (contractIsConversational && contractIsRemotable) {
             // Make sure we restore the remembered conv id to continue propagating
             workContext.setIdentifier(Scope.CONVERSATION, convIdFromThread);
         }
+        if (contractHasCallback) {
+            list = workContext.getCurrentCallbackUris();
+            if (list != null) {
+                list.removeLast();
+            }
+        }
         return result;
     }
 
@@ -175,10 +188,6 @@
         return invoke(null, method, args);
     }
 
-    protected URI getFromAddress() {
-        return contractHasCallback ? fromAddress : null;
-    }
-
     public void setWorkContext(WorkContext context) {
         workContext = context;
     }
@@ -198,12 +207,12 @@
         if (owner == null) {
             throw new ReactivationException("Current atomic component not set on work context");
         }
-        List<OutboundWire> wires = owner.getOutboundWires().get(referenceName);
+        List<Wire> wires = owner.getWires(referenceName);
         if (wires == null) {
             throw new ReactivationException("Reference wire not found", referenceName, owner.getUri().toString());
         }
         // TODO handle multiplicity
-        OutboundWire wire = wires.get(0);
+        Wire wire = wires.get(0);
         try {
             init(interfaze, wire, null);
         } catch (NoMethodForOperationException e) {
@@ -211,20 +220,13 @@
         }
     }
 
-    private void init(Class<?> interfaze, OutboundWire wire, Map<Method, OutboundChainHolder> mapping)
+    private void init(Class<?> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
         throws NoMethodForOperationException {
-        ServiceContract contract = wire.getServiceContract();
+        ServiceContract contract = wire.getSourceContract();
         this.referenceName = wire.getSourceUri().getFragment();
-        // TODO JFM remove getContainer
-        this.fromAddress = UriHelper.getDefragmentedName(wire.getSourceUri());
-        this.contractIsConversational = contract.getInteractionScope().equals(CONVERSATIONAL);
+        this.contractIsConversational = CONVERSATIONAL.equals(contract.getInteractionScope());
         this.contractIsRemotable = contract.isRemotable();
         this.contractHasCallback = contract.getCallbackClass() != null;
-        if (contractHasCallback) {
-            this.callbackClassName = contract.getCallbackClass().getName();
-        } else {
-            this.callbackClassName = null;
-        }
         // FIXME JFM this should not be dependent on PojoAtomicComponent
         // JFM commenting out as this should not be specific to pojo types
 //        this.wireContainerIsAtomicComponent = scaObject instanceof PojoAtomicComponent;

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java Sat Feb 17 00:35:19 2007
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import java.util.List;
 import java.util.Map;
 
 import org.osoa.sca.annotations.Constructor;
@@ -28,12 +29,9 @@
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.ChainHolder;
 import org.apache.tuscany.spi.wire.ProxyCreationException;
 import org.apache.tuscany.spi.wire.Wire;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
 
 import org.apache.tuscany.core.wire.WireServiceExtension;
 
@@ -57,58 +55,25 @@
     public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
         assert interfaze != null;
         assert wire != null;
-        if (wire instanceof InboundWire) {
-            InboundWire inbound = (InboundWire) wire;
-            JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(interfaze, inbound, context);
-            ClassLoader cl = interfaze.getClassLoader();
-            return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
-        } else if (wire instanceof OutboundWire) {
-            OutboundWire outbound = (OutboundWire) wire;
-            JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(interfaze, outbound, context);
-            ClassLoader cl = interfaze.getClassLoader();
-            return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
-        } else {
-            throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
-        }
+        JDKInvocationHandler handler = new JDKInvocationHandler(interfaze, wire, context);
+        ClassLoader cl = interfaze.getClassLoader();
+        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
     }
 
-    public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, OutboundChainHolder> mapping)
+    public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
         throws ProxyCreationException {
         assert interfaze != null;
         assert wire != null;
         assert mapping != null;
-        if (wire instanceof InboundWire) {
-            InboundWire inbound = (InboundWire) wire;
-            JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(interfaze, inbound, context);
-            ClassLoader cl = interfaze.getClassLoader();
-            return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
-        } else if (wire instanceof OutboundWire) {
-            OutboundWire outbound = (OutboundWire) wire;
-            JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(interfaze, outbound, context);
-            ClassLoader cl = interfaze.getClassLoader();
-            return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
-        } else {
-            throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
-        }
-    }
-
-    public Object createCallbackProxy(Class<?> interfaze, InboundWire wire) throws ProxyCreationException {
+        JDKInvocationHandler handler = new JDKInvocationHandler(interfaze, wire, context);
         ClassLoader cl = interfaze.getClassLoader();
-        JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, context);
         return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
     }
 
-    public WireInvocationHandler createHandler(Class<?> interfaze, Wire wire) {
-        assert wire != null;
-        if (wire instanceof InboundWire) {
-            InboundWire inbound = (InboundWire) wire;
-            return new JDKInboundInvocationHandler(interfaze, inbound, context);
-        } else if (wire instanceof OutboundWire) {
-            OutboundWire outbound = (OutboundWire) wire;
-            return new JDKOutboundInvocationHandler(interfaze, outbound, context);
-        } else {
-            throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
-        }
+    public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
+        ClassLoader cl = interfaze.getClassLoader();
+        JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, context);
+        return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
     }
 
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java Sat Feb 17 00:35:19 2007
@@ -19,9 +19,9 @@
 package org.apache.tuscany.core.binding.local;
 
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.TargetInvoker;
 
 import junit.framework.TestCase;
@@ -48,7 +48,7 @@
             }
         });
         EasyMock.replay(interceptor);
-        OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class);
+        InvocationChain chain = EasyMock.createMock(InvocationChain.class);
         EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor);
         EasyMock.replay(chain);
         invoker.invoke(chain, EasyMock.createNiceMock(TargetInvoker.class), new MessageImpl());
@@ -61,7 +61,7 @@
         TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
         EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
         EasyMock.replay(targetInvoker);
-        OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class);
+        InvocationChain chain = EasyMock.createMock(InvocationChain.class);
         EasyMock.expect(chain.getHeadInterceptor()).andReturn(null);
         EasyMock.replay(chain);
         invoker.invoke(chain, targetInvoker, new MessageImpl());

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java Sat Feb 17 00:35:19 2007
@@ -1,62 +1,41 @@
 package org.apache.tuscany.core.binding.local;
 
 import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
 
 import junit.framework.TestCase;
-import org.easymock.EasyMock;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
 
 /**
  * @version $Rev$ $Date$
  */
 public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase {
-    private InboundWire wire;
-    private Message message;
-    private OutboundInvocationChain chain;
-    private LocalCallbackTargetInvoker invoker;
 
     /**
      * Verfies an InvocationTargetException thrown when invoking the target is propagated to the client correctly and
      * the originating error is unwrapped
      */
     public void testThrowableTargetInvocation() throws Exception {
-        Message response = invoker.invoke(message);
+        Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+        Interceptor head = new ErrorInterceptor();
+        InvocationChain chain = new InvocationChainImpl(operation);
+        chain.addInterceptor(head);
+        Wire wire = new WireImpl();
+        wire.addCallbackInvocationChain(operation, chain);
+        LocalCallbackTargetInvoker invoker = new LocalCallbackTargetInvoker(operation, wire);
+        Message msg = new MessageImpl();
+        msg.setBody("foo");
+        Message response = invoker.invoke(msg);
         assertTrue(response.isFault());
         Object body = response.getBody();
         assertTrue(SomeException.class.equals(body.getClass()));
-        EasyMock.verify(wire);
-        EasyMock.verify(chain);
-    }
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        URI targetAddress = URI.create("from");
-        message = new MessageImpl();
-        message.pushFromAddress(targetAddress);
-        message.setBody("foo");
-        Message response = new MessageImpl();
-        response.setBody("response");
-        Operation<Type> operation = new Operation<Type>("echo", null, null, null);
-        Interceptor head = new ErrorInterceptor();
-        chain = EasyMock.createMock(OutboundInvocationChain.class);
-        EasyMock.expect(chain.getTargetInvoker()).andReturn(null);
-        EasyMock.expect(chain.getHeadInterceptor()).andReturn(head);
-        EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
-        chains.put(operation, chain);
-        wire = EasyMock.createMock(InboundWire.class);
-        EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains);
-        EasyMock.replay(wire);
-        invoker = new LocalCallbackTargetInvoker(operation, wire);
     }
 
     private class SomeException extends Exception {

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java Sat Feb 17 00:35:19 2007
@@ -19,16 +19,16 @@
 package org.apache.tuscany.core.binding.local;
 
 import java.lang.reflect.Type;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
-import java.net.URI;
 
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
 
 import junit.framework.TestCase;
 import org.easymock.EasyMock;
@@ -37,9 +37,9 @@
  * @version $Rev$ $Date$
  */
 public class LocalCallbackTargetInvokerTestCase extends TestCase {
-    private InboundWire wire;
+    private Wire wire;
     private Message message;
-    private OutboundInvocationChain chain;
+    private InvocationChain chain;
     private Interceptor head;
     private LocalCallbackTargetInvoker invoker;
 
@@ -58,7 +58,7 @@
         super.setUp();
         URI targetAddress = URI.create("from");
         message = new MessageImpl();
-        message.pushFromAddress(targetAddress);
+        message.pushCallbackUri(targetAddress);
         message.setBody("foo");
         Message response = new MessageImpl();
         response.setBody("response");
@@ -66,14 +66,14 @@
         head = EasyMock.createMock(Interceptor.class);
         EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andReturn(response);
         EasyMock.replay(head);
-        chain = EasyMock.createMock(OutboundInvocationChain.class);
+        chain = EasyMock.createMock(InvocationChain.class);
         EasyMock.expect(chain.getTargetInvoker()).andReturn(null);
         EasyMock.expect(chain.getHeadInterceptor()).andReturn(head);
         EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
+        Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
         chains.put(operation, chain);
-        wire = EasyMock.createMock(InboundWire.class);
-        EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains);
+        wire = EasyMock.createMock(Wire.class);
+        EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(chains);
         EasyMock.replay(wire);
 
         invoker = new LocalCallbackTargetInvoker(operation, wire);

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java Sat Feb 17 00:35:19 2007
@@ -19,80 +19,70 @@
 package org.apache.tuscany.core.binding.local;
 
 import java.lang.reflect.Type;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.HashMap;
-import java.util.Map;
-import java.net.URI;
 
 import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
 
 import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
 
 /**
  * @version $Rev$ $Date$
  */
 public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase {
-    private InboundWire wire;
-    private Message message;
-    private OutboundInvocationChain chain;
-    private Interceptor head;
     private LocalCallbackTargetInvoker invoker;
 
     /**
      * Verfies an exception thrown in the target is propagated to the client correctly
      */
     public void testThrowableTargetInvocation() throws Exception {
+        Message message = new MessageImpl();
+        message.setBody("foo");
         Message response = invoker.invoke(message);
         assertTrue(response.isFault());
         Object body = response.getBody();
-        if (!(body instanceof UndeclaredThrowableException)) {
-            fail(); // EasyMock wraps the Throwable in an UndeclaredThrowableException
+        if (!(body instanceof InsidiousException)) {
+            fail();
         }
-        UndeclaredThrowableException e = (UndeclaredThrowableException) body;
-        assertTrue(InsidiousException.class.equals(e.getUndeclaredThrowable().getClass()));
-        EasyMock.verify(wire);
-        EasyMock.verify(chain);
-        EasyMock.verify(head);
     }
 
     @SuppressWarnings("unchecked")
     protected void setUp() throws Exception {
         super.setUp();
-        URI targetAddress = URI.create("from");
-        message = new MessageImpl();
-        message.pushFromAddress(targetAddress);
-        message.setBody("foo");
-        Message response = new MessageImpl();
-        response.setBody("response");
         Operation<Type> operation = new Operation<Type>("echo", null, null, null);
-        head = EasyMock.createMock(Interceptor.class);
-        EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andStubAnswer(new IAnswer() {
-            public Object answer() throws Throwable {
-                throw new InsidiousException();   // andThrow() does not seem to work here
-            }
-        });
-        EasyMock.replay(head);
-        chain = EasyMock.createMock(OutboundInvocationChain.class);
-        EasyMock.expect(chain.getTargetInvoker()).andReturn(null);
-        EasyMock.expect(chain.getHeadInterceptor()).andReturn(head);
-        EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
-        chains.put(operation, chain);
-        wire = EasyMock.createMock(InboundWire.class);
-        EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains);
-        EasyMock.replay(wire);
+        InvocationChain chain = new InvocationChainImpl(operation);
+        chain.addInterceptor(new InsidiuousInterceptor());
+        Wire wire = new WireImpl();
+        wire.addCallbackInvocationChain(operation, chain);
         invoker = new LocalCallbackTargetInvoker(operation, wire);
     }
 
-    private class InsidiousException extends Throwable {
+    private class InsidiousException extends RuntimeException {
+
+    }
+
+    private class InsidiuousInterceptor implements Interceptor {
+
+        public Message invoke(Message msg) throws InsidiousException {
+            throw new InsidiousException();
+        }
 
+        public void setNext(Interceptor next) {
+
+        }
+
+        public Interceptor getNext() {
+            return null;
+        }
+
+        public boolean isOptimizable() {
+            return false;
+        }
     }
 
 

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java Sat Feb 17 00:35:19 2007
@@ -19,18 +19,18 @@
 package org.apache.tuscany.core.binding.local;
 
 import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.tuscany.spi.model.Operation;
 import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
 
 import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
 import org.easymock.EasyMock;
 
 /**
@@ -44,16 +44,11 @@
         TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
         EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
         EasyMock.replay(targetInvoker);
-        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
-        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
-        EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
-        chains.put(operation, chain);
-        OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class);
-        wire.getOutboundInvocationChains();
-        EasyMock.expectLastCall().andReturn(chains);
-        EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract);
-        EasyMock.replay(wire);
+        InvocationChain chain = new InvocationChainImpl(operation);
+        chain.setTargetInvoker(targetInvoker);
+        Wire wire = new WireImpl();
+        wire.addInvocationChain(operation, chain);
+        wire.setSourceContract(serviceContract);
         TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
         Message msg = invoker.invoke(new MessageImpl());
         assertFalse(msg.isFault());
@@ -68,21 +63,20 @@
         TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
         EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
         EasyMock.replay(targetInvoker);
-        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
-        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
-        EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
-        chains.put(operation, chain);
-        OutboundWire wire = EasyMock.createMock(OutboundWire.class);
+
+        InvocationChain chain = new InvocationChainImpl(operation);
+        chain.setTargetInvoker(targetInvoker);
+        InvocationChain callbackChain = new InvocationChainImpl(operation);
+        Wire wire = new WireImpl();
+        wire.addInvocationChain(operation, chain);
+        wire.addCallbackInvocationChain(operation, callbackChain);
+        wire.setSourceContract(serviceContract);
         URI uri = URI.create("foo");
-        EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
-        wire.getOutboundInvocationChains();
-        EasyMock.expectLastCall().andReturn(chains);
-        EasyMock.expect(wire.getServiceContract()).andReturn(contract);
-        EasyMock.replay(wire);
+        wire.setSourceUri(uri);
+        wire.addInvocationChain(operation, chain);
         TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
         Message msg = EasyMock.createMock(Message.class);
-        msg.pushFromAddress(EasyMock.eq(uri));
+        msg.pushCallbackUri(EasyMock.eq(uri));
         EasyMock.replay(msg);
         invoker.invoke(msg);
         EasyMock.verify(msg);
@@ -93,16 +87,12 @@
         TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
         EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andThrow(new TestException());
         EasyMock.replay(targetInvoker);
-        OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class);
-        EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker);
-        EasyMock.replay(chain);
-        Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
-        chains.put(operation, chain);
-        OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class);
-        wire.getOutboundInvocationChains();
-        EasyMock.expectLastCall().andReturn(chains);
-        EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract);
-        EasyMock.replay(wire);
+
+        InvocationChain chain = new InvocationChainImpl(operation);
+        chain.setTargetInvoker(targetInvoker);
+        Wire wire = new WireImpl();
+        wire.setSourceContract(serviceContract);
+        wire.addInvocationChain(operation, chain);
         TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
         Message msg = invoker.invoke(new MessageImpl());
         assertTrue(msg.isFault());

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java Sat Feb 17 00:35:19 2007
@@ -19,91 +19,185 @@
 package org.apache.tuscany.core.builder;
 
 import java.net.URI;
-import java.util.List;
-import java.util.Map;
 
+import org.apache.tuscany.spi.builder.Connector;
 import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
 import org.apache.tuscany.spi.component.Service;
 import org.apache.tuscany.spi.component.ServiceBinding;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManager;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
 import org.apache.tuscany.core.implementation.composite.ServiceImpl;
-import org.apache.tuscany.core.mock.binding.MockServiceBinding;
-import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.InboundWireImpl;
-import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.OutboundWireImpl;
 import org.easymock.EasyMock;
 
 /**
  * @version $Rev$ $Date$
  */
-public class AtomicConnectorTestCase extends AbstractConnectorImplTestCase {
-
-    public void testConnectSynchronousServiceWiresToAtomicTarget() throws Exception {
-        AtomicComponent target = createAtomicTarget();
-        componentManager.register(target);
-        // create the parent composite
-
-        URI sourceUri = URI.create("source");
-        InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
-        InboundWire inboundWire = new InboundWireImpl();
-        inboundWire.setSourceUri(sourceUri);
-        inboundWire.addInboundInvocationChain(operation, inboundChain);
-        inboundWire.setServiceContract(contract);
-
-        OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
-        OutboundWire outboundWire = new OutboundWireImpl();
-        outboundWire.setSourceUri(sourceUri);
-        outboundWire.setTargetUri(TARGET_NAME);
-        outboundWire.addOutboundInvocationChain(operation, outboundChain);
-        outboundWire.setServiceContract(contract);
-
-        // create the binding
-        ServiceBinding binding = new MockServiceBinding(sourceUri);
-        binding.setOutboundWire(outboundWire);
-        binding.setInboundWire(inboundWire);
+public class AtomicConnectorTestCase extends TestCase {
+    private static final URI PARENT = URI.create("parent");
+    private static final URI SOURCE = URI.create("source");
+    private static final URI TARGET = URI.create("parent#target");
+    private static final URI TARGET_NOFRAGMENT = URI.create("target");
+    private static final URI REFERENCE_NAME = URI.create("#ref");
+    private ComponentManager manager;
+    private Connector connector;
+    private ServiceContract<?> contract;
 
-        Service service = new ServiceImpl(sourceUri, null);
-        service.addServiceBinding(binding);
+    /**
+     * Verifies connecting a wire from an atomic component to a target atomic component
+     */
+    @SuppressWarnings({"unchecked"})
+    public void testConnectToAtomic() throws Exception {
+        AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+        EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+        EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+        source.attachWire(EasyMock.isA(Wire.class));
+        EasyMock.replay(source);
+        manager.register(source);
+
+        AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+        EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+        EasyMock.expect(target.isOptimizable()).andReturn(false);
+        EasyMock.expect(target.getUri()).andReturn(TARGET_NOFRAGMENT).atLeastOnce();
+        target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(target);
+        manager.register(target);
+
+        Implementation impl = new Implementation() {
+        };
+        ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+            new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+        ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+        type.add(referenceDefinition);
+        impl.setComponentType(type);
+
+        ComponentDefinition<?> definition = new ComponentDefinition(impl);
+        definition.setUri(SOURCE);
+        ReferenceTarget referenceTarget = new ReferenceTarget();
+        referenceTarget.setReferenceName(REFERENCE_NAME);
+        referenceTarget.addTarget(TARGET_NOFRAGMENT);
+        definition.add(referenceTarget);
+
+        connector.connect(definition);
+        EasyMock.verify(source);
+        EasyMock.verify(target);
+    }
 
-        connector.connect(service);
-        MessageImpl msg = new MessageImpl();
-        msg.setTargetInvoker(inboundChain.getTargetInvoker());
-        Message resp = inboundChain.getHeadInterceptor().invoke(msg);
-        assertEquals(RESPONSE, resp.getBody());
+    @SuppressWarnings({"unchecked"})
+    public void testConnectToReference() throws Exception {
+        AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+        EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+        source.attachWire(EasyMock.isA(Wire.class));
+        EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+        EasyMock.replay(source);
+        manager.register(source);
+
+        ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+        EasyMock.expect(binding.getUri()).andReturn(TARGET).atLeastOnce();
+        binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(binding);
+
+        Reference reference = new ReferenceImpl(TARGET, contract);
+        reference.addReferenceBinding(binding);
+
+        CompositeComponent component = new CompositeComponentImpl(PARENT);
+        component.register(reference);
+        manager.register(component);
+
+        Implementation impl = new Implementation() {
+        };
+        ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+            new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+        ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+        type.add(referenceDefinition);
+        impl.setComponentType(type);
+
+        ComponentDefinition<?> definition = new ComponentDefinition(impl);
+        definition.setUri(SOURCE);
+        ReferenceTarget referenceTarget = new ReferenceTarget();
+        referenceTarget.setReferenceName(REFERENCE_NAME);
+        referenceTarget.addTarget(TARGET);
+        definition.add(referenceTarget);
+
+        connector.connect(definition);
+        EasyMock.verify(source);
+        EasyMock.verify(binding);
     }
 
-    /**
-     * Verifies connecting a wire from an atomic component to a target atomic component with one synchronous operation
-     */
-    public void testConnectAtomicComponentToAtomicComponentSyncWire() throws Exception {
+    @SuppressWarnings({"unchecked"})
+    public void testConnectToService() throws Exception {
+        AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+        EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+        EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+        source.attachWire(EasyMock.isA(Wire.class));
+        EasyMock.replay(source);
+        manager.register(source);
+
+        ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+        EasyMock.expect(binding.getUri()).andReturn(TARGET).atLeastOnce();
+        binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(binding);
+
+        Service service = new ServiceImpl(TARGET, contract);
+        service.addServiceBinding(binding);
 
-        AtomicComponent target = createAtomicTarget();
-        componentManager.register(target);
-        // create the parent composite
-        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
-        EasyMock.replay(parent);
-        AtomicComponent source = createAtomicSource(parent);
-        connector.connect(source);
-
-        MessageImpl msg = new MessageImpl();
-        Map<String, List<OutboundWire>> wires = source.getOutboundWires();
-        OutboundWire wire = wires.get(TARGET_FRAGMENT).get(0);
-        OutboundInvocationChain chain = wire.getOutboundInvocationChains().get(operation);
-        msg.setTargetInvoker(chain.getTargetInvoker());
-        Message resp = chain.getHeadInterceptor().invoke(msg);
-        assertEquals(RESPONSE, resp.getBody());
+        CompositeComponent component = new CompositeComponentImpl(PARENT);
+        component.register(service);
+        manager.register(component);
+
+        Implementation impl = new Implementation() {
+        };
+        ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+            new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+        ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+        type.add(referenceDefinition);
+        impl.setComponentType(type);
+
+        ComponentDefinition<?> definition = new ComponentDefinition(impl);
+        definition.setUri(SOURCE);
+        ReferenceTarget referenceTarget = new ReferenceTarget();
+        referenceTarget.setReferenceName(REFERENCE_NAME);
+        referenceTarget.addTarget(TARGET);
+        definition.add(referenceTarget);
+
+        connector.connect(definition);
+        EasyMock.verify(source);
+        EasyMock.verify(binding);
     }
 
     protected void setUp() throws Exception {
         super.setUp();
+        manager = new ComponentManagerImpl();
+        connector = new ConnectorImpl(null, manager, null, null);
+        JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+        contract = registry.introspect(Foo.class);
+    }
+
+
+    private interface Foo {
+        void bar();
     }
 
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java?view=diff&rev=508732&r1=508731&r2=508732
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java Sat Feb 17 00:35:19 2007
@@ -71,7 +71,7 @@
         deploymentContext = new RootDeploymentContext(null, null, null, null);
         parent = EasyMock.createNiceMock(CompositeComponent.class);
         EasyMock.replay(parent);
-        registry = new BuilderRegistryImpl(null, null, null);
+        registry = new BuilderRegistryImpl(null, null);
         registry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
     }
 



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