You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2008/05/16 10:03:28 UTC

svn commit: r656959 [1/2] - in /incubator/tuscany/java/sca: itest/validation/ itest/validation/src/main/resources/NoMatchingBinding/ itest/validation/src/test/java/calculator/ modules/ modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ mod...

Author: slaws
Date: Fri May 16 01:03:27 2008
New Revision: 656959

URL: http://svn.apache.org/viewvc?rev=656959&view=rev
Log:
Turn on the Endpoint functionality

Added:
    incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/
    incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite   (with props)
    incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java   (with props)
    incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java   (with props)
    incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java   (with props)
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java   (with props)
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java   (with props)
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java   (with props)
Modified:
    incubator/tuscany/java/sca/itest/validation/pom.xml
    incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/XSDValidationTestCase.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties
    incubator/tuscany/java/sca/modules/binding-sca-axis2/pom.xml
    incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java
    incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
    incubator/tuscany/java/sca/modules/host-embedded/pom.xml
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java
    incubator/tuscany/java/sca/modules/pom.xml

Modified: incubator/tuscany/java/sca/itest/validation/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/validation/pom.xml?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/validation/pom.xml (original)
+++ incubator/tuscany/java/sca/itest/validation/pom.xml Fri May 16 01:03:27 2008
@@ -48,6 +48,13 @@
             <version>2.0-incubating-SNAPSHOT</version>
             <scope>runtime</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-ws-axis2</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>        
 
         <dependency>
             <groupId>junit</groupId>

Added: incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite (added)
+++ incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite Fri May 16 01:03:27 2008
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           targetNamespace="http://sample"
+           xmlns:sample="http://sample"
+           name="Calculator">
+
+    <component name="CalculatorServiceComponent">
+		<implementation.java class="calculator.CalculatorServiceImpl"/>
+        <reference name="addService" target="AddServiceComponent">
+            <binding.sca/>
+        </reference>
+        <reference name="subtractService" target="SubtractServiceComponent" />
+        <reference name="multiplyService" target="MultiplyServiceComponent" />
+        <reference name="divideService" target="DivideServiceComponent" />
+    </component>
+    
+    <component name="AddServiceComponent">
+        <implementation.java class="calculator.AddServiceImpl"/>
+        <service name="AddServiceImpl">
+            <binding.ws/>
+        </service>
+    </component>    
+
+    <component name="SubtractServiceComponent">
+        <implementation.java class="calculator.SubtractServiceImpl"/>
+    </component>
+
+    <component name="MultiplyServiceComponent">
+        <implementation.java class="calculator.MultiplyServiceImpl"/>
+    </component>
+
+    <component name="DivideServiceComponent">
+        <implementation.java class="calculator.DivideServiceImpl"/>
+    </component>
+
+</composite>

Propchange: incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/java/sca/itest/validation/src/main/resources/NoMatchingBinding/Calculator.composite
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java (added)
+++ incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java Fri May 16 01:03:27 2008
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package calculator;
+
+import java.io.File;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.impl.DefaultLoggingMonitorImpl;
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCANode2;
+import org.apache.tuscany.sca.node.SCANode2Factory;
+import org.apache.tuscany.sca.node.SCANode2Factory.SCAContribution;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class NoMatchingBindingTestCase extends TestCase {
+
+    private CalculatorService calculatorService;
+    private SCANode2 node;
+
+    @Override
+    protected void setUp() throws Exception {
+        try {
+            SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
+            node = nodeFactory.createSCANode(new File("src/main/resources/NoMatchingBinding/Calculator.composite").toURL().toString(),
+            		                 new SCAContribution("TestContribution", 
+            		                                     new File("src/main/resources/NoMatchingBinding").toURL().toString()));
+    
+            node.start();
+            calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
+        } catch (Exception ex){
+            // do nothing
+            return;
+        }
+        Assert.fail();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        node.stop();
+    }
+
+    public void testCalculator() throws Exception {
+        /*
+        ExtensionPointRegistry registry = ((NodeImpl)node).getExtensionPointRegistry();
+        UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+        MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+        Monitor monitor = monitorFactory.createMonitor();
+        Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem();
+        
+        assertNotNull(problem);
+        assertEquals("NoMatchingBinding", problem.getMessageId());
+        */
+ 
+    }
+}

Propchange: incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/NoMatchingBindingTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/XSDValidationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/XSDValidationTestCase.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/XSDValidationTestCase.java (original)
+++ incubator/tuscany/java/sca/itest/validation/src/test/java/calculator/XSDValidationTestCase.java Fri May 16 01:03:27 2008
@@ -20,6 +20,7 @@
 
 import java.io.File;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
@@ -33,6 +34,7 @@
 import org.apache.tuscany.sca.node.SCANode2Factory;
 import org.apache.tuscany.sca.node.SCANode2Factory.SCAContribution;
 import org.apache.tuscany.sca.node.impl.NodeImpl;
