You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/08/18 04:08:39 UTC

svn commit: r567203 [2/2] - in /incubator/tuscany/java/sca: itest/contribution-import-export/import-composite/src/test/java/helloworld/ itest/references/src/test/java/org/apache/tuscany/sca/itest/references/ modules/assembly-xml/src/test/java/org/apach...

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java Fri Aug 17 19:08:36 2007
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.core.runtime;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -33,9 +34,13 @@
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.assembly.WireableBinding;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.component.ComponentContextImpl;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.provider.BindingProviderFactory;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
@@ -51,6 +56,7 @@
 import org.apache.tuscany.sca.scope.ScopeRegistry;
 import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
 import org.apache.tuscany.sca.work.WorkScheduler;
+import org.osoa.sca.ComponentContext;
 
 /**
  * @version $Rev$ $Date$
@@ -59,12 +65,16 @@
 
     private final static String CALLBACK_PREFIX = "$callback$.";
 
+    private final AssemblyFactory assemblyFactory;
     private final InterfaceContractMapper interfaceContractMapper;
     private final ScopeRegistry scopeRegistry;
     private final WorkScheduler workScheduler;
     private final RuntimeWireProcessor wireProcessor;
     private final ProviderFactoryExtensionPoint providerFactories;
 
+    private final RequestContextFactory requestContextFactory;
+    private final ProxyFactory proxyFactory;
+    private final JavaInterfaceFactory javaInterfaceFactory;
     /**
      * @param assemblyFactory
      * @param interfaceContractMapper
@@ -73,17 +83,24 @@
      * @param wirePostProcessorRegistry
      */
     public CompositeActivatorImpl(AssemblyFactory assemblyFactory,
+                                  JavaInterfaceFactory javaInterfaceFactory,
                                   SCABindingFactory scaBindingFactory,
                                   InterfaceContractMapper interfaceContractMapper,
                                   ScopeRegistry scopeRegistry,
                                   WorkScheduler workScheduler,
                                   RuntimeWireProcessor wireProcessor,
+                                  RequestContextFactory requestContextFactory,
+                                  ProxyFactory proxyFactory,
                                   ProviderFactoryExtensionPoint providerFactories) {
+        this.assemblyFactory = assemblyFactory;
         this.interfaceContractMapper = interfaceContractMapper;
         this.scopeRegistry = scopeRegistry;
         this.workScheduler = workScheduler;
         this.wireProcessor = wireProcessor;
         this.providerFactories = providerFactories;
+        this.javaInterfaceFactory = javaInterfaceFactory;
+        this.requestContextFactory = requestContextFactory;
+        this.proxyFactory = proxyFactory;
     }
 
     /**
@@ -100,11 +117,14 @@
                     .getBindings());
             }
 
+            // [rfeng] Defer this
+            /*
             for (ComponentReference reference : component.getReferences()) {
                 addReferenceBindingProviders((RuntimeComponent)component,
                                                 (RuntimeComponentReference)reference,
                                                 reference.getBindings());
             }
+            */
 
             Implementation implementation = component.getImplementation();
             if (implementation instanceof Composite) {
@@ -146,6 +166,228 @@
         }
     }
 
