tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r782569 - in /tuscany/java/sca/modules: assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ core-spi/src/main/java/org/apache/tuscany/sca/runtime/ core/src/mai...
Date Mon, 08 Jun 2009 09:30:51 GMT
Author: slaws
Date: Mon Jun  8 09:30:48 2009
New Revision: 782569

URL: http://svn.apache.org/viewvc?rev=782569&view=rev
Log:
TUSCANY-3081 - Enable the local endpoint registry implementation in the endpoint module. This delays endpoint reference resolution until chains are first created.Callback processing needs a thorough review as part of the next change to make EndpointReference2 serializable. 

Modified:
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java
    tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
    tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
    tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java Mon Jun  8 09:30:48 2009
@@ -87,7 +87,7 @@
         Map<String, String> attributes = builderDeclaration.getAttributes();
             String id = attributes.get("id");
 
-            CompositeBuilder builder = new LazyCompositeBuilder(id, builderDeclaration, this, factories, mapper);
+            CompositeBuilder builder = new LazyCompositeBuilder(registry, id, builderDeclaration, this, factories, mapper);
             builders.put(id, builder);
         }
     }
@@ -98,6 +98,7 @@
      */
     private static class LazyCompositeBuilder implements CompositeBuilder {
 
+        private ExtensionPointRegistry registry;
         private FactoryExtensionPoint factories;
         private InterfaceContractMapper mapper;
         private String id;
@@ -105,8 +106,9 @@
         private CompositeBuilder builder;
         private CompositeBuilderExtensionPoint builders;
 
-        private LazyCompositeBuilder(String id, ServiceDeclaration factoryDeclaration,
+        private LazyCompositeBuilder(ExtensionPointRegistry registry, String id, ServiceDeclaration factoryDeclaration,
                                      CompositeBuilderExtensionPoint builders, FactoryExtensionPoint factories, InterfaceContractMapper mapper) {
+            this.registry = registry;
             this.id = id;
             this.builderDeclaration = factoryDeclaration;
             this.builders = builders;
@@ -130,8 +132,13 @@
                         Constructor<CompositeBuilder> constructor = builderClass.getConstructor(FactoryExtensionPoint.class, InterfaceContractMapper.class);
                         builder = constructor.newInstance(factories, mapper);
                     } catch (NoSuchMethodException e) {
-                        Constructor<CompositeBuilder> constructor = builderClass.getConstructor(CompositeBuilderExtensionPoint.class, FactoryExtensionPoint.class, InterfaceContractMapper.class);
-                        builder = constructor.newInstance(builders, factories, mapper);
+                        try {
+                            Constructor<CompositeBuilder> constructor = builderClass.getConstructor(CompositeBuilderExtensionPoint.class, FactoryExtensionPoint.class, InterfaceContractMapper.class);
+                            builder = constructor.newInstance(builders, factories, mapper);
+                        } catch (NoSuchMethodException ex) {
+                            Constructor<CompositeBuilder> constructor = builderClass.getConstructor(ExtensionPointRegistry.class);
+                            builder = constructor.newInstance(registry);
+                        }
                     }
                 } catch (Exception e) {
                     throw new IllegalStateException(e);

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java Mon Jun  8 09:30:48 2009
@@ -210,7 +210,7 @@
                 } else {
                     // add an unresolved endpoint reference with an unresolved endpoint to go with it
                     EndpointReference2 endpointRef = createEndpointRef( component, reference, true  );
-                    endpointRef.setTargetEndpoint(createEndpoint(true));
+                    endpointRef.setTargetEndpoint(createEndpoint(targetName));
                     reference.getEndpointReferences().add(endpointRef);
                     warning(monitor, "ComponentReferenceTargetNotFound",
                             composite, 
@@ -342,10 +342,11 @@
         			} // end if
         		} // end if
         		// (Debug) For the moment, print out the results
-        		System.out.println( "Created endpointRef. Component = " + component.getName() + " Reference = " +
-        				reference.getName() + " LeafComponent = " + endRef.getComponent().getName() + " LeafReference = " +
-        				endRef.getReference().getName() + " Binding = " + endRef.getBinding() + " target Component = " +
-        				endpoint.getComponent() + " target Service = " + endpoint.getService() );
+        		// disable for the time being - SL
+        		//System.out.println( "Created endpointRef. Component = " + component.getName() + " Reference = " +
+        		//		reference.getName() + " LeafComponent = " + endRef.getComponent().getName() + " LeafReference = " +
+        		//		endRef.getReference().getName() + " Binding = " + endRef.getBinding() + " target Component = " +
+        		//		endpoint.getComponent() + " target Service = " + endpoint.getService() );
         	} // end for
         } // end for
     	
@@ -859,4 +860,30 @@
 	    return endpoint;
     } // end method createEndpoint
     