+import org.osoa.sca.ServiceRuntimeException;
 
 /**
  * This shows how to test the Calculator service component.
@@ -45,19 +47,29 @@
     @Override
     protected void setUp() throws Exception {
         SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
-        node = nodeFactory.createSCANode(new File("src/main/resources/XsdValidation/Calculator.composite").toURL().toString(),
-        		                 new SCAContribution("TestContribution", 
-        		                                     new File("src/main/resources/XsdValidation").toURL().toString()));
-        node.start();
-        calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
+        try {
+            node = nodeFactory.createSCANode(new File("src/main/resources/XsdValidation/Calculator.composite").toURL().toString(),
+            		                 new SCAContribution("TestContribution", 
+            		                                     new File("src/main/resources/XsdValidation").toURL().toString()));
+            node.start();
+            calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
+        } catch (Exception ex){
+            // do nothing
+            return;
+        }
+        Assert.fail();
     }
 
     @Override
     protected void tearDown() throws Exception {
-        node.stop();
+        if (node != null){
+            node.stop();
+        }
     }
 
+
     public void testCalculator() throws Exception {
+        /*
         ExtensionPointRegistry registry = ((NodeImpl)node).getExtensionPointRegistry();
         UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
         MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
@@ -66,5 +78,7 @@
 
         assertNotNull(problem);
         assertEquals("SchemaError", problem.getMessageId());
+        */
     }
+ 
 }

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java Fri May 16 01:03:27 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.sca.assembly;
 
+import java.util.List;
+
 
 
 /**
@@ -71,4 +73,11 @@
      */
     void setCallbackService(ComponentService callbackService);
     
+    /**
+     * Returns the endpoints implied by this reference.
+     * 
+     * @return the endpoints implied by this reference
+     */
+    List<Endpoint> getEndpoints();    
+    
 }

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java Fri May 16 01:03:27 2008
@@ -36,6 +36,8 @@
 import org.apache.tuscany.sca.assembly.CompositeReference;
 import org.apache.tuscany.sca.assembly.CompositeService;
 import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.assembly.Multiplicity;
 import org.apache.tuscany.sca.assembly.OperationsConfigurator;
@@ -44,6 +46,8 @@
 import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.assembly.Wire;
+import org.apache.tuscany.sca.assembly.builder.DefaultEndpointBuilder;
+import org.apache.tuscany.sca.assembly.builder.EndpointBuilder;
 import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
@@ -61,31 +65,17 @@
 
     private Monitor monitor;
     private AssemblyFactory assemblyFactory;
+    private EndpointFactory endpointFactory;
     private InterfaceContractMapper interfaceContractMapper;
+    private EndpointBuilder endpointBuilder;
     
-    //Represents a target component and service
-    private class Target {
-        Component component;
-        ComponentService service;
-        
-        Target(Component component, ComponentService service) {
-            this.component = component;
-            this.service = service;
-        }
-        
-        Component getComponent() {
-            return component;
-        }
-        
-        ComponentService getService() {
-            return service;
-        }
-    };
     
-    protected BaseWireBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+    protected BaseWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
         this.assemblyFactory = assemblyFactory;
+        this.endpointFactory = endpointFactory;
         this.interfaceContractMapper = interfaceContractMapper;
         this.monitor = monitor;
+        this.endpointBuilder = new DefaultEndpointBuilder(monitor);
         
     }
     
@@ -353,11 +343,12 @@
         }
     }
     