+    /**
+     * @param ref
+     */
+    public void activate(RuntimeComponent component, RuntimeComponentReference ref) {
+        addReferenceBindingProviders(component, ref, ref.getBindings());
+        for (Binding binding : ref.getBindings()) {
+            addReferenceWire(component, ref, binding);
+            ReferenceBindingProvider provider = ref.getBindingProvider(binding);
+            if (provider != null) {
+                provider.start();
+            }
+        }
+    }
+
+    private void addReferenceBindingProviders(RuntimeComponent component,
+                                              RuntimeComponentReference reference,
+                                              List<Binding> bindings) {
+    
+        List<Binding> unresolvedTargetBindings = new ArrayList<Binding>();
+    
+        // create binding providers for all of the bindings for resolved targets
+        // or for all of the bindings where no targets are specified
+        for (Binding binding : bindings) {
+            BindingProviderFactory providerFactory =
+                (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass());
+            if (providerFactory != null) {
+                @SuppressWarnings("unchecked")
+                ReferenceBindingProvider bindingProvider =
+                    providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
+                                                                   (RuntimeComponentReference)reference,
+                                                                   binding);
+                if (bindingProvider != null) {
+                    ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider);
+                }
+            } else {
+                throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName());
+            }
+        }
+    
+        // Support for distributed domain follows
+    
+        // go over any targets that have not been resolved yet (as they are running on other nodes)
+        // and try an resolve them remotely
+        // TODO - this should work for any kind of wired binding but the only wireable binding 
+        //        is currently the SCA binding so we assume that
+        for (ComponentService service : reference.getTargets()) {
+            if (service.isUnresolved()) {
+                for (Binding binding : service.getBindings()) {
+                    // TODO - we should look at all the bindings now associated with the 
+                    //        unresolved target but we assume the SCA binding here as
+                    //        its currently the only wireable one
+                    if (binding instanceof SCABinding) {
+                        SCABinding scaBinding = (SCABinding)binding;
+    
+                        BindingProviderFactory providerFactory =
+                            (BindingProviderFactory)providerFactories.getProviderFactory(SCABinding.class);
+    
+                        if (providerFactory == null) {
+                            throw new IllegalStateException("Provider factory not found for class: " + scaBinding
+                                .getClass().getName());
+                        }
+    
+                        // clone the SCA binding and fill in service details 
+                        SCABinding clonedSCABinding = null;
+                        try {
+                            clonedSCABinding = (SCABinding)((WireableBinding)scaBinding).clone();
+                            clonedSCABinding.setURI(service.getName());
+                            ((WireableBinding)clonedSCABinding).setRemote(true);
+                        } catch (Exception e) {
+                            // warning("The binding doesn't support clone: " + binding.getClass().getSimpleName(), binding);
+                        }
+    
+                        @SuppressWarnings("unchecked")
+                        ReferenceBindingProvider bindingProvider =
+                            providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
+                                                                           (RuntimeComponentReference)reference,
+                                                                           clonedSCABinding);
+                        if (bindingProvider != null) {
+                            ((RuntimeComponentReference)reference)
+                                .setBindingProvider(clonedSCABinding, bindingProvider);
+    
+                            // add the cloned SCA binding to the reference as it will be used to look up the 
+                            // provider later
+                            reference.getBindings().remove(binding);
+                            reference.getBindings().add(clonedSCABinding);
+                        } else {
+                            throw new IllegalStateException(
+                                                            "No distributed SCA Binding implementation found for reference: " + reference
+                                                                .getName()
+                                                                + " and target: "
+                                                                + service.getName()
+                                                                + " or the referenced interface is not remoteable");
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Create the runtime wires for a reference binding
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     */
+    private void addReferenceWire(Component component, ComponentReference reference, Binding binding) {
+        if (!(reference instanceof RuntimeComponentReference)) {
+            return;
+        }
+    
+        // create wire if binding has an endpoint
+        Component targetComponent = null;
+        ComponentService targetComponentService = null;
+        Binding targetBinding = null;
+        if (binding instanceof WireableBinding) {
+            WireableBinding endpoint = (WireableBinding)binding;
+            targetComponent = endpoint.getTargetComponent();
+            targetComponentService = endpoint.getTargetComponentService();
+            targetBinding = endpoint.getTargetBinding();
+        }
+    
+        // create a forward wire, either static or dynamic
+        addReferenceWire(component, reference, binding, targetComponent, targetComponentService, targetBinding);
+    
+        /*
+        // if static forward wire (not from self-reference), try to create a static callback wire 
+        if (targetComponentService != null && !reference.getName().startsWith("$self$.")) {
+            ComponentReference callbackReference = targetComponentService.getCallbackReference();
+            if (callbackReference != null) {
+                Binding callbackBinding = null;
+                Binding callbackServiceBinding = null;
+                // select a service callback binding that can be wired back to this component
+                for (Binding refBinding : callbackReference.getBindings()) {
+                    // first look for a callback binding whose name matches the target binding name
+                    if (refBinding.getName().equals(targetBinding.getName())) {
+                        callbackBinding = refBinding;
+                        break;
+                    }
+                }
+                // see if there is a matching reference callback binding 
+                if (callbackBinding != null) {
+                    callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
+                }
+                // if there isn't an end-to-end match, try again based on target binding type
+                if (callbackBinding == null || callbackServiceBinding == null) {
+                    callbackBinding = callbackReference.getBinding(targetBinding.getClass());
+                    if (callbackBinding != null) {
+                        callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
+                    }
+                }
+                if (callbackBinding != null && callbackServiceBinding != null) {
+                    // end-to-end match, so create a static callback wire as well as the static forward wire
+    
+                    addReferenceWire(targetComponent, callbackReference, callbackBinding, component, reference
+                        .getCallbackService(), callbackServiceBinding);
+                } else {
+                    // no end-to-end match, so do not create a static callback wire
+                }
+            }
+        }
+        */
+    }
+
+    /**
+     * Create a reference wire for a forward call or a callback
+     * @param reference
+     * @param service
+     * @param serviceBinding
+     * @param component
+     * @param referenceBinding
+     */
+    private RuntimeWire addReferenceWire(Component refComponent,
+                                         ComponentReference reference,
+                                         Binding refBinding,
+                                         Component serviceComponent,
+                                         ComponentService service,
+                                         Binding serviceBinding) {
+        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+        InterfaceContract bindingContract = getInterfaceContract(reference, refBinding);
+    
+        // Use the interface contract of the reference on the component type
+        Reference componentTypeRef = reference.getReference();
+        InterfaceContract sourceContract =
+            componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
+        sourceContract = sourceContract.makeUnidirectional(false);
+    
+        EndpointReference wireSource =
+            new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
+        ComponentService callbackService = reference.getCallbackService();
+        if (callbackService != null) {
+            // select a reference callback binding to pass with invocations on this wire
+            Binding callbackBinding = null;
+            for (Binding binding : callbackService.getBindings()) {
+                // first look for a callback binding whose name matches the reference binding name
+                if (binding.getName().equals(refBinding.getName()) || binding.getName()
+                    .equals(CALLBACK_PREFIX + refBinding.getName())) {
+                    callbackBinding = binding;
+                    break;
+                }
+            }
+            // if no callback binding found, try again based on reference binding type
+            if (callbackBinding == null) {
+                callbackBinding = callbackService.getBinding(refBinding.getClass());
+            }
+            InterfaceContract callbackContract = callbackService.getInterfaceContract();
+            EndpointReference callbackEndpoint =
+                new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
+                                          callbackContract);
+            wireSource.setCallbackEndpoint(callbackEndpoint);
+        }
+    
+        EndpointReference wireTarget =
+            new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract);
+    
+        RuntimeWire wire =
+            new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor);
+        runtimeRef.getRuntimeWires().add(wire);
+    
+        return wire;
+    }
+
     private void addImplementationProvider(RuntimeComponent component, Implementation implementation) {
         ImplementationProviderFactory providerFactory =
             (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass());
@@ -206,7 +448,7 @@
                     // clone the SCA binding and fill in service details 
                     try {
                         clonedSCABinding = (SCABinding)((WireableBinding)scaBinding).clone();
-                        ((WireableBinding)clonedSCABinding).setIsRemote(true);
+                        ((WireableBinding)clonedSCABinding).setRemote(true);
                     } catch (Exception e) {
                         // warning("The binding doesn't support clone: " + binding.getClass().getSimpleName(), binding);
                     }  
@@ -223,12 +465,14 @@
                     throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName());
                 }
             }
+            // add the cloned SCA binding to the service as it will be used to look up the provider later
+            if (clonedSCABinding != null){
+                service.getBindings().remove(binding);
+                service.getBindings().add(clonedSCABinding);            
+            }
         }
         
-        // add the cloned SCA binding to the service as it will be used to look up the provider later
-        if (clonedSCABinding != null){
-            service.getBindings().add(clonedSCABinding);            
-        }
+
     }
 
     private void removeServiceBindingProviders(RuntimeComponent component,
@@ -239,85 +483,6 @@
           }
       }
 