+    /**
+     * Helper method to create an Endpoint
+     * @param unresolved
+     * @return the endpoint
+     */
+    private Endpoint2 createEndpoint(String targetName) {
+        String componentName;
+        String serviceName;
+        int i = targetName.lastIndexOf('/');
+        if (i != -1) {
+            componentName = targetName.substring(0, i);
+            serviceName = targetName.substring(i + 1);
+
+        } else {
+            componentName = targetName;
+            serviceName = null;
+        }
+        
+        Endpoint2 endpoint = assemblyFactory.createEndpoint();
+        endpoint.setUnresolved(true);
+        endpoint.setComponentName(componentName);
+        endpoint.setServiceName(serviceName);
+        return endpoint;
+    } // end method createEndpoint
+
+    
 } // end class

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java Mon Jun  8 09:30:48 2009
@@ -144,9 +144,11 @@
                     		leafService.getEndpoints().add(endpoint);
                     	} // end if 
                     } // end if
-                    System.out.println( "Endpoint created for Component = " + component.getName() + " Leaf component = " + 
-                    		endpoint.getComponent().getName() + " service = " + 
-                    		endpoint.getService().getName() + " binding = " + endpoint.getBinding() );
+                    // debug
+                    // disabled for the time being - SL
+                    //System.out.println( "Endpoint created for Component = " + component.getName() + " Leaf component = " + 
+                    //		endpoint.getComponent().getName() + " service = " + 
+                    //		endpoint.getService().getName() + " binding = " + endpoint.getBinding() );
             	} // end for	
     		} // end for
     		// Handle composites as implementations

Modified: tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java (original)
+++ tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java Mon Jun  8 09:30:48 2009
@@ -25,6 +25,7 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.oasisopen.sca.CallableReference;
 import org.oasisopen.sca.ComponentContext;
@@ -61,13 +62,12 @@
      * @param <B>
      * @param businessInterface The business interface
      * @param reference The reference to be wired
-     * @param binding The binding to be used, if it's null, either binding.sca or the 1st binding
-     * will be selected
+     * @param endpointReference The endpointReference to be used
      * @return A service reference representing the wire
      */
     <B> ServiceReference<B> getServiceReference(Class<B> businessInterface,
                                                 RuntimeComponentReference reference,
-                                                Binding binding);
+                                                EndpointReference2 endpointReference);
 
     /**
      * Bind the reference to a target component/componentService

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java Mon Jun  8 09:30:48 2009
@@ -33,6 +33,7 @@
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.Endpoint2;
 import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.assembly.EndpointRegistry;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.assembly.Reference;
 import org.apache.tuscany.sca.assembly.Service;
@@ -82,6 +83,7 @@
 public class CompositeActivatorImpl2 implements CompositeActivator {
     private static final Logger logger = Logger.getLogger(CompositeActivatorImpl2.class.getName());
 
+    private final ExtensionPointRegistry extensionPoints;
     private final AssemblyFactory assemblyFactory;
     private final MessageFactory messageFactory;
     private final InterfaceContractMapper interfaceContractMapper;
@@ -95,6 +97,7 @@
     private final ProxyFactory proxyFactory;
     private final JavaInterfaceFactory javaInterfaceFactory;
     private final PropertyValueFactory propertyValueFactory;
+    private final EndpointRegistry endpointRegistry;
 
     private final ConversationManager conversationManager;
 
@@ -103,6 +106,7 @@
     private Composite domainComposite;
     
     public CompositeActivatorImpl2(ExtensionPointRegistry extensionPoints) {
+        this.extensionPoints = extensionPoints;
         this.compositeContext = new CompositeContextImpl(extensionPoints);
         FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
         this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
@@ -120,6 +124,7 @@
         this.requestContextFactory = contextFactories.getFactory(RequestContextFactory.class);
         proxyFactory = compositeContext.getProxyFactory();
         this.conversationManager = compositeContext.getConversationManager();
+        this.endpointRegistry = utilities.getUtility(EndpointRegistry.class);
     }
 
     //=========================================================================
@@ -376,7 +381,8 @@
             endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding()));
             
             // create the wire
-            RuntimeWire wire = new RuntimeWireImpl2(false, 
+            RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
+                                                    false, 
                                                     endpointReference, 
                                                     endpoint, 
                                                     interfaceContractMapper, 
@@ -416,14 +422,7 @@
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName());
         }
-
-        // TODO this may need to move into the code where we check that an endpoint is resolved
-        for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
-            if (endpointReference.getBinding() != null){
-                addReferenceBindingProvider(component, reference, endpointReference.getBinding());
-            }
-        }
-        
+       
         // set the parent component onto the reference. It's used at start time when the 
         // reference is asked to return it's runtime wires. If there are none the reference
         // asks the component context to start the reference which creates the wires
@@ -443,7 +442,7 @@
             }
         }
     }  
-    
+/*    
     private ReferenceBindingProvider addReferenceBindingProvider(
             RuntimeComponent component, RuntimeComponentReference reference,
             Binding binding) {
@@ -476,7 +475,7 @@
                             + binding.getClass().getName());
         }
     }
-    
+*/    
     private void removeReferenceBindingProvider(RuntimeComponent component,
             RuntimeComponentReference reference, Binding binding) {
         reference.setBindingProvider(binding, null);
@@ -535,29 +534,8 @@
         }
         
         configureComponentContext(runtimeComponent);