-    private List<Target> createComponentReferenceTargets(Composite composite,
-                                                         Map<String, Component> components,
-                                                         Map<String, ComponentService> componentServices,
-                                                         ComponentReference componentReference) {
-        List<Target> targets = new ArrayList<Target>();
+    private List<Endpoint> createComponentReferenceTargets(Composite composite,
+                                                           Map<String, Component> components,
+                                                           Map<String, ComponentService> componentServices,
+                                                          ComponentReference componentReference) {
+
+        List<Endpoint> endpoints = new ArrayList<Endpoint>();
         
         if (componentReference.getAutowire() == Boolean.TRUE) {
 
@@ -368,8 +359,16 @@
                 for (ComponentService targetComponentService : targetComponent.getServices()) {
                     if (componentReference.getInterfaceContract() == null ||
                         interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
-                        Target target = new Target(targetComponent, targetComponentService);
-                        targets.add(target);
+                        
+                        Endpoint endpoint = endpointFactory.createEndpoint();
+                        endpoint.setTargetName(targetComponent.getName());
+                        endpoint.setSourceComponent(null); // TODO - fixed up at start
+                        endpoint.setSourceComponentReference(componentReference);
+                        endpoint.setTargetComponent(targetComponent);
+                        endpoint.setTargetComponentService(targetComponentService);
+                        endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+                        endpoints.add(endpoint);
+                        
                         if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) {
                             break;
                         }
@@ -378,7 +377,7 @@
             }
             
             if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) {
-                if (targets.size() == 0) {
+                if (endpoints.size() == 0) {
                     warning("No target services found for the component reference to be autowired: " + componentReference
                                 .getName(),
                             componentReference);
@@ -408,8 +407,14 @@
                     if (componentReference.getInterfaceContract() == null ||
                         interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
 
-                        Target target = new Target(targetComponent, targetComponentService);
-                        targets.add(target);
+                        Endpoint endpoint = endpointFactory.createEndpoint();
+                        endpoint.setTargetName(targetComponent.getName());
+                        endpoint.setSourceComponent(null); // TODO - fixed up at start
+                        endpoint.setSourceComponentReference(componentReference);                        
+                        endpoint.setTargetComponent(targetComponent);
+                        endpoint.setTargetComponentService(targetComponentService);
+                        endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+                        endpoints.add(endpoint);
 
                         // mark the reference target as resolved. Used later when we are looking to 
                         // see if an sca binding is associated with a resolved target or not
@@ -422,6 +427,13 @@
                     // can be used for comparison when the target is resolved at runtime
                     componentService.getBindings().addAll(componentReference.getBindings());
                     
+                    Endpoint endpoint = endpointFactory.createEndpoint();
+                    endpoint.setTargetName(name);
+                    endpoint.setSourceComponent(null); // TODO - fixed up at start
+                    endpoint.setSourceComponentReference(componentReference);                    
+                    endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+                    endpoints.add(endpoint);
+                    
                     // The bindings will be cloned back into the reference when the 
                     // target is finally resolved. 
                     warning("ComponentReferenceTargetNotFound", composite, composite.getName().toString(), componentService.getName());
@@ -452,8 +464,14 @@
                     if (componentReference.getInterfaceContract() == null ||
                         interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
 
-                        Target target = new Target(targetComponent, targetComponentService);
-                        targets.add(target);
+                        Endpoint endpoint = endpointFactory.createEndpoint();
+                        endpoint.setTargetName(targetComponent.getName());
+                        endpoint.setSourceComponent(null); // TODO - fixed up at start
+                        endpoint.setSourceComponentReference(componentReference);                        
+                        endpoint.setTargetComponent(targetComponent);
+                        endpoint.setTargetComponentService(targetComponentService);
+                        endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+                        endpoints.add(endpoint);
                         
                         // mark the reference target as resolved. Used later when we are looking to 
                         // see if an sca binding is associated with a resolved target or not
@@ -473,11 +491,93 @@
                     // The bindings will be cloned back into the reference when the 
                     // target is finally resolved. 
                     
+                    Endpoint endpoint = endpointFactory.createEndpoint();
+                    endpoint.setTargetName(name);
+                    endpoint.setSourceComponent(null); // TODO - fixed up at start
+                    endpoint.setSourceComponentReference(componentReference);                    
+                    endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+                    endpoints.add(endpoint);                    
+                    
                     warning("Component reference target from component type not found, it might be a remote service: " + componentService.getName(), composite);
                 }
             }
+        } 
+            
+                
+        // if no endpoints have found so far retrieve any target names that are in binding URIs
+        if (endpoints.isEmpty()){
+            for (Binding binding : componentReference.getBindings()) {
+
+                String uri = binding.getURI();
+                
+                // user hasn't put a uri on the binding so it's not a target name
+                if (uri == null) {
+                    continue;
+                }
+                
+                // user might have put a local target name in the uri so get
+                // the path part and see if it refers to a target we know about
+                // - if it does the reference binding will be matched with a service binding
+                // - if it doesn't it is assumed to be an external reference 
+                uri = URI.create(uri).getPath();
+                
+                if (uri.startsWith("/")) {
+                    uri = uri.substring(1);
+                }
+                                               
+                // Resolve the target component and service
+                ComponentService targetComponentService = componentServices.get(uri);
+                Component targetComponent;
+                
+                int s = uri.indexOf('/');
+                if (s == -1) {
+                    targetComponent = components.get(uri);
+                } else {
+                    targetComponent = components.get(uri.substring(0, s));
+                }
+
+                // if the path of the binding URI matches a component in the 
+                // composite then configure an endpoint with this component as the target
+                // if not then the binding URI will be assumed to reference an external service
+                if (targetComponentService != null) {
+
+                    // Check that the target component service provides
+                    // a superset of the component reference interface
+                    if (componentReference.getInterfaceContract() == null ||
+                        interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+                        Endpoint endpoint = endpointFactory.createEndpoint();
+                        endpoint.setTargetName(targetComponent.getName());
+                        endpoint.setSourceComponent(null); // TODO - fixed up at start
+                        endpoint.setSourceComponentReference(componentReference);                        
+                        endpoint.setTargetComponent(targetComponent);
+                        endpoint.setTargetComponentService(targetComponentService);
+                        endpoint.getCandidateBindings().add(binding);
+                        endpoints.add(endpoint);                        
+                    } else {
+                        warning("ReferenceIncompatibleInterface",
+                                composite,
+                                composite.getName().toString(),
+                                componentReference.getName(),
+                                uri);
+                    }
+                } else {
+                    
+                    /* TODO - don't enable this yet as we have tests that 
+                              use relative URIs in bindings that don't refer to 
+                              targets 
+                    Endpoint endpoint = endpointFactory.createEndpoint();
+                    endpoint.setTargetName(uri);
+                    endpoint.setSourceComponent(null); // TODO - fixed up at start
+                    endpoint.setSourceComponentReference(componentReference);                        
+                    endpoint.getCandidateBindings().add(binding);
+                    endpoints.add(endpoint); 
+                    */
+                }
+            }
         }
-        return targets;
+
+        return endpoints;
     }
 
 
@@ -492,23 +592,61 @@
     private void connectComponentReferences(Composite composite,
                                             Map<String, Component> components,
                                             Map<String, ComponentService> componentServices,
-                                            Map<String, ComponentReference> componentReferences) {
+                                            Map<String, ComponentReference> componentReferences){
+               
         for (ComponentReference componentReference : componentReferences.values()) {
             
-            List<Target> targets = createComponentReferenceTargets(composite, 
-                                                                   components, 
-                                                                   componentServices, 
-                                                                   componentReference);
+            List<Endpoint> endpoints = createComponentReferenceTargets(composite, 
+                                                                       components, 
+                                                                       componentServices, 
+                                                                       componentReference);
 
+            componentReference.getEndpoints().addAll(endpoints);
+            
+            // build each endpoint 
+            if (!endpoints.isEmpty()) { 
+
+                for(Endpoint endpoint : endpoints){
+                    endpointBuilder.build(endpoint);
+                }
+                
+                // TODO - The following step ensures that the reference binding list remains 
+                //        as the record of resolved targets for now. This needs fixing so 
+                //        that the endpoint takes on this responsibility. 
+                componentReference.getBindings().clear();
+                
+                if (componentReference.getCallback() != null){
+                    componentReference.getCallback().getBindings().clear();
+                }
+                
+                for(Endpoint endpoint : endpoints){
+                    if (endpoint.isUnresolved() == false){
+                        componentReference.getBindings().add(endpoint.getSourceBinding());
+                        
+                        if (componentReference.getCallback() != null){
+                            componentReference.getCallback().getBindings().add(endpoint.getSourceCallbackBinding());
+                        }
+                    } 
+                }                
+                
+            } else {
+                // do nothing as no targets have been specified so the bindings
+                // in the reference binding list are assumed to be manually configured
+            }
+                
+            
+/*            
             // Select the reference bindings matching the target service bindings 
             List<Binding> selectedBindings = new ArrayList<Binding>();
+            List<Binding> selectedCallbackBindings = null;
     
             // Handle callback
             boolean bidirectional = false;
+            
             if (componentReference.getInterfaceContract() != null && componentReference.getInterfaceContract().getCallbackInterface() != null) {
                 bidirectional = true;
+                selectedCallbackBindings = new ArrayList<Binding>();
             }
-            List<Binding> selectedCallbackBindings = bidirectional ? new ArrayList<Binding>() : null;
     
             for (Target target : targets) {
                 
@@ -530,7 +668,7 @@
                 // Match the binding against the bindings of the target service
                 Binding selected = BindingConfigurationUtil.resolveBindings(componentReference, targetComponent, targetComponentService);
                 if (selected == null) {
-                    warning("Component reference doesn't have a matching binding", componentReference);
+                    warning("NoMatchingBinding", componentReference, componentReference.getName(), targetComponentService.getName());
                 } else {
                     selectedBindings.add(selected);
                 }
@@ -541,7 +679,7 @@
                     }
                 }
             }
-                       
+*/                       
             
             // Need to tidy up the reference binding list and add in the bindings that 
             // have been selected above. The situation so far...
@@ -553,7 +691,8 @@
             //    Unwired reference (0 targets)
             //       Binding.uri = null  - Either a callback reference or the reference is yet to be wired
             //                             by the implementation so leave the binding where it is
-            //       Binding.uri != null - from the composite file so leave it             
+            //       Binding.uri != null - from the composite file so leave it  
+/*            
             if ((componentReference.getTargets().size() > 0) ||
                 (!targets.isEmpty())) {
 
@@ -602,9 +741,11 @@
                     }
                 }
             }
-            
+
+*/            
             // Connect the optimizable bindings to their target component and
             // service
+/*            
             for (Binding binding : componentReference.getBindings()) {
                 if (!(binding instanceof OptimizableBinding)) {
                     continue;
@@ -651,6 +792,7 @@
                     optimizableBinding.setTargetBinding(targetComponentService.getBinding(optimizableBinding.getClass()));
                 }
             }
+*/             
         }
     }
 

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java Fri May 16 01:03:27 2008
@@ -58,7 +58,7 @@
     }
     
     
-    static Binding matchBinding(Component component, ComponentService service, List<Binding> source, List<Binding> target) {
+    static Binding matchBinding(Component targetComponent, ComponentService targetComponentService, List<Binding> source, List<Binding> target) {
         List<Binding> matched = new ArrayList<Binding>();
         // Find the corresponding bindings from the service side
         for (Binding binding : source) {
@@ -71,8 +71,8 @@
                         
                         //Customise the binding name to make it unique 
                         // regardless of how many bindings or targets there are
-                        if ( component != null){
-                            cloned.setName(binding.getName() + "#" + component.getName() + "/" + serviceBinding.getName());
+                        if ( targetComponent != null){
+                            cloned.setName(binding.getName() + "#" + targetComponent.getName() + "/" + serviceBinding.getName());
                         } else {
                             cloned.setName(binding.getName() + "#" + serviceBinding.getName());
                         }
@@ -85,8 +85,8 @@
                         
                         if (binding instanceof OptimizableBinding) {
                             OptimizableBinding endpoint = ((OptimizableBinding)cloned);
-                            endpoint.setTargetComponent(component);
-                            endpoint.setTargetComponentService(service);
+                            endpoint.setTargetComponent(targetComponent);
+                            endpoint.setTargetComponentService(targetComponentService);
                             endpoint.setTargetBinding(serviceBinding);
                         } 
                            
@@ -141,4 +141,6 @@
     
         return matchBinding(component, service, source, target);
     }
+    
+  
 }

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java Fri May 16 01:03:27 2008
@@ -21,6 +21,7 @@
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
 import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
@@ -34,8 +35,8 @@
  */
 public class ComponentReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
 
-    public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
-        super(assemblyFactory, interfaceContractMapper, monitor);
+    public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+        super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
     }
 
     public void build(Composite composite) throws CompositeBuilderException {

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java Fri May 16 01:03:27 2008
@@ -23,6 +23,8 @@
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultEndpointFactory;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
@@ -62,7 +64,7 @@
                                 IntentAttachPointTypeFactory  intentAttachPointTypeFactory,
                                 InterfaceContractMapper interfaceContractMapper,
                                 Monitor monitor) {
-        this(assemblyFactory, scaBindingFactory, intentAttachPointTypeFactory, interfaceContractMapper, null, monitor);
+        this(assemblyFactory, null, scaBindingFactory,  intentAttachPointTypeFactory, interfaceContractMapper, null, monitor);
     }
     
     /**
@@ -70,18 +72,25 @@
      * 
      * @param assemblyFactory
      * @param scaBindingFactory
+     * @param endpointFactory
      * @param intentAttachPointTypeFactory
      * @param interfaceContractMapper
      * @param policyDefinitions
      * @param monitor
      */
     public CompositeBuilderImpl(AssemblyFactory assemblyFactory,
+                                EndpointFactory endpointFactory,
                                 SCABindingFactory scaBindingFactory,
                                 IntentAttachPointTypeFactory  intentAttachPointTypeFactory,
                                 InterfaceContractMapper interfaceContractMapper,
                                 SCADefinitions policyDefinitions,
                                 Monitor monitor) {
         
+        // TODO - why does this builder have two constructors
+        if (endpointFactory == null){
+            endpointFactory = new DefaultEndpointFactory();
+        }
+        
         if (monitor == null){
             monitor = new Monitor () {
                 public void problem(Problem problem) {
@@ -107,9 +116,10 @@
             };
         }
         
+        
         compositeIncludeBuilder = new CompositeIncludeBuilderImpl(monitor); 
-        componentWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, interfaceContractMapper, monitor);
-        compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, interfaceContractMapper, monitor);
+        componentWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+        compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
         compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor);
         componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);
         compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor);

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java Fri May 16 01:03:27 2008
@@ -21,6 +21,7 @@
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
@@ -33,8 +34,8 @@
  */
 public class CompositeReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
 