-    private void addReferenceBindingProviders(RuntimeComponent component,
-                                                 RuntimeComponentReference reference,
-                                                 List<Binding> bindings) {
-        
-        // create binding providers for all of the bindings for resolved targets
-        // or for all of the bindings where no targets are specified
-        for (Binding binding : bindings) {
-            BindingProviderFactory providerFactory =
-                (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass());
-            if (providerFactory != null) {
-                @SuppressWarnings("unchecked")
-                ReferenceBindingProvider bindingProvider =
-                    providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
-                                                                   (RuntimeComponentReference)reference,
-                                                                   binding);
-                if (bindingProvider != null) {
-                    ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider);
-                }
-            } else {
-                throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName());
-            }
-        }
-        
-        // Support for distributed domain follows
-        
-        // go over any targets that have not been resolved yet (as they are running on other nodes)
-        // and try an resolve them remotely
-        // TODO - this should work for any kind of wired binding but the only wireable binding 
-        //        is currently the SCA binding so we assume that
-        for ( ComponentService service : reference.getTargets()){
-            if ( service.isUnresolved()){
-                for (Binding binding : service.getBindings()) {
-                    // TODO - we should look at all the bindings now associated with the 
-                    //        unresolved target but we assume the SCA binding here as
-                    //        its currently the only wireable one
-                    if (binding instanceof SCABinding) {
-                        SCABinding scaBinding = (SCABinding)binding;
-                
-                        BindingProviderFactory providerFactory =
-                            (BindingProviderFactory)providerFactories.getProviderFactory(SCABinding.class);
-                        
-                        if (providerFactory == null) {
-                            throw new IllegalStateException("Provider factory not found for class: " + scaBinding.getClass().getName());
-                        }
-                        
-                        // clone the SCA binding and fill in service details 
-                        SCABinding clonedSCABinding = null;
-                        try {
-                            clonedSCABinding = (SCABinding)((WireableBinding)scaBinding).clone();
-                            clonedSCABinding.setURI(service.getName());
-                            ((WireableBinding)clonedSCABinding).setIsRemote(true);
-                        } catch (Exception e) {
-                            // warning("The binding doesn't support clone: " + binding.getClass().getSimpleName(), binding);
-                        }  
-
-                        @SuppressWarnings("unchecked")
-                        ReferenceBindingProvider bindingProvider =
-                            providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
-                                                                           (RuntimeComponentReference)reference,
-                                                                           clonedSCABinding);
-                        if (bindingProvider != null) {
-                            ((RuntimeComponentReference)reference).setBindingProvider(clonedSCABinding, bindingProvider);
-                            
-                            // add the cloned SCA binding to the reference as it will be used to look up the 
-                            // provider later
-                            reference.getBindings().add(clonedSCABinding);
-                        } else {
-                            throw new IllegalStateException("No distributed SCA Binding implementation found for reference: " +
-                                                            reference.getName() +
-                                                            " and target: " + 
-                                                            service.getName() + 
-                                                            " or the referenced interface is not remoteable");
-                        }
-                    }
-                }
-            }
-        }  
-    }
-
     private void removeReferenceBindingProviders(RuntimeComponent component,
                                                    RuntimeComponentReference reference,
                                                    List<Binding> bindings) {
@@ -341,6 +506,11 @@
     }
 
     public void start(Component component) {
+        RuntimeComponent runtimeComponent = ((RuntimeComponent)component);
+        ComponentContext componentContext =
+            new ComponentContextImpl(this, assemblyFactory, proxyFactory, interfaceContractMapper, requestContextFactory,
+                                     javaInterfaceFactory, runtimeComponent);
+        runtimeComponent.setComponentContext(componentContext);
 
         for (ComponentService service : component.getServices()) {
             for (Binding binding : service.getBindings()) {
@@ -353,44 +523,29 @@
 //                wireProcessor.process(wire);
 //            }
         }
+        
         for (ComponentReference reference : component.getReferences()) {
-            for (Binding binding : reference.getBindings()) {
-                ReferenceBindingProvider bindingProvider =
-                    ((RuntimeComponentReference)reference).getBindingProvider(binding);
-                if (bindingProvider != null) {
-                    try {
-                        bindingProvider.start();
-                    } catch (RuntimeException e) {
-                        // TODO: [rfeng] Ignore the self reference if a runtime exception happens
-                        if (!reference.getName().startsWith("$self$.")) {
-                            throw e;
-                        }
-                    }
-                }
-            }
-//            for (RuntimeWire wire : ((RuntimeComponentReference)reference).getRuntimeWires()) {
-//                wireProcessor.process(wire);
-//            }
+            ((RuntimeComponentReference) reference).setComponent(runtimeComponent);
         }
-
+        
         Implementation implementation = component.getImplementation();
         if (implementation instanceof Composite) {
             start((Composite)implementation);
         } else {
-            ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
+            ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
             if (implementationProvider != null) {
                 implementationProvider.start();
             }
         }
 
         if (component instanceof ScopedRuntimeComponent) {
-            ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
-            if (runtimeComponent.getScopeContainer() != null) {
-                runtimeComponent.getScopeContainer().start();
+            ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+            if (scopedRuntimeComponent.getScopeContainer() != null) {
+                scopedRuntimeComponent.getScopeContainer().start();
             }
         }
 
-        ((RuntimeComponent)component).setStarted(true);
+        runtimeComponent.setStarted(true);
     }
 
     /**
@@ -447,12 +602,14 @@
                 // Recursively create runtime wires
                 addRuntimeWires((Composite)implementation);
             } else {
+                /* [rfeng] Defer this
                 // Create outbound wires for the component references
                 for (ComponentReference reference : component.getReferences()) {
                     for (Binding binding : reference.getBindings()) {
                         addReferenceWire(component, reference, binding);
                     }
                 }
+                */
                 // Create inbound wires for the component services
                 for (ComponentService service : component.getServices()) {
                     for (Binding binding : service.getBindings()) {
@@ -508,81 +665,6 @@
     }
 
     /**
-     * Create the runtime wires for a reference binding
-     * 
-     * @param component
-     * @param reference
-     * @param binding
-     */
-    private void addReferenceWire(Component component, ComponentReference reference, Binding binding) {
-        if (!(reference instanceof RuntimeComponentReference)) {
-            return;
-        }
-        if (binding instanceof WireableBinding && binding.getURI() == null) {
-            return;
-        }
-
-        // create wire if binding has an endpoint
-        Component targetComponent = null;
-        ComponentService targetComponentService = null;
-        Binding targetBinding = null;
-        if (binding instanceof WireableBinding) {
-            WireableBinding endpoint = (WireableBinding)binding;
-            targetComponent = endpoint.getTargetComponent();
-            targetComponentService = endpoint.getTargetComponentService();
-            targetBinding = endpoint.getTargetBinding();
-        }
-
-        // create a forward wire, either static or dynamic
-        addReferenceWire(component,
-                         reference,
-                         binding,
-                         targetComponent,
-                         targetComponentService,
-                         targetBinding);
-
-        // if static forward wire (not from self-reference), try to create a static callback wire 
-        if (targetComponentService != null && !reference.getName().startsWith("$self$.")) {
-            ComponentReference callbackReference = targetComponentService.getCallbackReference();
-            if (callbackReference != null) {
-                Binding callbackBinding = null;
-                Binding callbackServiceBinding = null;
-                // select a service callback binding that can be wired back to this component
-                for (Binding refBinding : callbackReference.getBindings()) {
-                    // first look for a callback binding whose name matches the target binding name
-                    if (refBinding.getName().equals(targetBinding.getName())) {
-                        callbackBinding = refBinding;
-                        break;
-                    }
-                }
-                // see if there is a matching reference callback binding 
-                if (callbackBinding != null) {
-                    callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
-                }
-                // if there isn't an end-to-end match, try again based on target binding type
-                if (callbackBinding == null || callbackServiceBinding == null) {
-                    callbackBinding = callbackReference.getBinding(targetBinding.getClass());
-                    if (callbackBinding != null) {
-                        callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
-                    }
-                }
-                if (callbackBinding != null && callbackServiceBinding != null) {
-                    // end-to-end match, so create a static callback wire as well as the static forward wire
-
-                    addReferenceWire(targetComponent,
-                                     callbackReference,
-                                     callbackBinding,
-                                     component,
-                                     reference.getCallbackService(),
-                                     callbackServiceBinding);
-                } else {
-                    // no end-to-end match, so do not create a static callback wire
-                }
-            }
-        }
-    }
-
-    /**
      * Remove the runtime wires for a reference binding
      * @param reference
      */
@@ -592,61 +674,6 @@
         }
         RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
         runtimeRef.getRuntimeWires().clear();
-    }
-
-    /**
-     * Create a reference wire for a forward call or a callback
-     * @param reference
-     * @param service
-     * @param serviceBinding
-     * @param component
-     * @param referenceBinding
-     */
-    private RuntimeWire addReferenceWire(Component refComponent,
-                                         ComponentReference reference,
-                                         Binding refBinding,
-                                         Component serviceComponent,
-                                         ComponentService service,
-                                         Binding serviceBinding) {
-        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
-        InterfaceContract bindingContract = getInterfaceContract(reference, refBinding);
-    
-        // Use the interface contract of the reference on the component type
-        Reference componentTypeRef = reference.getReference();
-        InterfaceContract sourceContract =
-            componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
-        sourceContract = sourceContract.makeUnidirectional(false);
-
-        EndpointReference wireSource =
-            new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
-        ComponentService callbackService = reference.getCallbackService();
-        if (callbackService != null) {
-            // select a reference callback binding to pass with invocations on this wire
-            Binding callbackBinding = null;
-            for (Binding binding : callbackService.getBindings()) {
-                // first look for a callback binding whose name matches the reference binding name
-                if (binding.getName().equals(refBinding.getName()) ||
-                    binding.getName().equals(CALLBACK_PREFIX + refBinding.getName())) {
-                    callbackBinding = binding;
-                    break;
-                }
-            }
-            // if no callback binding found, try again based on reference binding type
-            if (callbackBinding == null) {
-                callbackBinding = callbackService.getBinding(refBinding.getClass());
-            }
-            InterfaceContract callbackContract = callbackService.getInterfaceContract();
-            EndpointReference callbackEndpoint = new EndpointReferenceImpl(
-                    (RuntimeComponent)refComponent, callbackService, callbackBinding, callbackContract);
-            wireSource.setCallbackEndpoint(callbackEndpoint);
-        }
-   
-        EndpointReference wireTarget =
-            new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract);
-    
-        RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor);
-        runtimeRef.getRuntimeWires().add(wire);
-        return wire;
     }
 
     /**

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java Fri Aug 17 19:08:36 2007
@@ -135,4 +135,12 @@
             return false;
         return true;
     }
+
+    /**
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java Fri Aug 17 19:08:36 2007
@@ -19,29 +19,19 @@
 
 package org.apache.tuscany.sca.core.runtime;
 
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.Property;
 import org.apache.tuscany.sca.assembly.impl.ComponentImpl;
-import org.apache.tuscany.sca.core.component.ServiceReferenceImpl;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
-import org.apache.tuscany.sca.core.invocation.WireObjectFactory;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.apache.tuscany.sca.scope.ScopeContainer;
 import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
-import org.osoa.sca.CallableReference;
-import org.osoa.sca.RequestContext;
-import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ComponentContext;
 
 /**
  * @version $Rev$ $Date$
  */
 public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent, ScopedRuntimeComponent {
-    public static final String SELF_REFERENCE_PREFIX = "$self$.";
+    protected ComponentContext componentContext;
     protected ImplementationProvider implementationProvider;
     protected ProxyFactory proxyService;
     protected ScopeContainer scopeContainer;
@@ -55,62 +45,6 @@
         this.proxyService = proxyService;
     }
 