-
-/* TODO - EPR won't start until reference is actually started later
-        for (ComponentReference reference : component.getReferences()) {
-            if (logger.isLoggable(Level.FINE)) {
-                logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
-            }
-            RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
-            runtimeRef.setComponent(runtimeComponent);
-            
-            for (Binding binding : reference.getBindings()) {
-                final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
-                if (bindingProvider != null) {
-                    // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. 
-                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
-                        public Object run() {
-                            bindingProvider.start();
-                            return null;
-                          }
-                    });                       
-                }
-            }
-        }
-*/
+        
+        // Reference bindings aren't started until the wire is first used
 
         for (ComponentService service : component.getServices()) {
             if (logger.isLoggable(Level.FINE)) {
@@ -565,6 +543,7 @@
             }
             RuntimeComponentService runtimeService = (RuntimeComponentService)service;
             for (Endpoint2 endpoint : service.getEndpoints()) {
+                endpointRegistry.addEndpoint(endpoint);
                 final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
                 if (bindingProvider != null) {
                     // bindingProvider.start();
@@ -611,6 +590,7 @@
                 logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName());
             }
             for (Endpoint2 endpoint : service.getEndpoints()) {
+                endpointRegistry.removeEndpoint(endpoint);
                 final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(endpoint.getBinding());
                 if (bindingProvider != null) {
                     // Allow bindings to read properties. Requires PropertyPermission read in security policy. 
@@ -689,6 +669,7 @@
                 return;
             }
             
+            /* The way it was 
             // create a wire for each endpoint reference. An endpoint reference says that a
             // target has been specified and hence the reference has been wired in some way.
             // The service may not have been found yet, depending on the way the composite 
@@ -725,7 +706,21 @@
                     // add the wire
                     addReferenceWire(component, componentReference, endpointReference);
                 }
-            }           
+            }   
+            */
+            
+            // create a wire for each endpoint reference. An endpoint reference says either that 
+            // - a target has been specified and hence the reference has been wired in some way.
+            // - an unwired binding ha been specified
+            // and endpoint reference representing a wired reference may not at this point
+            // be resolved (the service to which it points may not be present in the 
+            // current composite). Endpoint reference resolution takes place when the wire
+            // is first used (when the chains are created)
+            for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){
+                addReferenceWire(component, componentReference, endpointReference);
+                endpointRegistry.addEndpointReference(endpointReference);
+            }
+            
         }
     }
 