-    public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
-        super(assemblyFactory, interfaceContractMapper, monitor);
+    public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+        super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
     }
 
     public void build(Composite composite) throws CompositeBuilderException {

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java Fri May 16 01:03:27 2008
@@ -22,9 +22,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.assembly.Reference;
 
 /**
@@ -37,6 +39,7 @@
     private Boolean autowire;
     private List<CompositeReference> promotedAs = new ArrayList<CompositeReference>();
     private ComponentService callbackService;
+    private List<Endpoint> endpoints = new ArrayList<Endpoint>();
 
     /**
      * Constructs a new component reference.
@@ -83,4 +86,7 @@
         this.callbackService = callbackService;
     }
     
+    public List<Endpoint> getEndpoints(){
+        return endpoints;
+    }
 }

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties Fri May 16 01:03:27 2008
@@ -40,4 +40,6 @@
 PromotedReferenceNotFound = Promoted component reference not found: Composite = {0} Reference = {1}
 PromotedServiceNotFound = Promoted component service not found: Composite = {0} Service = {1}
 ComponentReferenceTargetNotFound = Component reference target not found, it might be a remote service running elsewhere in the SCA Domain: Composite = {0} Service = {1}
-NoSCABindingAvailableForUnresolvedService = A local service cannot be found for reference {0} target {1} and there is no SCA binding available to represent the unresolved target
\ No newline at end of file
+NoSCABindingAvailableForUnresolvedService = A local service cannot be found for reference {0} target {1} and there is no SCA binding available to represent the unresolved target
+NoMatchingBinding = Component reference {0} does not have a binding which matches the bindings of service {1}
+NoMatchingCallbackBinding = Component reference {0} does not have a callback binding which matches the callback bindings of service {1}
\ No newline at end of file

Modified: incubator/tuscany/java/sca/modules/binding-sca-axis2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-axis2/pom.xml?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-axis2/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/binding-sca-axis2/pom.xml Fri May 16 01:03:27 2008
@@ -77,12 +77,20 @@
             <artifactId>tuscany-implementation-java-runtime</artifactId>
             <version>2.0-incubating-SNAPSHOT</version>
             <scope>test</scope>
-        </dependency>        
+        </dependency> 
+               
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-interface-wsdl-java2wsdl</artifactId>
             <version>2.0-incubating-SNAPSHOT</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-endpoint</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>         
 
     </dependencies>
 

Modified: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java Fri May 16 01:03:27 2008
@@ -20,7 +20,12 @@
 
 import junit.framework.Assert;
 
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldClient;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -62,19 +67,19 @@
         Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred");
         
     }
-    
+        
     @Test
-    public void testHelloWorldRemote() throws Exception {  
+    public void testHelloWorldRemote() throws Exception { 
+        
         HelloWorldClient helloWorldClientA;
         helloWorldClientA = nodeA.getService(HelloWorldClient.class, "AHelloWorldClientRemote");
+        
         try {
             helloWorldClientA.getGreetings("fred");
         } catch (ServiceUnavailableException ex){
-            return;
+            Assert.fail(); 
         }
-        Assert.fail();
-        
-    }    
+    }     
     
     @Test
     public void testHelloWorldLocalAndRemote() throws Exception {

Added: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java (added)
+++ incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java Fri May 16 01:03:27 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.binding.sca.axis2;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.EndpointProviderFactory;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * The factory for creating endpoint Binding providers
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TestEndpointProviderFactoryImpl implements EndpointProviderFactory<Endpoint> {
+    
+    private ExtensionPointRegistry extensionPoints;
+    
+    public TestEndpointProviderFactoryImpl(ExtensionPointRegistry extensionPoints) {
+        this.extensionPoints = extensionPoints;     
+    } 
+    
+    public EndpointProvider createEndpointProvider(Endpoint endpoint) {
+              
+        return  new TestEndpointProviderImpl(extensionPoints, endpoint);
+    }
+
+    public Class<Endpoint> getModelType() {
+        return Endpoint.class;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderFactoryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java (added)
+++ incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java Fri May 16 01:03:27 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.binding.sca.axis2;
+
+import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.ComponentContextImpl;
+import org.apache.tuscany.sca.endpoint.impl.EndpointProviderImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+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.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceUnavailableException;
+
+/** 
+ * The endpoint binding provider allows unresolved endpoints to be plumbed into
+ * the runtime start and message send processing as a hook to late resolution
+ * of target services
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TestEndpointProviderImpl extends EndpointProviderImpl {
+
+    private final static Logger logger = Logger.getLogger(TestEndpointProviderImpl.class.getName());
+
+    private Endpoint endpoint;
+    private int startedCount = 0;
+    
+    public TestEndpointProviderImpl(ExtensionPointRegistry extensionPoints,
+                                    Endpoint endpoint) {
+        super(extensionPoints, endpoint);    
+        this.endpoint = endpoint;
+    }
+        
+    public void start() {
+        if (endpoint.isUnresolved()){
+            
+            if (startedCount == 1) {
+                // pretend to resolve the endpoint. In this test case to what we know 
+                // it should be
+                logger.info("Fixing up endpoint soure binding");
+                endpoint.setSourceBinding(endpoint.getCandidateBindings().get(0));
+                endpoint.getSourceBinding().setURI("http://localhost:8085/BHelloWorldServiceRemote");
+            } else {
+                startedCount++;
+            }
+        }
+    }   
+    
+}

Propchange: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestEndpointProviderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java (original)
+++ incubator/tuscany/java/sca/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java Fri May 16 01:03:27 2008
@@ -29,6 +29,7 @@
 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.Endpoint;
 import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.xml.Constants;
@@ -40,6 +41,8 @@
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.node.NodeException;
+import org.apache.tuscany.sca.provider.EndpointProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -73,7 +76,7 @@
             // create and start domainA
             nodeRuntime = new ReallySmallRuntime(cl);
             nodeRuntime.start();
-            
+                        
             // Create an in-memory domain level composite
             AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
             nodeComposite = assemblyFactory.createComposite();
@@ -85,6 +88,13 @@
 
             // add a contribution to the domain
             ContributionService contributionService = nodeRuntime.getContributionService();
+            
+            // fix up the endpoint provider for testing purposes
+            logger.info("Fixing up endpoint provider factory");
+            ProviderFactoryExtensionPoint providerFactories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ProviderFactoryExtensionPoint.class);
+            EndpointProviderFactory providerFactory =(EndpointProviderFactory)providerFactories.getProviderFactory(Endpoint.class);            
+            providerFactories.removeProviderFactory(providerFactory);
+            providerFactories.addProviderFactory(new TestEndpointProviderFactoryImpl(nodeRuntime.getExtensionPointRegistry()));            
 
             // find the current directory as a URL. This is where our contribution 
             // will come from
@@ -125,8 +135,7 @@
         } catch(Exception ex) {
             throw new NodeException(ex);
         }
-    }
-    
+    }   
     
     public <B> B getService(Class<B> businessInterface, String serviceName) {
         ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);

Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java Fri May 16 01:03:27 2008
@@ -27,6 +27,7 @@
 import java.util.Set;
 
 import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
@@ -110,6 +111,7 @@
         if (loaded)
             return;
 
+        loadProviderFactories(EndpointProviderFactory.class);
         loadProviderFactories(BindingProviderFactory.class);
         loadProviderFactories(ImplementationProviderFactory.class);
         loadProviderFactories(PolicyProviderFactory.class);
@@ -171,7 +173,15 @@
                     new LazyPolicyProviderFactory(registry, modelTypeName, factoryDeclaration);
                 factoryExtensionPoint.addProviderFactory(factory);
                 factories.add(factory);
+            } else if (factoryClass == EndpointProviderFactory.class) {
+                // Load a policy provider factory
+                String modelTypeName = attributes.get("model");
 
+                // Create a provider factory wrapper and register it
+                EndpointProviderFactory factory =
+                    new LazyEndpointProviderFactory(registry, modelTypeName, factoryDeclaration);
+                factoryExtensionPoint.addProviderFactory(factory);
+                factories.add(factory);
             }
         }
         return factories;
@@ -359,5 +369,56 @@
         }
 
     }
+    
+    /**
+     * A wrapper around an endpoint provider factory allowing lazy
+     * loading and initialization of endpoint providers.
+     */
+    private class LazyEndpointProviderFactory implements EndpointProviderFactory {
+        private ExtensionPointRegistry registry;
+        private String modelTypeName;
+        private ServiceDeclaration providerClass;
+        private EndpointProviderFactory factory;
+        private Class modelType;
+
+        private LazyEndpointProviderFactory(ExtensionPointRegistry registry,
+                                            String modelTypeName,
+                                            ServiceDeclaration providerClass) {
+            this.registry = registry;
+            this.modelTypeName = modelTypeName;
+            this.providerClass = providerClass;
+        }
+
+        @SuppressWarnings("unchecked")
+        private EndpointProviderFactory getFactory() {
+            if (factory == null) {
+                try {
+                    Class<EndpointProviderFactory> factoryClass = (Class<EndpointProviderFactory>)providerClass.loadClass();
+                    Constructor<EndpointProviderFactory> constructor =
+                        factoryClass.getConstructor(ExtensionPointRegistry.class);
+                    factory = constructor.newInstance(registry);
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return factory;
+        }
+
+        public EndpointProvider createEndpointProvider(Endpoint endpoint) {
+            return getFactory().createEndpointProvider(endpoint);
+        }
+
+        public Class getModelType() {
+            if (modelType == null) {
+                try {
+                    modelType = providerClass.loadClass(modelTypeName);
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return modelType;
+        }
+
+    }    
 
 }

Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java Fri May 16 01:03:27 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+
+/**
+ * A reference binding implementation can options implement this
+ * interface to tie into the Tuscany SCA runtime
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface EndpointProvider {
+
+    /**
+     * This method will be invoked when the endpoint is
+     * activated. The provider will attempt to resolve the 
+     * endpoint against available services. 
+     */
+    void start();
+
+    /**
+     * This method will be invoked when the endpont is
+     * deactivated.
+     */
+    void stop();
+
+}

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java?rev=656959&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java Fri May 16 01:03:27 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+
+/**
+ * A factory for creating the runtime artifacts that represent endpoints.
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface EndpointProviderFactory<M extends Endpoint> extends ProviderFactory<M> {
+
+    /**
+     * Creates a new endpoint provider for the given component and
+     * reference.
+     * 
+     * @param component The runtime component
+     * @param reference The reference on the runtime component
+     * @param enpoint The endpoint assembly model object
+     * @return The endpoint provider
+     */
+    EndpointProvider createEndpointProvider(M endpoint);
+}

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/EndpointProviderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java Fri May 16 01:03:27 2008
@@ -23,8 +23,10 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.EndpointProvider;
 import org.apache.tuscany.sca.provider.PolicyProvider;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 
@@ -70,6 +72,24 @@
     void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider);
     
     /**
+     * Returns the endpoint provider associated with this
+     * component reference and the given endpoint.
+     * 
+     * @param endpont The assembly model endpoint 
+     * @return The enpoint provider
+     */
+    EndpointProvider getEndpointProvider(Endpoint endpoint);
+    
+    /**
+     * Sets the endpoint provider associated with this
+     * component reference and the given endpoint.
+     * 
+     * @param binding The assembly model binding 
+     * @param bindingProvider The runtime reference binding provider
+     */
+    void setEndpointProvider(Endpoint endpoint, EndpointProvider endpointProvider);    
+    
+    /**
      * Add a policy provider for the given binding to the reference
      * @param binding The assembly model binding
      * @param policyProvider The policy handler

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java?rev=656959&r1=656958&r2=656959&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java Fri May 16 01:03:27 2008
@@ -32,6 +32,7 @@
 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.Endpoint;
 import org.apache.tuscany.sca.assembly.Implementation;
 import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.assembly.Reference;
@@ -53,6 +54,8 @@
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.invocation.MessageFactory;
 import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.EndpointProviderFactory;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
 import org.apache.tuscany.sca.provider.PolicyProvider;
@@ -138,6 +141,14 @@
         for (Binding binding : ref.getBindings()) {
             addReferenceBindingProvider(component, ref, binding);
         }
+        
+        for (Endpoint endpoint : ref.getEndpoints()){
+            // TODO - source component should be set in the builder but the 
+            //        way the builder is written it's difficult to get at it
+            endpoint.setSourceComponent(component);
+            
+            addEndpointProvider(component, ref, endpoint);
+        }
     }
 
     public void start(RuntimeComponent component, RuntimeComponentReference ref) {
@@ -153,12 +164,18 @@
                 }
                 addReferenceWire(component, ref, binding);
             }
+            
+            // targets now have an endpoint representation. We can use this to 
+            // look for unresolved endpoints using dummy wires for late resolution
+            for (Endpoint endpoint : ref.getEndpoints()){
+                addReferenceEndpointWire(component, ref, endpoint);
+            }
         }
     }
 
     public void stop(Component component, ComponentReference reference) {
         if (logger.isLoggable(Level.FINE)) {
-            logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
+            logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
         }
         RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
         for (Binding binding : reference.getBindings()) {
@@ -185,6 +202,56 @@
      * @param reference
      * @param binding
      */
+    private EndpointProvider addEndpointProvider(RuntimeComponent component,
+                                                 RuntimeComponentReference reference,
+                                                 Endpoint endpoint){
+        
+        // only create provides for unresolved endpoint currently
+        // this will also prevent a wire from being created later
+        if (!endpoint.isUnresolved()){
+            return null;
+        }
+        
+        EndpointProviderFactory providerFactory =
+            (EndpointProviderFactory)providerFactories.getProviderFactory(endpoint.getClass());
+        
+        if (providerFactory != null) {
+            @SuppressWarnings("unchecked")
+            EndpointProvider endpointProvider =
+                providerFactory.createEndpointProvider(endpoint);
+            if (endpointProvider != null) {
+                ((RuntimeComponentReference)reference).setEndpointProvider(endpoint, endpointProvider);
+            }
+            
+            /* TODO - should this get done here for endpoints or in the endpoint itself?
+            for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+                PolicyProvider policyProvider = f.createReferencePolicyProvider(component, reference, binding);
+                if (policyProvider != null) {
+                    reference.addPolicyProvider(binding, policyProvider);
+                }
+            }
+            */
+
+            return endpointProvider;
+        } else {
+            // TODO - for the time being allow the lack of an endpoint provider to be the 
+            //        switch to turn off endpoint processing
+            return null;
+            //throw new IllegalStateException("Endpoint provider factory not found for class: " + endpoint.getClass().getName());
+        }
+    }
+    
+    public void addReferenceBindingProviderForEndpoint(Endpoint endpoint){
+        addReferenceBindingProvider((RuntimeComponent)endpoint.getSourceComponent(),
+                                    (RuntimeComponentReference)endpoint.getSourceComponentReference(),
+                                    endpoint.getSourceBinding());
+    }
+
+    /**
+     * @param component
+     * @param reference
+     * @param binding
+     */
     private ReferenceBindingProvider addReferenceBindingProvider(RuntimeComponent component,
                                                                  RuntimeComponentReference reference,
                                                                  Binding binding) {
@@ -219,6 +286,32 @@
         // The code that used to be here to resolved unresolved targets is now 
         // at the bottom of BaseWireBuilder.connectComponentReferences()
     }
+    
+    /**
+     * Create the runtime wires for a reference endpoint. Currently this method
+     * only deals with the late binding case and creates a dummy wire that 
+     * will use the Endpoint to resolve the target at the point when the 
+     * wire chains are created.
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     */
+    private void addReferenceEndpointWire(Component component, ComponentReference reference, Endpoint endpoint) {
+        // only deal with unresolved endpoints as, to prevent breaking changes, targets that are resolved
+        // at build time are still represented as bindings in the binding list
+        if (((RuntimeComponentReference)reference).getEndpointProvider(endpoint) == null){ 
+            // no endpoint provider has previously been created so don't create the 
+            // wire
+            return;
+        }
+        
+        RuntimeWire wire = new EndpointWireImpl(endpoint, this);
+        
+        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+        runtimeRef.getRuntimeWires().add(wire);
+    }
+    
 
     /**
      * Create the runtime wires for a reference binding
@@ -231,11 +324,12 @@
         if (!(reference instanceof RuntimeComponentReference)) {
             return;
         }
-
+        
         // create wire if binding has an endpoint
         Component targetComponent = null;
         ComponentService targetComponentService = null;
         Binding targetBinding = null;
+    
         if (binding instanceof OptimizableBinding) {
             OptimizableBinding endpoint = (OptimizableBinding)binding;
             targetComponent = endpoint.getTargetComponent();
@@ -289,6 +383,14 @@
         */
     }
 