-    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
-        return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX);
-    }
-
-    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
-        return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX + serviceName);
-    }
-
-    public <B> B getProperty(Class<B> type, String propertyName) {
-        for (Property p : getProperties()) {
-            if (p.getName().equals(propertyName)) {
-                // FIXME: Need to use the property object factory to create the
-                // instance
-                return null;
-            }
-        }
-        return null;
-    }
-
-    public RequestContext getRequestContext() {
-        return null;
-    }
-
-    public <B> B getService(Class<B> businessInterface, String referenceName) {
-        List<ComponentReference> refs = getReferences();
-        for (ComponentReference ref : refs) {
-            if (ref.getName().equals(referenceName)) {
-                RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
-                RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
-                return proxyService.createProxy(businessInterface, wire);
-            }
-        }
-        return null;
-    }
-
-    public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
-        List<ComponentReference> references = getReferences();
-        for (ComponentReference reference : references) {
-            if (reference.getName().equals(referenceName) || referenceName.equals("$self$.")
-                && reference.getName().startsWith(referenceName)) {
-                RuntimeComponentReference attachPoint = (RuntimeComponentReference)reference;
-                RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
-                WireObjectFactory<B> factory = new WireObjectFactory<B>(businessInterface, wire, proxyService);
-                return new ServiceReferenceImpl<B>(businessInterface, factory);
-            }
-        }
-        return null;
-
-    }
-
-    @SuppressWarnings("unchecked")
-    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
-        Object ref = proxyService.cast(target);
-        return (R)ref;
-    }
-
     public ImplementationProvider getImplementationProvider() {
         return implementationProvider;
     }