@@ -735,6 +730,7 @@
         }
         RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
         for ( EndpointReference2 endpointReference : runtimeRef.getEndpointReferences()){
+            endpointRegistry.removeEndpointReference(endpointReference);
             ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
             if (bindingProvider != null) {
                 bindingProvider.stop();
@@ -759,6 +755,7 @@
         // TODO - EPR - interface contract seems to be null in the implementation.web
         //              case. Not introspecting the CT properly?
         if (sourceContract == null){
+            // TODO - Can't do this with move of matching to wire
             // take the contract from the service to which the reference is connected
             sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract();
             reference.setInterfaceContract(sourceContract);
@@ -790,9 +787,11 @@
         }
 */
 
+/* TODO - EPR can't do this until the binding matches the EPR        
         InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding());
         Endpoint2 endpoint = endpointReference.getTargetEndpoint();
         endpoint.setInterfaceContract(bindingContract);
+*/
     
 /* TODO - EPR review in the light of new matching code        
         // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a
@@ -803,9 +802,12 @@
 */        
 
         // create the wire
-        RuntimeWire wire = new RuntimeWireImpl2(true, 
+        // null endpoint passed in here as the endpoint reference may 
+        // not be resolved yet
+        RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
+                                                true, 
                                                 endpointReference, 
-                                                endpoint, 
+                                                null, 
                                                 interfaceContractMapper, 
                                                 workScheduler, 
                                                 wireProcessor,

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl2.java Mon Jun  8 09:30:48 2009
@@ -20,6 +20,8 @@
 package org.apache.tuscany.sca.core.assembly.impl;
 
 import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -29,6 +31,11 @@
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.Endpoint2;
 import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
+import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.core.conversation.ConversationManager;
 import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
 import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker;
@@ -42,9 +49,13 @@
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
 import org.apache.tuscany.sca.provider.PolicyProviderRRB;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB;
 import org.apache.tuscany.sca.provider.ServiceBindingProvider;
@@ -62,6 +73,9 @@
  * @version $Rev$ $Date$
  */
 public class RuntimeWireImpl2 implements RuntimeWire {
+    
+    private ExtensionPointRegistry extensionPoints;
+    
     private Boolean isReferenceWire = false;
     private EndpointReference2 endpointReference;
     private Endpoint2 endpoint;
@@ -82,6 +96,9 @@
 
     private List<InvocationChain> chains;
     private InvocationChain bindingInvocationChain;
+    
+    private EndpointReferenceBuilder endpointReferenceBuilder;
+    private final ProviderFactoryExtensionPoint providerFactories;
 
     /**
      * @param source
@@ -92,7 +109,8 @@
      * @param messageFactory 
      * @param conversationManager 
      */
-    public RuntimeWireImpl2(boolean isReferenceWire,
+    public RuntimeWireImpl2(ExtensionPointRegistry extensionPoints,
+                            boolean isReferenceWire,
                             EndpointReference2 endpointReference,
                             Endpoint2 endpoint,
                             InterfaceContractMapper interfaceContractMapper,
@@ -101,6 +119,7 @@
                             MessageFactory messageFactory,
                             ConversationManager conversationManager) {
         super();
+        this.extensionPoints = extensionPoints;
         this.isReferenceWire = isReferenceWire;
         this.endpointReference = endpointReference;
         this.endpoint = endpoint;
@@ -110,6 +129,10 @@
         this.messageFactory = messageFactory;
         this.conversationManager = conversationManager;
         this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this);
+       
+        UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+        this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class);
+        this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
     }
 
     public synchronized List<InvocationChain> getInvocationChains() {
@@ -164,12 +187,15 @@
      * Initialize the invocation chains
      */
     private void initInvocationChains() {
+   
         chains = new ArrayList<InvocationChain>();
         InterfaceContract sourceContract = endpointReference.getInterfaceContract();
-        InterfaceContract targetContract = endpoint.getInterfaceContract();
 
         if (isReferenceWire) {
             // It's the reference wire
+            resolveEndpointReference();
+
+            InterfaceContract targetContract = endpoint.getInterfaceContract();
             RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
             Binding refBinding = endpointReference.getBinding();
             for (Operation operation : sourceContract.getInterface().getOperations()) {
@@ -191,6 +217,7 @@
             
         } else {
             // It's the service wire
+            InterfaceContract targetContract = endpoint.getInterfaceContract();
             RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
             RuntimeComponent serviceComponent = (RuntimeComponent)endpoint.getComponent();
             Binding serviceBinding = endpoint.getBinding();
@@ -216,6 +243,88 @@
         wireProcessor.process(this);
     }
     
+    /**
+     * This code used to be in the activator but has moved here as 
+     * the endpoint reference may not now be resolved until the wire
+     * is first used
+     */
+    private void resolveEndpointReference(){
+        endpointReferenceBuilder.build(endpointReference, null);
+        
+        // set the endpoint based on the resolved endpoint
+        endpoint = endpointReference.getTargetEndpoint();
+                
+        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)endpointReference.getReference();
+        
+        if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
+            addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(), 
+                    runtimeRef, 
+                    endpointReference.getBinding());
+        }
+        
+        // start the binding provider   
+        final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
+        
+        if (bindingProvider != null) {
+            // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. 
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    bindingProvider.start();
+                    return null;
+                  }
+            });                       
+        }
+        
+        InterfaceContract bindingContract = getInterfaceContract(endpointReference.getReference(), endpointReference.getBinding());
+        Endpoint2 endpoint = endpointReference.getTargetEndpoint();
+        endpoint.setInterfaceContract(bindingContract);
+    }
+    
+    private ReferenceBindingProvider addReferenceBindingProvider(
+            RuntimeComponent component, RuntimeComponentReference reference,
+            Binding binding) {
+        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);
+            }
+            for (PolicyProviderFactory f : providerFactories
+                    .getPolicyProviderFactories()) {
+                PolicyProvider policyProvider = f
+                        .createReferencePolicyProvider(component, reference,
+                                binding);
+                if (policyProvider != null) {
+                    reference.addPolicyProvider(binding, policyProvider);
+                }
+            }
+
+            return bindingProvider;
+        } else {
+            throw new IllegalStateException(
+                    "Provider factory not found for class: "
+                            + binding.getClass().getName());
+        }
+    }  
+    
+    private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
+        InterfaceContract interfaceContract = reference.getInterfaceContract();
+        ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+        if (provider != null) {
+            InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+            if (bindingContract != null) {
+                interfaceContract = bindingContract;
+            }
+        }
+        return interfaceContract.makeUnidirectional(false);
+    }     
+    
     private void initReferenceBindingInvocationChains() {
         RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
         Binding referenceBinding = endpointReference.getBinding();

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java Mon Jun  8 09:30:48 2009
@@ -81,9 +81,6 @@
 
     protected transient RuntimeComponent component;
     protected transient RuntimeComponentReference reference;
-    // TODO - EPR - remove wire indexing on bindings as enpoint references
-    //              can share reference bindings
-    protected transient Binding binding;
     protected transient EndpointReference2 endpointReference;
 
     protected String scdl;
@@ -110,36 +107,33 @@
     protected CallableReferenceImpl(Class<B> businessInterface,
                                     RuntimeComponent component,
                                     RuntimeComponentReference reference,
-                                    Binding binding,
+                                    EndpointReference2 endpointReference,
                                     ProxyFactory proxyFactory,
                                     CompositeActivator compositeActivator) {
         this.proxyFactory = proxyFactory;
         this.businessInterface = businessInterface;
         this.component = component;
         this.reference = reference;
-        this.binding = binding;
+        this.endpointReference = endpointReference;
         
         // FIXME: The SCA Specification is not clear how we should handle multiplicity 
         // for CallableReference
-        if (this.binding == null) {
-            this.binding = this.reference.getBinding(SCABinding.class);
-            if (this.binding == null) {
-
-                // TODO: TUSCANY-2580: if the refernece doesn't have a binding yet then instead of NPE use a candidate one if its avaialable              
-                if (reference.getBindings() != null && reference.getBindings().size() > 0) {
-                    this.binding = this.reference.getBindings().get(0);
-                } 
+        if (this.endpointReference == null) {
+            
+            // TODO - EPR - If no endpoint reference specified assume the first one
+            //        This will happen when a self reference is created in which case the 
+            //        the reference should only have on endpointReference so use that 
+            if (this.reference.getEndpointReferences().size() == 0){
+                throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " + 
+                        component.getName() + " has no endpoint references");
             }
             
-            // TODO - EPR - If no binding specified assume default binding and find the endpoint reference 
-            //              related to it
-            for (EndpointReference2 endpointReference : this.reference.getEndpointReferences()){
-                if ((endpointReference.getBinding() != null) && 
-                    (endpointReference.getBinding() instanceof SCABinding)){
-                    this.endpointReference = endpointReference;
-                    break;
-                }
+            if (this.reference.getEndpointReferences().size() > 1){
+                throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " + 
+                        component.getName() + " has more than one endpoint reference");
             }
+            
+            this.endpointReference = this.reference.getEndpointReferences().get(0);
         }
 
         // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding?
@@ -160,8 +154,6 @@
             resolve();
             if (endpointReference != null){
                 return reference.getRuntimeWire(endpointReference);
-            } else if (reference != null) {
-                return reference.getRuntimeWire(binding);
             } else {
                 return null;
             }
@@ -174,7 +166,6 @@
         if (wire != null) {
             this.component = wire.getSource().getComponent();
             this.reference = (RuntimeComponentReference)wire.getSource().getContract();
-            this.binding = wire.getSource().getBinding();
             this.endpointReference = wire.getEndpointReference();
             this.compositeActivator = ((ComponentContextExt)component.getComponentContext()).getCompositeActivator();
             this.conversationManager = this.compositeActivator.getCompositeContext().getConversationManager();
@@ -276,6 +267,8 @@
     /**
      * @throws IOException
      */
+ // TODO - EPR all needs sorting out for endpoint references
+    
     private synchronized void resolve() throws Exception {
         if ((scdl != null || xmlReader != null) && component == null && reference == null) {
             CompositeContext componentContextHelper = CompositeContext.getCurrentCompositeContext();
@@ -308,6 +301,7 @@
                     attachConversation(parameters.getConversationID());
                 }
 
+                // TODO - EPR all needs sorting out for endpoint references
                 for (Binding binding : reference.getBindings()) {
                     if (binding instanceof OptimizableBinding) {
                         // Resolve the Component
@@ -341,6 +335,7 @@
                         }
                     }
                 }
+/*
                 // FIXME: The SCA Specification is not clear how we should handle multiplicity 
                 // for CallableReference
                 if (binding == null) {
@@ -349,6 +344,8 @@
                         binding = reference.getBindings().get(0);
                     }
                 }
+*/
+                
                 Interface i = reference.getInterfaceContract().getInterface();
                 if (i instanceof JavaInterface) {
                     JavaInterface javaInterface = (JavaInterface)i;
@@ -370,9 +367,11 @@
                     }
                     this.businessInterface = (Class<B>)javaInterface.getJavaClass();
                 }
+/*                
                 if (binding instanceof BindingBuilderExtension) {
                     ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null);
                 }
+*/
                 this.proxyFactory = compositeActivator.getCompositeContext().getProxyFactory();
             }
         } else {
@@ -508,6 +507,7 @@
         return parameters;
     }
 
+    // TODO - EPR - needs sorting out for new endpoint references
     public EndpointReference getEndpointReference() {
         try {
             resolve();
@@ -517,7 +517,7 @@
             InterfaceContract sourceContract =
                 componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
             sourceContract = sourceContract.makeUnidirectional(false);
-            EndpointReference epr = new EndpointReferenceImpl(component, reference, binding, sourceContract);
+            EndpointReference epr = new EndpointReferenceImpl(component, reference, null /*binding*/, sourceContract);
             ReferenceParameters parameters = getReferenceParameters();
             epr.setReferenceParameters(parameters);
             return epr;

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java Mon Jun  8 09:30:48 2009
@@ -215,7 +215,7 @@
      */
     public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface,
                                                        RuntimeComponentReference reference,
-                                                       Binding binding) {
+                                                       EndpointReference2 endpointReference) {
         try {
             RuntimeComponentReference ref = (RuntimeComponentReference)reference;
             InterfaceContract interfaceContract = reference.getInterfaceContract();
@@ -233,7 +233,7 @@
                 }
             }
             ref.setComponent(component);
-            return new ServiceReferenceImpl<B>(businessInterface, component, ref, binding, proxyFactory,
+            return new ServiceReferenceImpl<B>(businessInterface, component, ref, endpointReference, proxyFactory,
                                                compositeActivator);
         } catch (Exception e) {
             throw new ServiceRuntimeException(e);
@@ -452,9 +452,9 @@
             for (ComponentReference ref : component.getReferences()) {
                 if (referenceName.equals(ref.getName())) {
                     ArrayList<ServiceReference<B>> serviceRefs = new ArrayList<ServiceReference<B>>();
-                    for (Binding binding : ref.getBindings()) {
+                    for (EndpointReference2 endpointReference : ref.getEndpointReferences()) {
                         serviceRefs
-                            .add(getServiceReference(businessInterface, (RuntimeComponentReference)ref, binding));
+                            .add(getServiceReference(businessInterface, (RuntimeComponentReference)ref, endpointReference));
                     }
                     return serviceRefs;
                 }

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java Mon Jun  8 09:30:48 2009
@@ -21,6 +21,7 @@
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
 import org.apache.tuscany.sca.core.assembly.CompositeActivator;
 import org.apache.tuscany.sca.core.context.CallableReferenceExt;
 import org.apache.tuscany.sca.core.context.ServiceReferenceExt;
@@ -79,10 +80,10 @@
     public ServiceReferenceImpl(Class<B> businessInterface,
                                 RuntimeComponent component,
                                 RuntimeComponentReference reference,
-                                Binding binding,
+                                EndpointReference2 endpointReference,
                                 ProxyFactory proxyFactory,
                                 CompositeActivator compositeActivator) {
-        super(businessInterface, component, reference, binding, proxyFactory, compositeActivator);
+        super(businessInterface, component, reference, endpointReference, proxyFactory, compositeActivator);
     }
 
     public Object getConversationID() {

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java Mon Jun  8 09:30:48 2009
@@ -19,6 +19,7 @@
 package org.apache.tuscany.sca.core.invocation;
 
 import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
 import org.apache.tuscany.sca.core.factory.ObjectCreationException;
 import org.apache.tuscany.sca.core.factory.ObjectFactory;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -34,7 +35,7 @@
     private Class<?> businessInterface;
     private RuntimeComponent component;
     private RuntimeComponentReference reference;
-    private Binding binding;
+    private EndpointReference2 endpointReference;
 
     /**
      * Constructor.
@@ -49,15 +50,15 @@
     public CallableReferenceObjectFactory(Class<?> businessInterface,
                                           RuntimeComponent component,
                                           RuntimeComponentReference reference,
-                                          Binding binding) {
+                                          EndpointReference2 endpointReference) {
         this.businessInterface = businessInterface;
         this.component = component;
         this.reference = reference;
-        this.binding = binding;
+        this.endpointReference = endpointReference;
     }
 
     public CallableReference<?> getInstance() throws ObjectCreationException {
-        return component.getComponentContext().getServiceReference(businessInterface, reference, binding);
+        return component.getComponentContext().getServiceReference(businessInterface, reference, endpointReference);
     }
 
 }

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java Mon Jun  8 09:30:48 2009
@@ -137,6 +137,9 @@
     }
 
     /**
+     * Gets the endpoint reference from the incoming message that points
+     * back to the callback service
+     * 
      * @param msgContext
      */
     private static EndpointReference getCallbackEndpoint(Message msgContext) {
@@ -159,20 +162,34 @@
                 RuntimeComponentReference ref = null;
                 if (contract == null) {
                     //TODO - EPR - does it ever go through here?
+                    //       in what situation is there no reference in the endpoint reference
+                    //       pointing back to the callbac service
                     boundWire = (RuntimeWire)wire.clone();
 
                 } else if (contract instanceof RuntimeComponentReference) {
+                    // TODO - EPP - the endpoint reference pointing back to the 
+                    //        callback service holds a reference representing
+                    //        a reference to the callback service. This is true if a 
+                    //        callback object has been set into the reference on the 
+                    //        client side 
                     ref = (RuntimeComponentReference)contract;
-                    //TODO - EPR - get the bound wire based on endpont reference no binding
-                    //boundWire = ref.getRuntimeWire(resolvedEndpoint.getBinding());
+                    
+                    // TODO - EPR - get the wire from the reference that matches the 
+                    //        injected callback reference wire. We don't have bindings yet as the 
+                    //        callback object wire hasn't been initialized 
+/*                    
                     for (RuntimeWire runtimeWire : ref.getRuntimeWires()){
-                        if (runtimeWire.getEndpointReference().getBinding().getName().equals(resolvedEndpoint.getBinding().getName())){
+                        if (runtimeWire.getEndpointReference().getBinding().getName().equals(wire.getEndpointReference().getBinding().getName())){
                             boundWire = runtimeWire;
                             break;
                         }
                     }
+*/
+                    // just get the first one for now
+                    boundWire = ref.getRuntimeWires().get(0);
 
                 } else {  // contract instanceof RuntimeComponentService
+                    //TODO - EPR - I think it does this if no callback object has been set explicitly
                     ref = bind((RuntimeComponentReference)wire.getSource().getContract(),
                                 resolvedEndpoint);
                     boundWire = ref.getRuntimeWires().get(0);
@@ -242,7 +259,9 @@
         RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract();
         
         // TODO - EPR
-        wire.getEndpointReference().getTargetEndpoint().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
+        // needs to be set after the chains have been created for the first time
+        // as now the binding provider won't be created until that time 
+        //wire.getEndpointReference().getTargetEndpoint().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
     }
 
     /**

Modified: tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java Mon Jun  8 09:30:48 2009
@@ -149,10 +149,15 @@
             throw new ServiceRuntimeException("No runtime wire is available");
         }
         InvocationChain chain = getInvocationChain(method, wire);
+        
         if (chain == null) {
             throw new IllegalArgumentException("No matching operation is found: " + method);
         }
 
+        // The EndpointReference is not now resolved until the invocation chain 
+        // is first created so reset the source here 
+        source = wire.getSource();
+        
         // send the invocation down the wire
         Object result = invoke(chain, args, wire, source);
 
@@ -349,11 +354,17 @@
                 scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID());
             }
         }
-
+        
         Interface interfaze = msg.getFrom().getCallbackEndpoint().getInterfaceContract().getInterface();
         if (callbackObject != null) {
             if (callbackObject instanceof ServiceReference) {
-                EndpointReference callbackRef = ((CallableReferenceExt<?>)callbackObject).getEndpointReference();
+                CallableReferenceExt<?> callableReference = (CallableReferenceExt<?>)callbackObject;
+                EndpointReference callbackRef = callableReference.getEndpointReference();
+                
+                // TODO - EPR - create chains on the callback reference in case this hasn't already happened
+                //        needed as the bindings are not now matched until the chanins are created
+                callableReference.getRuntimeWire().getInvocationChains();
+                
                 parameters.setCallbackReference(callbackRef);
             } else {
                 if (interfaze != null) {

Modified: tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java (original)
+++ tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java Mon Jun  8 09:30:48 2009
@@ -32,6 +32,7 @@
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.assembly.Endpoint2;
 import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.assembly.EndpointRegistry;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.assembly.SCABinding;
@@ -40,6 +41,7 @@
 import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.definitions.Definitions;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.monitor.Monitor;
@@ -47,6 +49,7 @@
 import org.apache.tuscany.sca.monitor.Problem.Severity;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySubject;
+import org.oasisopen.sca.SCARuntimeException;
 
 /**
  * An builder that takes endpoint references and resolves them. It either finds local 
@@ -62,15 +65,19 @@
     protected ExtensionPointRegistry extensionPoints;
     protected AssemblyFactory assemblyFactory;
     protected InterfaceContractMapper interfaceContractMapper;
+    protected EndpointRegistry endpointRegistry;
     
     
     public EndpointReferenceBuilderImpl(ExtensionPointRegistry extensionPoints) {
         this.extensionPoints = extensionPoints;
-    }
-    
-    public EndpointReferenceBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) {
+        
+        FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
         this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
-        this.interfaceContractMapper = mapper;
+        
+        UtilityExtensionPoint utils = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+        this.interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class);
+        
+        this.endpointRegistry = utils.getUtility(EndpointRegistry.class);
     }
 
     public String getID() {
@@ -121,58 +128,6 @@
             monitor.problem(problem);
         }
     }    
-    
-    /**
-     * Index components inside a composite
-     * 
-     * @param composite
-     * @param componentServices
-
-     */
-    protected void indexComponents(Composite composite,
-                                 Map<String, Component> components) {
-        for (Component component : composite.getComponents()) {
-            // Index components by name
-            components.put(component.getName(), component);
-        }    
-    }
-    
-    /**
-     * Index services inside a composite
-     * 
-     * @param composite
-     * @param componentServices
-     */
-    protected void indexServices(Composite composite,
-                                 Map<String, ComponentService> componentServices) {
-
-        for (Component component : composite.getComponents()) {
-            
-            ComponentService nonCallbackService = null;
-            int nonCallbackServiceCount = 0;
-            
-            for (ComponentService componentService : component.getServices()) {                 
-                // Index component services by component name / service name
-                String uri = component.getName() + '/' + componentService.getName();
-                componentServices.put(uri, componentService);
-                
-                // count how many non-callback there are
-                if (!componentService.isCallback()) {                            
-                    
-                    if (nonCallbackServiceCount == 0) {
-                        nonCallbackService = componentService;
-                    }
-                    nonCallbackServiceCount++;
-                }
-            }
-            if (nonCallbackServiceCount == 1) {
-                // If we have a single non callback service, index it by
-                // component name as well
-                componentServices.put(component.getName(), nonCallbackService);
-            }
-        }    
-    }    
-        
 
     /**
      * Build all the endpoint references
@@ -181,46 +136,37 @@
      */
     public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException 
     {
-        // process top level composite references
-        // TODO - I don't think OASIS allows for these
-        //
-        //processCompositeReferences(composite);
-        
-        // process component services
-        processComponentReferences(composite, monitor);  
-    }
-    
-    private void processCompositeReferences(Composite composite) {
-        // TODO do we need this for OASIS?
+        // Not used now
     }
-    
-    private void processComponentReferences(Composite composite, Monitor monitor) {
-        
-        // index all of the components in the composite
-        Map<String, Component> components = new HashMap<String, Component>();
-        indexComponents(composite, components);
-        
-        // index all of the services in the composite
-        Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>();
-        indexServices(composite, componentServices);
+
+    /*
+    private void populateEndpointRegistry(Composite composite, Monitor monitor) {
         
-        // create endpoint references for each component's references
+        // register endpoints (and endpoint references) for each component
         for (Component component : composite.getComponents()) {
             // recurse for composite implementations
             Implementation implementation = component.getImplementation();
             if (implementation instanceof Composite) {
-                processComponentReferences((Composite)implementation, monitor);
+                populateEndpointRegistry((Composite)implementation, monitor);
+            }
+            
+            // register endpoints  
+            for (ComponentService service : component.getServices()) {
+                for (Endpoint2 endpoint : service.getEndpoints()){
+                    endpointRegistry.addEndpoint(endpoint);
+                }
             }
             
-            // build endpoint references 
+            // register endpoint references  
             for (ComponentReference reference : component.getReferences()) {
                 for (EndpointReference2 endpointReference : reference.getEndpointReferences()){
-                    build(endpointReference, monitor);
+                    endpointRegistry.addEndpointReference(endpointReference);
                 }
-            }
+            }            
         }
-    }    
-
+    }
+    */
+    
     /**
      * Build a single endpoint reference
      * 
@@ -234,23 +180,50 @@
             // an error?
         } else {          
             if (endpoint.isUnresolved() == false){
-                // everything is resolved
+                // Wired - service resolved - binding matched
+                // The service is in the same composite
                 return;
             }
             
             if (endpointReference.isUnresolved() == false ){  
-                // TODO - bring resolution and binding matching together
-                // just do binding matching
+                // Wired - service resolved - binding not matched 
+                // The service is in the same composite
+                // TODO - How do we get to here?
                 matchForwardBinding(endpointReference, 
                                     monitor);
                 
                 matchCallbackBinding(endpointReference, 
                                      monitor);
             } else {
-                // resolve the endpoint reference in the domain and then 
-                // match bindings
+                // Wired - service specified but unresolved
+                // The service is in a remote composite somewhere else in the domain
+                
+                // find the service in the endpoint registry
+                List<Endpoint2> endpoints = endpointRegistry.findEndpoint(endpointReference);
+                
+                // TODO - do we exepect to find more than one endpoint in 
+                //        anything other than the autowire case?
+                if (endpoints.size() == 0) {
+                    throw new SCARuntimeException("No endpoints found for EndpointReference " + endpointReference.toString());
+                }
+                
+                if (endpoints.size() > 1) {
+                    throw new SCARuntimeException("More than one endpoint found for EndpointReference" + endpointReference.toString());
+                }
+                
+                endpointReference.setTargetEndpoint(endpoints.get(0));
+                
+                matchForwardBinding(endpointReference, 
+                        monitor);
+    
+                matchCallbackBinding(endpointReference, 
+                         monitor);
             } 
-        }        
+        }      
+        
+        if (endpointReference.isUnresolved()){
+            throw new SCARuntimeException("EndpointReference can't be resolved");
+        }
     }
     
     // TODO - EPR - In OASIS case there are no bindings to match with on the 
@@ -279,7 +252,7 @@
         if (matchedReferenceBinding.isEmpty()) {
             // No matching binding
             endpointReference.setBinding(null);
-            endpointReference.setTargetEndpoint(null);
+            endpointReference.setUnresolved(true);
             warning(monitor, 
                     "NoMatchingBinding", 
                     endpointReference.getReference(),
@@ -324,6 +297,7 @@
                 Endpoint2 clonedEndpoint = (Endpoint2)serviceEndpoint.clone();
                 
                 endpointReference.setTargetEndpoint(clonedEndpoint);
+                endpointReference.setUnresolved(false);
 
             } catch (Exception ex) {
                 // do nothing
@@ -368,6 +342,7 @@
         if (matchedEndpoint.isEmpty()) {
             // No matching binding
             endpointReference.setCallbackEndpoint(null);
+            endpointReference.setUnresolved(true);
             warning(monitor, 
                     "NoMatchingCallbackBinding", 
                     endpointReference.getReference(),
@@ -386,6 +361,7 @@
             }
             
             endpointReference.setCallbackEndpoint(matchedEndpoint.get(selectedEndpoint));
+            endpointReference.setUnresolved(false);
         }
     }     
     

Modified: 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/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java?rev=782569&r1=782568&r2=782569&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java (original)
+++ tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java Mon Jun  8 09:30:48 2009
@@ -221,7 +221,7 @@
                                 new CallableReferenceObjectFactory(businessInterface, component,
                                                                    (RuntimeComponentReference)wireList.get(i)
                                                                        .getSource().getContract(), wireList.get(i)
-                                                                       .getSource().getBinding());
+                                                                       .getEndpointReference());
                         } else {
                             factory = createObjectFactory(baseType, wireList.get(i));
                         }
@@ -246,7 +246,7 @@
                                     .getGenericType());
                             factory =
                                 new CallableReferenceObjectFactory(businessInterface, component,
-                                                                   (RuntimeComponentReference)componentReference, null);
+                                                                   (RuntimeComponentReference)componentReference, wireList.get(0).getEndpointReference());
                         } else {
                             factory = createObjectFactory(element.getType(), wireList.get(0));
                         }



Mime
View raw message