+    public void addReferenceWireForEndpoint(Endpoint endpoint){
+        addReferenceWire(endpoint.getSourceComponent(),
+                         endpoint.getSourceComponentReference(),
+                         endpoint.getSourceBinding(),
+                         endpoint.getTargetComponent(),
+                         endpoint.getTargetComponentService(),
+                         endpoint.getTargetBinding());
+    }
     /**
      * Create a reference wire for a forward call or a callback
      * @param reference
@@ -483,6 +585,21 @@
                     });                       
                 }
             }
+            for (Endpoint endpoint : reference.getEndpoints()) {
+                final EndpointProvider endpointProvider = runtimeRef.getEndpointProvider(endpoint);
+                if (endpointProvider != null) {
+                    // Allow endpoints to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+                    // TODO - do we need to allow this for endpoints. Leave as is for now
+                    //        doesn't seem to be done this way if a provider is started
+                    //        at wire creation time?
+                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                        public Object run() {
+                            endpointProvider.start();
+                            return null;
+                          }
+                    });                       
+                }
+            }
         }
 
         for (ComponentService service : component.getServices()) {
@@ -579,6 +696,21 @@
                     });                       
                 }
             }
+            for (Endpoint endpoint : reference.getEndpoints()) {
+                final EndpointProvider endpointProvider = runtimeRef.getEndpointProvider(endpoint);
+                if (endpointProvider != null) {
+                    // Allow endpoints to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+                    // TODO - do we need to allow this for endpoints. Leave as is for now
+                    //        doesn't seem to be done this way if a provider is started
+                    //        at wire creation time?
+                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                        public Object run() {
+                            endpointProvider.stop();
+                            return null;
+                          }
+                    });                       
+                }
+            }            
         }
         Implementation implementation = component.getImplementation();
         if (implementation instanceof Composite) {