@@ -133,5 +67,19 @@
 
     public void setStarted(boolean started) {
         this.started = started;
+    }
+
+    /**
+     * @return the componentContext
+     */
+    public ComponentContext getComponentContext() {
+        return componentContext;
+    }
+
+    /**
+     * @param componentContext the componentContext to set
+     */
+    public void setComponentContext(ComponentContext componentContext) {
+        this.componentContext = componentContext;
     }
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java Fri Aug 17 19:08:36 2007
@@ -26,34 +26,38 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl;
+import org.apache.tuscany.sca.core.component.ComponentContextImpl;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.InvocationChain;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
 
 public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference {
-    private List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+    private List<RuntimeWire> wires;
     private Map<Binding, ReferenceBindingProvider> bindingProviders = new HashMap<Binding, ReferenceBindingProvider>();
     private InterfaceContractMapper mapper;
 
+    private RuntimeComponent component;
+
     public RuntimeComponentReferenceImpl(InterfaceContractMapper mapper) {
         super();
         this.mapper = mapper;
     }
 
-    public void addRuntimeWire(RuntimeWire wire) {
-        wires.add(wire);
-    }
-
-    public List<RuntimeWire> getRuntimeWires() {
+    public synchronized List<RuntimeWire> getRuntimeWires() {
+        if (wires == null) {
+            wires = new ArrayList<RuntimeWire>();
+            ((ComponentContextImpl)component.getComponentContext()).getCompositeActivator().activate(component, this);
+        }
         return wires;
     }
 
     public RuntimeWire getRuntimeWire(Binding binding) {
-        for (RuntimeWire wire : wires) {
+        for (RuntimeWire wire : getRuntimeWires()) {
             if (wire.getSource().getBinding() == binding) {
                 return wire;
             }
@@ -81,6 +85,31 @@
             }
         }
         return null;
+    }
+
+    /**
+     * @return the component
+     */
+    public RuntimeComponent getComponent() {
+        return component;
+    }
+
+    /**
+     * @param component the component to set
+     */
+    public void setComponent(RuntimeComponent component) {
+        this.component = component;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl#clone()
+     */
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        RuntimeComponentReferenceImpl ref = (RuntimeComponentReferenceImpl) super.clone();
+        ref.wires = null;
+        ref.bindingProviders = new HashMap<Binding, ReferenceBindingProvider>();
+        return ref;
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java Fri Aug 17 19:08:36 2007
@@ -26,6 +26,7 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.InvocationChain;
@@ -33,21 +34,17 @@
 import org.apache.tuscany.sca.provider.ServiceBindingProvider;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceRuntimeException;
 
 public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService {
     private InterfaceContractMapper mapper;
-
-    public RuntimeComponentServiceImpl(InterfaceContractMapper mapper) {
-        super();
-        this.mapper = mapper;
-    }
-
     private List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
     private List<RuntimeWire> callbackWires = new ArrayList<RuntimeWire>();
     private Map<Binding, ServiceBindingProvider> bindingProviders = new HashMap<Binding, ServiceBindingProvider>();
 
-    public void addRuntimeWire(RuntimeWire wire) {
-        wires.add(wire);
+    public RuntimeComponentServiceImpl(InterfaceContractMapper mapper) {
+        super();
+        this.mapper = mapper;
     }
 
     public List<RuntimeWire> getRuntimeWires() {
@@ -67,10 +64,6 @@
         return callbackWires;
     }
 
-    public void addCallbackWire(RuntimeWire callbackWire) {
-        this.callbackWires.add(callbackWire);
-    }
-
     public ServiceBindingProvider getBindingProvider(Binding binding) {
         return bindingProviders.get(binding);
     }
@@ -80,7 +73,11 @@
     }
 
     public Invoker getInvoker(Binding binding, Operation operation) {
-        InvocationChain chain = getInvocationChain(binding, operation);
+        return getInvoker(binding, null, operation);
+    }
+
+    public Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation) {
+        InvocationChain chain = getInvocationChain(binding, interfaceContract, operation);
         if (chain != null) {
             return chain.getHeadInvoker();
         } else {
@@ -88,11 +85,19 @@
         }
     }
 
-    public InvocationChain getInvocationChain(Binding binding, Operation operation) {
+    public InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation) {
         RuntimeWire wire = getRuntimeWire(binding);
         if (wire == null) {
             return null;
         }
+        if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) {
+            try {
+                wire = (RuntimeWire)wire.clone();
+                wire.getSource().setInterfaceContract(interfaceContract);
+            } catch (CloneNotSupportedException e) {
+                throw new ServiceRuntimeException(e);
+            }
+        }
         for (InvocationChain chain : wire.getInvocationChains()) {
             Operation op = chain.getTargetOperation();
             if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
@@ -102,4 +107,21 @@
         return null;
     }
 
+    public InvocationChain getInvocationChain(Binding binding, Operation operation) {
+        return getInvocationChain(binding, null, operation);
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl#clone()
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        RuntimeComponentServiceImpl clone = (RuntimeComponentServiceImpl)super.clone();
+        clone.bindingProviders =
+            (Map<Binding, ServiceBindingProvider>)((HashMap<Binding, ServiceBindingProvider>)bindingProviders).clone();
+        clone.wires = (List<RuntimeWire>)((ArrayList<RuntimeWire>)wires).clone();
+        clone.callbackWires = (List<RuntimeWire>)((ArrayList<RuntimeWire>)callbackWires).clone();
+        return clone;
+    }
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java Fri Aug 17 19:08:36 2007
@@ -128,6 +128,11 @@
     public EndpointReference getTarget() {
         return wireTarget;
     }
+    
+    public void setTarget(EndpointReference target) {
+        this.wireTarget = target;
+        this.chains = null;
+    }
 
     /**
      * Add the interceptor for a binding
@@ -203,5 +208,17 @@
             invoker = provider.createInvoker((RuntimeComponentService)service, operation);
             chain.addInvoker(invoker);
         }
+    }
+
+    /**
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        RuntimeWireImpl copy =(RuntimeWireImpl) super.clone();
+        copy.wireSource = (EndpointReference) wireSource.clone();
+        copy.wireTarget = (EndpointReference) wireTarget.clone();
+        copy.chains = null;
+        return copy;
     }
 }

Modified: incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationImplementationProvider.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationImplementationProvider.java (original)
+++ incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationImplementationProvider.java Fri Aug 17 19:08:36 2007
@@ -45,10 +45,14 @@
     RuntimeComponent runtimeComponent;
     Implementation impl;
     Object userImpl;
-    
+    InvokerFactory factory;
+
     List<InvokerProxy> invokers = new ArrayList<InvokerProxy>();
-    
-    public ImplementationImplementationProvider(ImplementationActivator implementationActivator, RuntimeComponent rc, Implementation impl, Object userImpl) {
+
+    public ImplementationImplementationProvider(ImplementationActivator implementationActivator,
+                                                RuntimeComponent rc,
+                                                Implementation impl,
+                                                Object userImpl) {
         this.implementationActivator = implementationActivator;
         this.runtimeComponent = rc;
         this.impl = impl;
@@ -57,19 +61,15 @@
 
     public Invoker createInvoker(RuntimeComponentService arg0, final Operation op) {
         InvokerProxy invoker = new InvokerProxy(op);
-        invokers.add(invoker);    
         return invoker;
     }
 
     public Invoker createCallbackInvoker(Operation operation) {
-        throw new RuntimeException("TODO: callbacks not yet implemented"); 
+        throw new RuntimeException("TODO: callbacks not yet implemented");
     }
 
     public void start() {
-        InvokerFactory factory = implementationActivator.createInvokerFactory(runtimeComponent, impl, userImpl);
-        for (InvokerProxy invoker : invokers) {
-            invoker.start(factory);
-        }
+        factory = implementationActivator.createInvokerFactory(runtimeComponent, impl, userImpl);
     }
 
     public void stop() {
@@ -78,14 +78,20 @@
     class InvokerProxy implements Invoker {
         Invoker invoker;
         Operation op;
+
         InvokerProxy(Operation op) {
             this.op = op;
         }
-        public Message invoke(Message arg0) {
-            return invoker.invoke(arg0);
+
+        public Message invoke(Message msg) {
+            init();
+            return invoker.invoke(msg);
         }
-        public void start(InvokerFactory factory) {
-            invoker = factory.createInvoker(op);
+
+        public synchronized void init() {
+            if (invoker == null) {
+                invoker = factory.createInvoker(op);
+            }
         }
-     }
+    }
 }

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java Fri Aug 17 19:08:36 2007
@@ -50,6 +50,7 @@
 import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
 import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.osoa.sca.CallableReference;
 import org.osoa.sca.ComponentContext;
 import org.osoa.sca.Constants;
@@ -358,7 +359,7 @@
                         if (serviceName != null) {
                             serviceName = "$promoted$." + serviceName;
                         }
-                        componentContext = (ComponentContext)compositeService.getPromotedComponent();
+                        componentContext = ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
                     }
                     break;
                 }
@@ -367,7 +368,7 @@
                 throw new ServiceRuntimeException("Composite service not found: " + name);
             }
         } else {
-            componentContext = (ComponentContext)component;
+            componentContext = ((RuntimeComponent)component).getComponentContext();
         }
 
         ServiceReference<B> serviceReference;

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java Fri Aug 17 19:08:36 2007
@@ -19,9 +19,6 @@
 
 package org.apache.tuscany.sca.host.embedded.impl;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -29,13 +26,13 @@
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.CompositeService;
-import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.contribution.service.ContributionService;
 import org.apache.tuscany.sca.core.runtime.ActivationException;
 import org.apache.tuscany.sca.core.runtime.CompositeActivator;
 import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.osoa.sca.CallableReference;
 import org.osoa.sca.ComponentContext;
 import org.osoa.sca.Constants;
@@ -175,7 +172,7 @@
                         if (serviceName != null) {
                             serviceName = "$promoted$." + serviceName;
                         }
-                        componentContext = (ComponentContext)compositeService.getPromotedComponent();
+                        componentContext = ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
                     }
                     break;
                 }
@@ -184,7 +181,7 @@
                 throw new ServiceRuntimeException("Composite service not found: " + name);
             }
         } else {
-            componentContext = (ComponentContext)component;
+            componentContext = ((RuntimeComponent)component).getComponentContext();
         }
 
         ServiceReference<B> serviceReference;

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java Fri Aug 17 19:08:36 2007
@@ -22,7 +22,6 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -48,10 +47,6 @@
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.provider.BindingProviderFactory;
-import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
-import org.apache.tuscany.sca.provider.ProviderFactory;
-import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.scope.ScopeRegistry;
 
 public class ReallySmallRuntime {
@@ -126,6 +121,7 @@
                                                                                 assemblyFactory,
                                                                                 scaBindingFactory,
                                                                                 mapper,
+                                                                                proxyFactory,
                                                                                 scopeRegistry,
                                                                                 workManager);
 

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java Fri Aug 17 19:08:36 2007
@@ -35,6 +35,8 @@
 import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;
 import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;
 import org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.context.RequestContextFactory;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
 import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.ContributionPostProcessor;
@@ -71,6 +73,7 @@
 import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
 import org.apache.tuscany.sca.core.work.Jsr237WorkScheduler;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
@@ -101,6 +104,7 @@
                                                               AssemblyFactory assemblyFactory,
                                                               SCABindingFactory scaBindingFactory,
                                                               InterfaceContractMapper mapper,
+                                                              ProxyFactory proxyFactory,
                                                               ScopeRegistry scopeRegistry,
                                                               WorkManager workManager) {
 
@@ -124,10 +128,13 @@
         // Create a provider factory extension point
         ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
 
+        JavaInterfaceFactory javaInterfaceFactory = registry.getExtensionPoint(ModelFactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class);
+        RequestContextFactory requestContextFactory = registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class);
+       
         // Create the composite activator
         CompositeActivator compositeActivator =
-            new CompositeActivatorImpl(assemblyFactory, scaBindingFactory, mapper, scopeRegistry, workScheduler,
-                                       wireProcessor, providerFactories);
+            new CompositeActivatorImpl(assemblyFactory, javaInterfaceFactory, scaBindingFactory, mapper, scopeRegistry, workScheduler,
+                                       wireProcessor, requestContextFactory, proxyFactory, providerFactories);
 
         return compositeActivator;
     }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java Fri Aug 17 19:08:36 2007
@@ -35,6 +35,6 @@
 
 
     public ComponentContext getInstance() throws ObjectCreationException {
-        return component.getComponentContext();
+        return component.getComponent().getComponentContext();
     }
 }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java Fri Aug 17 19:08:36 2007
@@ -36,9 +36,6 @@
 import org.apache.tuscany.sca.assembly.Reference;
 import org.apache.tuscany.sca.context.ComponentContextFactory;
 import org.apache.tuscany.sca.context.RequestContextFactory;
-import org.apache.tuscany.sca.core.component.ComponentContextImpl;
-import org.apache.tuscany.sca.core.component.ComponentContextProvider;
-import org.apache.tuscany.sca.core.component.ServiceReferenceImpl;
 import org.apache.tuscany.sca.core.invocation.CallbackWireObjectFactory;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
@@ -50,13 +47,8 @@
 import org.apache.tuscany.sca.implementation.java.context.TargetMethodNotFoundException;
 import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
 import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
-import org.apache.tuscany.sca.implementation.java.injection.ArrayMultiplicityObjectFactory;
 import org.apache.tuscany.sca.implementation.java.injection.ConversationIDObjectFactory;
-import org.apache.tuscany.sca.implementation.java.injection.FieldInjector;
-import org.apache.tuscany.sca.implementation.java.injection.Injector;
 import org.apache.tuscany.sca.implementation.java.injection.InvalidAccessorException;
-import org.apache.tuscany.sca.implementation.java.injection.ListMultiplicityObjectFactory;
-import org.apache.tuscany.sca.implementation.java.injection.MethodInjector;
 import org.apache.tuscany.sca.implementation.java.injection.ObjectCallbackException;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -69,9 +61,6 @@
 import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
 import org.apache.tuscany.sca.scope.TargetDestructionException;
 import org.apache.tuscany.sca.scope.TargetInvokerCreationException;
-import org.osoa.sca.CallableReference;
-import org.osoa.sca.ComponentContext;
-import org.osoa.sca.ServiceReference;
 import org.osoa.sca.annotations.ConversationID;
 
 /**
@@ -79,7 +68,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public class JavaComponentContextProvider implements ComponentContextProvider {
+public class JavaComponentContextProvider {
     private JavaPropertyValueObjectFactory propertyValueFactory;
     private DataBindingExtensionPoint dataBindingRegistry;
     
@@ -87,8 +76,6 @@
     private JavaInstanceFactoryProvider<?> configuration;
     private ProxyFactory proxyService;
 
-    private final ComponentContext componentContext;
-
     public JavaComponentContextProvider(RuntimeComponent component,
                              JavaInstanceFactoryProvider configuration,
                              DataBindingExtensionPoint dataBindingExtensionPoint,
@@ -98,11 +85,11 @@
         super();
         this.configuration = configuration;
         this.proxyService = configuration.getProxyFactory();
-        if (componentContextFactory != null) {
-            this.componentContext = componentContextFactory.createComponentContext(component, requestContextFactory);
-        } else {
-            this.componentContext = new ComponentContextImpl(this, requestContextFactory, this.proxyService);
-        }
+//        if (componentContextFactory != null) {
+//            this.componentContext = componentContextFactory.createComponentContext(component, requestContextFactory);
+//        } else {
+//            this.componentContext = new ComponentContextImpl(this, requestContextFactory, this.proxyService);
+//        }
         this.component = component;
         this.dataBindingRegistry = dataBindingExtensionPoint;
         this.propertyValueFactory = propertyValueObjectFactory;
@@ -244,63 +231,6 @@
         }
     }
 
-    public boolean implementsCallback(Class callbackClass) {
-        Class<?>[] implementedInterfaces = configuration.getDefinition().getJavaClass().getInterfaces();
-        for (Class<?> implementedInterface : implementedInterfaces) {
-            if (implementedInterface.isAssignableFrom(callbackClass)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    protected Injector<Object> createInjector(Member member, RuntimeWire wire) {
-        if (member instanceof Field) {
-            Class<?> type = ((Field)member).getType();
-            ObjectFactory<?> factory = createWireFactory(type, wire);
-            return new FieldInjector<Object>((Field)member, factory);
-        } else if (member instanceof Method) {
-            Class<?> type = ((Method)member).getParameterTypes()[0];
-            ObjectFactory<?> factory = createWireFactory(type, wire);
-            return new MethodInjector<Object>((Method)member, factory);
-        } else if (member instanceof Constructor) {
-            return null;
-        } else {
-            throw new InvalidAccessorException("Member must be a field or method: " + member.getName());
-        }
-    }
-
-    protected Injector<Object> createMultiplicityInjector(Member member,
-                                                          Class<?> interfaceType,
-                                                          List<RuntimeWire> wireFactories) {
-        List<ObjectFactory<?>> factories = new ArrayList<ObjectFactory<?>>();
-        for (RuntimeWire wire : wireFactories) {
-            factories.add(createWireFactory(interfaceType, wire));
-        }
-        if (member instanceof Field) {
-            Field field = (Field)member;
-            if (field.getType().isArray()) {
-                return new FieldInjector<Object>(field, new ArrayMultiplicityObjectFactory(interfaceType, factories));
-            } else {
-                return new FieldInjector<Object>(field, new ListMultiplicityObjectFactory(factories));
-            }
-        } else if (member instanceof Method) {
-            Method method = (Method)member;
-            if (method.getParameterTypes()[0].isArray()) {
-                return new MethodInjector<Object>(method, new ArrayMultiplicityObjectFactory(interfaceType, factories));
-            } else {
-                return new MethodInjector<Object>(method, new ListMultiplicityObjectFactory(factories));
-            }
-        } else {
-            throw new InvalidAccessorException("Member must be a field or method: " + member.getName());
-        }
-    }
-
-    public ComponentContext getComponentContext() {
-        return componentContext;
-    }
-
     @SuppressWarnings("unchecked")
     public <B> B getProperty(Class<B> type, String propertyName) {
         JavaElementImpl element = configuration.getDefinition().getPropertyMembers().get(propertyName);
@@ -327,6 +257,7 @@
 
     }
 
+    /*
     public <B> B getService(Class<B> type, String name) {
         List<RuntimeWire> referenceWires = getWiresForReference(name);
         if (referenceWires == null || referenceWires.size() < 1) {
@@ -346,7 +277,7 @@
         } else {
             // TODO support multiplicity
             RuntimeWire wire = referenceWires.get(0);
-            ObjectFactory<B> factory = createWireFactory(type, wire);
+            WireObjectFactory<B> factory = createWireFactory(type, wire);
             return new ServiceReferenceImpl<B>(type, factory);
         }
     }
@@ -359,19 +290,7 @@
         }
         return null;
     }
-
-    @SuppressWarnings("unchecked")
-    public <B, R extends CallableReference<B>> R cast(B target) {
-        return (R)proxyService.cast(target);
-    }
-
-    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
-        return null;
-    }
-
-    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
-        return null;
-    }
+    */
 
     public Object createInstance() throws ObjectCreationException {
         return createInstanceWrapper().getInstance();
@@ -418,7 +337,7 @@
 
     }
 
-    protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, RuntimeWire wire) {
+    protected <B> WireObjectFactory<B> createWireFactory(Class<B> interfaze, RuntimeWire wire) {
         return new WireObjectFactory<B>(interfaze, wire, proxyService);
     }
 
@@ -426,6 +345,13 @@
                                                           Object propertyValue,
                                                           Class javaType) {
         return propertyValueFactory.createValueFactory(property, propertyValue, javaType);
+    }
+
+    /**
+     * @return the component
+     */
+    public RuntimeComponent getComponent() {
+        return component;
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java Fri Aug 17 19:08:36 2007
@@ -49,16 +49,39 @@
 
     protected ScriptEngine scriptEngine;
     protected XMLHelper xmlHelper;
+    
+    protected RuntimeComponent rc; 
+    protected ComponentType ct; 
+    protected ScriptImplementation implementation;
+    protected PropertyValueObjectFactory propertyFactory;
 
-    public ScriptInvokerFactory(RuntimeComponent rc, ComponentType ct, ScriptImplementation implementation, PropertyValueObjectFactory propertyFactory) {
-        init(rc, ct, implementation, propertyFactory);
-    }
     
+    /**
+     * @param rc
+     * @param ct
+     * @param implementation
+     * @param propertyFactory
+     */
+    public ScriptInvokerFactory(RuntimeComponent rc,
+                                ComponentType ct,
+                                ScriptImplementation implementation,
+                                PropertyValueObjectFactory propertyFactory) {
+        super();
+        this.rc = rc;
+        this.ct = ct;
+        this.implementation = implementation;
+        this.propertyFactory = propertyFactory;
+    }
+
     public Invoker createInvoker(Operation operation) {
+        init(rc, ct, implementation, propertyFactory);
         return new ScriptInvoker(scriptEngine, xmlHelper, operation);
     }
     
-    protected void init(RuntimeComponent rc, ComponentType ct, ScriptImplementation implementation, PropertyValueObjectFactory propertyFactory) {
+    protected synchronized void init(RuntimeComponent rc, ComponentType ct, ScriptImplementation implementation, PropertyValueObjectFactory propertyFactory) {
+        if(scriptEngine!=null) {
+            return;
+        }
         try {
             scriptEngine = getScriptEngineByExtension(implementation.getScriptLanguage());
             if (scriptEngine == null) {
@@ -104,7 +127,7 @@
         for (ComponentReference reference : component.getReferences()) {
             if (reference.getName().equals(name)) {
                 Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass();
-                return component.getService(iface, name);
+                return component.getComponentContext().getService(iface, name);
             }
         }
         throw new IllegalArgumentException("reference " + name + " not found on component: " + component);

Modified: incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java Fri Aug 17 19:08:36 2007
@@ -24,7 +24,6 @@
 import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.ComponentProperty;
-import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.assembly.Property;
 import org.apache.tuscany.sca.assembly.Reference;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
@@ -32,8 +31,6 @@
 import org.apache.tuscany.sca.implementation.java.context.JavaPropertyValueObjectFactory;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -130,15 +127,7 @@
      * @return an Bean of the type defined by <B>
      */
     private <B> B getService(Class<B> businessInterface, String referenceName) {
-        List<ComponentReference> refs = component.getReferences();
-        for (ComponentReference ref : refs) {
-            if (ref.getName().equals(referenceName)) {
-                RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref;
-                RuntimeWire wire = attachPoint.getRuntimeWires().get(0);
-                return proxyService.createProxy(businessInterface, wire);
-            }
-        }
-        return null;
+        return component.getComponentContext().getService(businessInterface, referenceName);
     }
 
     /**

Modified: incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?view=diff&rev=567203&r1=567202&r2=567203
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java Fri Aug 17 19:08:36 2007
@@ -88,6 +88,10 @@
         List<Operation> operations = new ArrayList<Operation>(methods.length);
         Set<String> names = remotable? new HashSet<String>() : null;
         for (Method method : methods) {
+            if (method.getDeclaringClass() == Object.class) {
+                // Skip the methods on the Object.class
+                continue;
+            }
             String name = method.getName();
             if (remotable && names.contains(name)) {
                 throw new OverloadedOperationException(method);



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