tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r782804 - in /tuscany/java/sca/modules: assembly/src/main/java/org/apache/tuscany/sca/assembly/ assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ core-spi/src/main/java/org/apache/tuscany/sca/runtime/ core/src/main/java/org/apach...
Date Mon, 08 Jun 2009 21:50:12 GMT
Author: rfeng
Date: Mon Jun  8 21:50:12 2009
New Revision: 782804

URL: http://svn.apache.org/viewvc?rev=782804&view=rev
Log:
Move EndpointRegistry from assembly to core-spi
Add EndpointListener

Added:
    tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java
    tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java
    tuscany/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
      - copied unchanged from r782684, tuscany/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointRegistry
Removed:
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointRegistry.java
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointRegistryImpl.java
    tuscany/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointRegistry
Modified:
    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/endpoint/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
    tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
    tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java

Added: tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java?rev=782804&view=auto
==============================================================================
--- tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java (added)
+++ tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java Mon Jun  8 21:50:12 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.runtime;
+
+import java.util.EventListener;
+
+import org.apache.tuscany.sca.assembly.Endpoint2;
+
+/**
+ * A listener for endpoint events
+ */
+public interface EndpointListener extends EventListener {
+    /**
+     * The method is invoked when a new endpoint is added to the registry
+     * @param endpoint
+     */
+    void endpointAdded(Endpoint2 endpoint);
+    /**
+     * The method is invoked when an endpoint is removed the registry
+     * @param endpoint
+     */
+    void endpointRemoved(Endpoint2 endpoint);
+    /**
+     * The method is invoked when an endpoint is updated in the registry
+     * @param oldEndpoint
+     * @param newEndpoint
+     */
+    void endpointUpdated(Endpoint2 oldEndpoint, Endpoint2 newEndpoint);
+}

Added: tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java?rev=782804&view=auto
==============================================================================
--- tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java (added)
+++ tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java Mon Jun  8 21:50:12 2009
@@ -0,0 +1,48 @@
+/*
+ * 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.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
+
+/**
+ * The EndpointRegistry holds the active service endpoints for the SCA domain
+ */
+public interface EndpointRegistry {
+    void addEndpoint(Endpoint2 endpoint);
+    void removeEndpoint(Endpoint2 endpoint);
+
+    Endpoint2 getEndpoint(String uri);
+    void updateEndpoint(String uri, Endpoint2 endpoint);
+    List<Endpoint2> findEndpoint(EndpointReference2 endpointReference);
+    List<Endpoint2> getEndpoints();
+
+    void addEndpointReference(EndpointReference2 endpointReference);
+    void removeEndpointReference(EndpointReference2 endpointReference);
+    List<EndpointReference2> findEndpointReference(Endpoint2 endpoint);
+    List<EndpointReference2> getEndpointRefereneces();
+
+    void addListener(EndpointListener listener);
+    void removeListener(EndpointListener listener);
+    List<EndpointListener> getListeners();
+
+}

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=782804&r1=782803&r2=782804&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 21:50:12 2009
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.core.assembly.impl;
@@ -33,7 +33,6 @@
 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;
@@ -68,6 +67,7 @@
 import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -104,7 +104,7 @@
     private final CompositeContext compositeContext;
 
     private Composite domainComposite;
-    
+
     public CompositeActivatorImpl2(ExtensionPointRegistry extensionPoints) {
         this.extensionPoints = extensionPoints;
         this.compositeContext = new CompositeContextImpl(extensionPoints);
@@ -130,9 +130,9 @@
     //=========================================================================
     // Activation
     //=========================================================================
-    
+
     // Composite activation/deactivation
-    
+
     public void activate(Composite composite) throws ActivationException {
         try {
             if (logger.isLoggable(Level.FINE)) {
@@ -158,9 +158,9 @@
             throw new ActivationException(e);
         }
     }
-    
+
     // Component activation/deactivation
-    
+
     public void activateComponent(Component component)
             throws ActivationException {
         try {
@@ -190,7 +190,7 @@
             throw new ActivationException(e);
         }
     }
-   
+
     public void deactivateComponent(Component component)
             throws ActivationException {
         try {
@@ -217,10 +217,10 @@
         } catch (Exception e) {
             throw new ActivationException(e);
         }
-    }      
-    
+    }
+
     // add/remove artifacts required to get the implementation going
-    
+
     private void addImplementationProvider(RuntimeComponent component, Implementation implementation) {
         ImplementationProviderFactory providerFactory =
             (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass());
@@ -241,14 +241,14 @@
                 component.addPolicyProvider(policyProvider);
             }
         }
-        
+
     }
 
     private void removeImplementationProvider(RuntimeComponent component) {
         component.setImplementationProvider(null);
         component.getPolicyProviders().clear();
     }
-    
+
     private void addScopeContainer(Component component) {
         if (!(component instanceof ScopedRuntimeComponent)) {
             return;
@@ -269,13 +269,13 @@
         ScopeContainer scopeContainer = runtimeComponent.getScopeContainer();
         if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
             conversationManager.removeListener((ConversationalScopeContainer) scopeContainer);
-        }        
+        }
         runtimeComponent.setScopeContainer(null);
     }
-    
-    
+
+
     // Service activation/deactivation
-    
+
     public void activate(RuntimeComponent component, RuntimeComponentService service) {
         if (service.getService() == null) {
             if (logger.isLoggable(Level.WARNING)) {
@@ -285,14 +285,14 @@
             }
             return;
         }
-        
-        /* TODO - EPR - activate services at all levels as promoted endpoin references are maintained 
-         *              on the higher level services 
+
+        /* TODO - EPR - activate services at all levels as promoted endpoin references are maintained
+         *              on the higher level services
         if (service.getService() instanceof CompositeService) {
             return;
         }
         */
-        
+
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Activating component service: " + component.getURI() + "#" + service.getName());
         }
@@ -312,7 +312,7 @@
             removeServiceBindingProvider(component, service, binding);
         }
     }
-    
+
     private ServiceBindingProvider addServiceBindingProvider(
             RuntimeComponent component, RuntimeComponentService service,
             Binding binding) {
@@ -358,18 +358,18 @@
         if (!(service instanceof RuntimeComponentService)) {
             return;
         }
-        
+
         RuntimeComponentService runtimeService = (RuntimeComponentService)service;
 
         // Add a wire for each service Endpoint
         for ( Endpoint2 endpoint : runtimeService.getEndpoints()){
-            
+
             // fluff up a fake endpoint reference as we are on the service side
             // so we need to represent the reference that will call us
             EndpointReference2 endpointReference = assemblyFactory.createEndpointReference();
             endpointReference.setBinding(endpoint.getBinding());
             endpointReference.setTargetEndpoint(endpoint);
-            
+
             // create the interface contract for the binding and service ends of the wire
             // that are created as forward only contracts
             // FIXME: [rfeng] We might need a better way to get the impl interface contract
@@ -379,30 +379,30 @@
             }
             endpoint.setInterfaceContract(targetService.getInterfaceContract().makeUnidirectional(false));
             endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding()));
-            
+
             // create the wire
             RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
-                                                    false, 
-                                                    endpointReference, 
-                                                    endpoint, 
-                                                    interfaceContractMapper, 
-                                                    workScheduler, 
+                                                    false,
+                                                    endpointReference,
+                                                    endpoint,
+                                                    interfaceContractMapper,
+                                                    workScheduler,
                                                     wireProcessor,
-                                                    messageFactory, 
+                                                    messageFactory,
                                                     conversationManager);
-            
+
             runtimeService.getRuntimeWires().add(wire);
         }
-    }  
-    
+    }
+
     private void removeServiceWires(ComponentService service) {
         if (!(service instanceof RuntimeComponentService)) {
             return;
         }
         RuntimeComponentService runtimeService = (RuntimeComponentService)service;
         runtimeService.getRuntimeWires().clear();
-    }    
-    
+    }
+
     private InterfaceContract getServiceBindingInterfaceContract(ComponentService service, Binding binding) {
         InterfaceContract interfaceContract = service.getInterfaceContract();
 
@@ -415,22 +415,22 @@
         }
         return interfaceContract.makeUnidirectional(false);
     }
-    
+
     // Reference activation/deactivation
-    
+
     public void activate(RuntimeComponent component, RuntimeComponentReference reference) {
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName());
         }
-       
-        // set the parent component onto the reference. It's used at start time when the 
+
+        // 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
         reference.setComponent(component);
-        
+
         // TODO reference wires are added at component start for some reason
-    }    
-    
+    }
+
     public void deactivate(RuntimeComponent component, RuntimeComponentReference reference) {
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Deactivating component reference: " + component.getURI() + "#" + reference.getName());
@@ -441,8 +441,8 @@
                 removeReferenceBindingProvider(component, reference, endpointReference.getBinding());
             }
         }
-    }  
-/*    
+    }
+/*
     private ReferenceBindingProvider addReferenceBindingProvider(
             RuntimeComponent component, RuntimeComponentReference reference,
             Binding binding) {
@@ -475,7 +475,7 @@
                             + binding.getClass().getName());
         }
     }
-*/    
+*/
     private void removeReferenceBindingProvider(RuntimeComponent component,
             RuntimeComponentReference reference, Binding binding) {
         reference.setBindingProvider(binding, null);
@@ -486,24 +486,24 @@
             }
         }
     }
-    
+
     private void removeReferenceWires(ComponentReference reference) {
         if (!(reference instanceof RuntimeComponentReference)) {
             return;
         }
-        
+
         // TODO - EPR what is this all about?
         // [rfeng] Comment out the following statements to avoid the on-demand activation
         // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
         // runtimeRef.getRuntimeWires().clear();
     }
-    
+
     //=========================================================================
     // Start
     //=========================================================================
-    
+
     // Composite start/stop
-    
+
     public void start(Composite composite) {
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Starting composite: " + composite.getName());
@@ -521,9 +521,9 @@
             stop(component);
         }
     }
-    
+
     // Component start/stop
-    
+
     public void start(Component component) {
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("Starting component: " + component.getURI());
@@ -532,9 +532,9 @@
         if(runtimeComponent.isStarted()) {
             return;
         }
-        
+
         configureComponentContext(runtimeComponent);
-        
+
         // Reference bindings aren't started until the wire is first used
 
         for (ComponentService service : component.getServices()) {
@@ -547,13 +547,13 @@
                 final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
                 if (bindingProvider != null) {
                     // bindingProvider.start();
-                    // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. 
+                    // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
                     AccessController.doPrivileged(new PrivilegedAction<Object>() {
                         public Object run() {
                             bindingProvider.start();
                             return null;
                           }
-                    });                       
+                    });
                 }
             }
         }
@@ -593,13 +593,13 @@
                 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. 
+                    // Allow bindings to read properties. Requires PropertyPermission read in security policy.
                     AccessController.doPrivileged(new PrivilegedAction<Object>() {
                         public Object run() {
                             bindingProvider.stop();
                             return null;
                           }
-                    });                       
+                    });
                 }
             }
         }
@@ -608,19 +608,19 @@
                 logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
             }
             RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
-            
+
             for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
                 final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
                 if (bindingProvider != null) {
-                    // Allow bindings to read properties. Requires PropertyPermission read in security policy. 
+                    // Allow bindings to read properties. Requires PropertyPermission read in security policy.
                     AccessController.doPrivileged(new PrivilegedAction<Object>() {
                         public Object run() {
                             bindingProvider.stop();
                             return null;
                           }
-                    });                       
+                    });
                 }
-            }              
+            }
         }
         Implementation implementation = component.getImplementation();
         if (implementation instanceof Composite) {
@@ -628,19 +628,19 @@
         } else {
             final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
             if (implementationProvider != null) {
-                // Allow bindings to read properties. Requires PropertyPermission read in security policy. 
+                // Allow bindings to read properties. Requires PropertyPermission read in security policy.
                 AccessController.doPrivileged(new PrivilegedAction<Object>() {
                     public Object run() {
                         implementationProvider.stop();
                         return null;
                       }
-                });                       
+                });
             }
         }
 
         if (component instanceof ScopedRuntimeComponent) {
             ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
-            if (runtimeComponent.getScopeContainer() != null && 
+            if (runtimeComponent.getScopeContainer() != null &&
                     runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) {
                 runtimeComponent.getScopeContainer().stop();
             }
@@ -648,79 +648,79 @@
 
         ((RuntimeComponent)component).setStarted(false);
     }
-    
+
     public void configureComponentContext(RuntimeComponent runtimeComponent) {
         RuntimeComponentContext componentContext = (RuntimeComponentContext) componentContextFactory.createComponentContext(runtimeComponent);
         runtimeComponent.setComponentContext(componentContext);
-    }    
-    
+    }
+
     // Service start/stop
-    
+
     // TODO - EPR done as part of the component start above
-    
+
     // Reference start/stop
     // Used by component context start
     // TODO - EPR I don't know why reference wires don't get added until component start
-    
+
     public void start(RuntimeComponent component, RuntimeComponentReference componentReference) {
         synchronized (componentReference) {
-            
+
             if (!(componentReference instanceof RuntimeComponentReference)) {
                 return;
             }
-            
-            /* The way it was 
+
+            /* 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 
-            // is deployed, but it is expected to be found. In the case where the reference 
-            // is unwired (a target has not been specified) there will be no endpoint 
+            // The service may not have been found yet, depending on the way the composite
+            // is deployed, but it is expected to be found. In the case where the reference
+            // is unwired (a target has not been specified) there will be no endpoint
             // reference and this will lead to null being injected
             for (EndpointReference2 endpointReference : componentReference.getEndpointReferences()){
-                
+
                 // if there is a binding an endpoint has been found for the endpoint reference
                 if (endpointReference.getBinding() != null){
-                    
+
                     // add the binding provider. This is apparently a repeat
                     // of previous configuration as self references are created
                     // on the fly and miss the previous point where providers are added
                     RuntimeComponentReference runtimeRef = (RuntimeComponentReference)componentReference;
-                    
+
                     if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
                         addReferenceBindingProvider(component, componentReference, endpointReference.getBinding());
                     }
-                    
-                    // start the binding provider   
+
+                    // 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. 
+                        // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
                         AccessController.doPrivileged(new PrivilegedAction<Object>() {
                             public Object run() {
                                 bindingProvider.start();
                                 return null;
                               }
-                        });                       
+                        });
                     }
-                    
+
                     // add the wire
                     addReferenceWire(component, componentReference, endpointReference);
                 }
-            }   
+            }
             */
-            
-            // create a wire for each endpoint reference. An endpoint reference says either that 
+
+            // 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 
+            // 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);
             }
-            
+
         }
     }
 
@@ -737,10 +737,10 @@
             }
         }
     }
-    
+
     private void addReferenceWire(Component component, ComponentReference reference, EndpointReference2 endpointReference) {
         RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
-        
+
         // Use the interface contract of the reference on the component type and if there
         // isn't one then use the one from the reference itself
         Reference componentTypeRef = reference.getReference();
@@ -751,7 +751,7 @@
         } else {
             sourceContract = componentTypeRef.getInterfaceContract();
         }
-       
+
         // TODO - EPR - interface contract seems to be null in the implementation.web
         //              case. Not introspecting the CT properly?
         if (sourceContract == null){
@@ -760,7 +760,7 @@
             sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract();
             reference.setInterfaceContract(sourceContract);
         }
-        
+
         endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false));
 
 /* TODO - EPR should have been done previously during matching
@@ -787,36 +787,36 @@
         }
 */
 
-/* TODO - EPR can't do this until the binding matches the EPR        
+/* 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        
+
+/* 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
-        // nested composite. 
+        // nested composite.
         if (serviceBinding != null) {
             wireTarget.setURI(serviceBinding.getURI());
         }
-*/        
+*/
 
         // create the wire
-        // null endpoint passed in here as the endpoint reference may 
+        // null endpoint passed in here as the endpoint reference may
         // not be resolved yet
         RuntimeWire wire = new RuntimeWireImpl2(extensionPoints,
-                                                true, 
-                                                endpointReference, 
-                                                null, 
-                                                interfaceContractMapper, 
-                                                workScheduler, 
+                                                true,
+                                                endpointReference,
+                                                null,
+                                                interfaceContractMapper,
+                                                workScheduler,
                                                 wireProcessor,
-                                                messageFactory, 
+                                                messageFactory,
                                                 conversationManager);
         runtimeRef.getRuntimeWires().add(wire);
-        
+
     }
-    
+
     private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
         InterfaceContract interfaceContract = reference.getInterfaceContract();
         ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
@@ -827,13 +827,13 @@
             }
         }
         return interfaceContract.makeUnidirectional(false);
-    }    
-    
-    
-    
+    }
+
+
+
    // Utility functions
    // TODO - can we get rid of these?
-    
+
     public CompositeContext getCompositeContext() {
         return compositeContext;
     }
@@ -872,5 +872,5 @@
         }
         return null;
     }
-    
+
 }

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=782804&r1=782803&r2=782804&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 21:50:12 2009
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.core.assembly.impl;
@@ -29,10 +29,11 @@
 import org.apache.tuscany.sca.assembly.Component;
 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.CompositeService;
+import org.apache.tuscany.sca.assembly.Contract;
 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;
@@ -49,7 +50,6 @@
 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;
@@ -73,9 +73,9 @@
  * @version $Rev$ $Date$
  */
 public class RuntimeWireImpl2 implements RuntimeWire {
-    
+
     private ExtensionPointRegistry extensionPoints;
-    
+
     private Boolean isReferenceWire = false;
     private EndpointReference2 endpointReference;
     private Endpoint2 endpoint;
@@ -96,18 +96,18 @@
 
     private List<InvocationChain> chains;
     private InvocationChain bindingInvocationChain;
-    
+
     private EndpointReferenceBuilder endpointReferenceBuilder;
     private final ProviderFactoryExtensionPoint providerFactories;
 
     /**
      * @param source
      * @param target
-     * @param interfaceContractMapper 
-     * @param workScheduler 
-     * @param wireProcessor 
-     * @param messageFactory 
-     * @param conversationManager 
+     * @param interfaceContractMapper
+     * @param workScheduler
+     * @param wireProcessor
+     * @param messageFactory
+     * @param conversationManager
      */
     public RuntimeWireImpl2(ExtensionPointRegistry extensionPoints,
                             boolean isReferenceWire,
@@ -129,7 +129,7 @@
         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);
@@ -141,7 +141,7 @@
         }
         return chains;
     }
-    
+
     public synchronized InvocationChain getBindingInvocationChain() {
         if (bindingInvocationChain == null) {
             bindingInvocationChain = new InvocationChainImpl(null, null, isReferenceWire);
@@ -168,10 +168,10 @@
         }
         return null;
     }
-    
+
     public Object invoke(Message msg) throws InvocationTargetException {
         return getBindingInvocationChain().getHeadInvoker().invoke(msg);
-    }    
+    }
 
     public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
         Message msg = messageFactory.createMessage();
@@ -184,18 +184,71 @@
     }
 
     /**
+     * Navigate the component/componentType inheritence chain to find the leaf contract
+     * @param contract
+     * @return
+     */
+    private Contract getLeafContract(Contract contract) {
+        Contract prev = null;
+        Contract current = contract;
+        while (current != null) {
+            prev = current;
+            if (current instanceof ComponentReference) {
+                current = ((ComponentReference)current).getReference();
+            } else if (current instanceof CompositeReference) {
+                current = ((CompositeReference)current).getPromotedReferences().get(0);
+            } else if (current instanceof ComponentService) {
+                current = ((ComponentService)current).getService();
+            } else if (current instanceof CompositeService) {
+                current = ((CompositeService)current).getPromotedService();
+            } else {
+                break;
+            }
+            if (current == null) {
+                return prev;
+            }
+        }
+        return current;
+    }
+
+    private InterfaceContract getLeafInterfaceContract(EndpointReference2 epr) {
+        ComponentReference reference = epr.getReference();
+        if (reference == null) {
+            return epr.getInterfaceContract();
+        }
+        InterfaceContract interfaceContract = getLeafContract(reference).getInterfaceContract();
+        if (interfaceContract == null) {
+            interfaceContract = epr.getInterfaceContract();
+        }
+        return interfaceContract;
+    }
+
+    private InterfaceContract getLeafInterfaceContract(Endpoint2 ep) {
+        ComponentService service = ep.getService();
+        if (service == null) {
+            return ep.getInterfaceContract();
+        }
+        InterfaceContract interfaceContract = getLeafContract(service).getInterfaceContract();
+        if (interfaceContract == null) {
+            interfaceContract = ep.getInterfaceContract();
+        }
+        return interfaceContract;
+    }
+
+    /**
      * Initialize the invocation chains
      */
     private void initInvocationChains() {
-   
         chains = new ArrayList<InvocationChain>();
-        InterfaceContract sourceContract = endpointReference.getInterfaceContract();
+        //        InterfaceContract sourceContract = endpointReference.getInterfaceContract();
+        //        InterfaceContract targetContract = endpoint.getInterfaceContract();
+        InterfaceContract sourceContract = getLeafInterfaceContract(endpointReference);
 
         if (isReferenceWire) {
             // It's the reference wire
             resolveEndpointReference();
 
-            InterfaceContract targetContract = endpoint.getInterfaceContract();
+            InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
             RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
             Binding refBinding = endpointReference.getBinding();
             for (Operation operation : sourceContract.getInterface().getOperations()) {
@@ -214,13 +267,13 @@
                 addReferenceBindingInterceptor(reference, refBinding, chain, operation);
                 chains.add(chain);
             }
-            
+
         } else {
             // It's the service wire
-            InterfaceContract targetContract = endpoint.getInterfaceContract();
             RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
             RuntimeComponent serviceComponent = (RuntimeComponent)endpoint.getComponent();
             Binding serviceBinding = endpoint.getBinding();
+            InterfaceContract targetContract = getLeafInterfaceContract(endpoint);
             for (Operation operation : sourceContract.getInterface().getOperations()) {
                 Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
                 if (targetOperation == null) {
@@ -238,48 +291,49 @@
                 addImplementationInterceptor(serviceComponent, service, chain, targetOperation);
                 chains.add(chain);
             }
-            
+
         }
         wireProcessor.process(this);
     }
-    
+
+
     /**
-     * This code used to be in the activator but has moved here as 
+     * 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, 
+            addReferenceBindingProvider((RuntimeComponent)endpointReference.getComponent(),
+                    runtimeRef,
                     endpointReference.getBinding());
         }
-        
-        // start the binding provider   
+
+        // 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. 
+            // 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) {
@@ -311,8 +365,8 @@
                     "Provider factory not found for class: "
                             + binding.getClass().getName());
         }
-    }  
-    
+    }
+
     private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
         InterfaceContract interfaceContract = reference.getInterfaceContract();
         if (interfaceContract == null) {
@@ -326,19 +380,18 @@
             }
         }
         return interfaceContract.makeUnidirectional(false);
-    }     
-    
+    }
+
     private void initReferenceBindingInvocationChains() {
         RuntimeComponentReference reference = (RuntimeComponentReference)endpointReference.getReference();
         Binding referenceBinding = endpointReference.getBinding();
-        
+
         // add the binding interceptors to the reference binding wire
         ReferenceBindingProvider provider = reference.getBindingProvider(referenceBinding);
-        if ((provider != null) &&
-            (provider instanceof ReferenceBindingProviderRRB)){
+        if ((provider != null) && (provider instanceof ReferenceBindingProviderRRB)) {
             ((ReferenceBindingProviderRRB)provider).configureBindingChain(this);
         }
-        
+
         // add the policy interceptors to the service binding wire
         // find out which policies are active
         List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(referenceBinding);
@@ -351,20 +404,19 @@
                     }
                 }
             }
-        }               
-    }    
-    
+        }
+    }
+
     private void initServiceBindingInvocationChains() {
         RuntimeComponentService service = (RuntimeComponentService)endpoint.getService();
         Binding serviceBinding = endpoint.getBinding();
-        
+
         // add the binding interceptors to the service binding wire
         ServiceBindingProvider provider = service.getBindingProvider(serviceBinding);
-        if ((provider != null) &&
-            (provider instanceof ServiceBindingProviderRRB)){
+        if ((provider != null) && (provider instanceof ServiceBindingProviderRRB)) {
             ((ServiceBindingProviderRRB)provider).configureBindingChain(this);
         }
-        
+
         // add the policy interceptors to the service binding wire
         List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(serviceBinding);
         if (pps != null) {
@@ -376,59 +428,53 @@
                     }
                 }
             }
-        }        
-        
-        
-        // TODO - add something on the end of the wire to invoke the 
+        }
+
+        // TODO - add something on the end of the wire to invoke the
         //        invocation chain. Need to split out the runtime
         //        wire invoker into conversation, callback interceptors etc
         bindingInvocationChain.addInvoker(invoker);
-        
+
     }
 
     // ===============================================================
     // TODO - EPR remove when we convert fully over to EndpointReference2
-    
+
     // TODO - remove. Just here during development
     static EndpointReference epr;
-    
+
     public EndpointReference getSource() {
         // TODO - EPR convert this into method that returns EndpointReference2
-        
+
         // convert the source info into old endpoint reference format
-        epr = new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(),
-                                                          endpointReference.getReference(),
-                                                          endpointReference.getBinding(),
-                                                          endpointReference.getInterfaceContract());
-        
-        if (endpointReference.getCallbackEndpoint() != null){
+        epr =
+            new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+                .getReference(), endpointReference.getBinding(), endpointReference.getInterfaceContract());
+
+        if (endpointReference.getCallbackEndpoint() != null) {
             // convert the source callback endpoint into old endpoint reference format
             EndpointReference cepr;
-            cepr = new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(),
-                    endpointReference.getCallbackEndpoint().getService(),
-                    endpointReference.getCallbackEndpoint().getBinding(),
-                    endpointReference.getCallbackEndpoint().getInterfaceContract());
+            cepr =
+                new EndpointReferenceImpl((RuntimeComponent)endpointReference.getComponent(), endpointReference
+                    .getCallbackEndpoint().getService(), endpointReference.getCallbackEndpoint().getBinding(),
+                                          endpointReference.getCallbackEndpoint().getInterfaceContract());
             epr.setCallbackEndpoint(cepr);
         }
-        
-        
-        // TODO - somtimes used to reset the interface contract so we 
-        //        copy it back in in the rebuild method below  
+
+        // TODO - somtimes used to reset the interface contract so we
+        //        copy it back in in the rebuild method below
         return epr;
     }
 
-    
-    
     public EndpointReference getTarget() {
         // TODO - EPR convert this into method that returns Endpoint2
-        
+
         Endpoint2 endpoint = this.endpoint != null ? this.endpoint : endpointReference.getTargetEndpoint();
 
         // convert the target info into old endpoint reference format
-        EndpointReference epr = new EndpointReferenceImpl((RuntimeComponent)endpoint.getComponent(),
-                                                           endpoint.getService(),
-                                                           endpoint.getBinding(),
-                                                           endpoint.getInterfaceContract());
+        EndpointReference epr =
+            new EndpointReferenceImpl((RuntimeComponent)endpoint.getComponent(), endpoint.getService(), endpoint
+                .getBinding(), endpoint.getInterfaceContract());
         return epr;
     }
 
@@ -436,27 +482,27 @@
         // TODO - can we use the idea of setTarget to rebuild the wire?
 
     }
-    
+
     // ===================================================================
 
     public void rebuild() {
         // TODO - can we use the idea of setTarget to rebuild the wire?
-        //        used at the moment by binding.sca when it resets the 
+        //        used at the moment by binding.sca when it resets the
         //        source interface contract for local wires
         this.chains = null;
-        
+
         // TODO - cheating here as I fixed the RuntimeComponentService code
         //        to call this when it resets the interface contract
         endpointReference.setInterfaceContract(epr.getInterfaceContract());
     }
-    
-    public EndpointReference2 getEndpointReference(){
+
+    public EndpointReference2 getEndpointReference() {
         return endpointReference;
     }
 
     /**
      * Add the interceptor for a reference binding
-     * 
+     *
      * @param reference
      * @param binding
      * @param chain
@@ -486,7 +532,7 @@
 
     /**
      * Add the interceptor for a binding
-     * 
+     *
      * @param reference
      * @param binding
      * @param chain
@@ -509,7 +555,7 @@
 
     /**
      * Add a non-blocking interceptor if the reference binding needs it
-     * 
+     *
      * @param reference
      * @param binding
      * @param chain
@@ -542,7 +588,7 @@
 
     /**
      * Add the interceptor for a component implementation
-     * 
+     *
      * @param component
      * @param service
      * @param chain

Modified: tuscany/java/sca/modules/endpoint/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint/META-INF/MANIFEST.MF?rev=782804&r1=782803&r2=782804&view=diff
==============================================================================
--- tuscany/java/sca/modules/endpoint/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/endpoint/META-INF/MANIFEST.MF Mon Jun  8 21:50:12 2009
@@ -21,6 +21,7 @@
  org.apache.tuscany.sca.interfacedef;version="2.0.0";resolution:=optional,
  org.apache.tuscany.sca.monitor;version="2.0.0";resolution:=optional,
  org.apache.tuscany.sca.policy;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.runtime;version="2.0.0",
  org.oasisopen.sca;version="2.0.0",
  org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional
 Bundle-SymbolicName: org.apache.tuscany.sca.endpoint

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=782804&r1=782803&r2=782804&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 21:50:12 2009
@@ -6,34 +6,27 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.endpoint.impl;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.assembly.Component;
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ComponentService;
 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;
 import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
@@ -49,44 +42,45 @@
 import org.apache.tuscany.sca.monitor.Problem.Severity;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
 import org.oasisopen.sca.SCARuntimeException;
 
 /**
- * An builder that takes endpoint references and resolves them. It either finds local 
+ * An builder that takes endpoint references and resolves them. It either finds local
  * service endpoints if they are available or asks the domain. The main function here
- * is to perform binding and policy matching. 
+ * is to perform binding and policy matching.
  * This is a separate builder in case it is required by undresolved endpoints
- * once the runtime has started. 
- * 
+ * once the runtime has started.
+ *
  * @version $Rev$ $Date$
  */
 public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointReferenceBuilder {
-    
+
     protected ExtensionPointRegistry extensionPoints;
     protected AssemblyFactory assemblyFactory;
     protected InterfaceContractMapper interfaceContractMapper;
     protected EndpointRegistry endpointRegistry;
-    
-    
+
+
     public EndpointReferenceBuilderImpl(ExtensionPointRegistry extensionPoints) {
         this.extensionPoints = extensionPoints;
-        
+
         FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
         this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
-        
+
         UtilityExtensionPoint utils = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
         this.interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class);
-        
+
         this.endpointRegistry = utils.getUtility(EndpointRegistry.class);
     }
 
     public String getID() {
         return "org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder";
     }
-    
+
     /**
      * Report a warning.
-     * 
+     *
      * @param monitor
      * @param problems
      * @param message
@@ -98,10 +92,10 @@
             monitor.problem(problem);
         }
     }
-    
+
     /**
      * Report a error.
-     * 
+     *
      * @param monitor
      * @param problems
      * @param message
@@ -112,11 +106,11 @@
             Problem problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
             monitor.problem(problem);
         }
-    }  
-    
+    }
+
     /**
      * Report a exception.
-     * 
+     *
      * @param problems
      * @param message
      * @param model
@@ -127,21 +121,21 @@
             problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex);
             monitor.problem(problem);
         }
-    }    
+    }
 
     /**
      * Build all the endpoint references
-     * 
+     *
      * @param composite
      */
-    public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException 
+    public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException
     {
         // Not used now
     }
 
     /*
     private void populateEndpointRegistry(Composite composite, Monitor monitor) {
-        
+
         // register endpoints (and endpoint references) for each component
         for (Component component : composite.getComponents()) {
             // recurse for composite implementations
@@ -149,88 +143,88 @@
             if (implementation instanceof Composite) {
                 populateEndpointRegistry((Composite)implementation, monitor);
             }
-            
-            // register endpoints  
+
+            // register endpoints
             for (ComponentService service : component.getServices()) {
                 for (Endpoint2 endpoint : service.getEndpoints()){
                     endpointRegistry.addEndpoint(endpoint);
                 }
             }
-            
-            // register endpoint references  
+
+            // register endpoint references
             for (ComponentReference reference : component.getReferences()) {
                 for (EndpointReference2 endpointReference : reference.getEndpointReferences()){
                     endpointRegistry.addEndpointReference(endpointReference);
                 }
-            }            
+            }
         }
     }
     */
-    
+
     /**
      * Build a single endpoint reference
-     * 
+     *
      * @param endpoint
      * @param monitor
      */
     public void build(EndpointReference2 endpointReference, Monitor monitor) {
         Endpoint2 endpoint = endpointReference.getTargetEndpoint();
-      
+
         if (endpoint == null){
             // an error?
-        } else {          
+        } else {
             if (endpoint.isUnresolved() == false){
                 // Wired - service resolved - binding matched
                 // The service is in the same composite
                 return;
             }
-            
-            if (endpointReference.isUnresolved() == false ){  
-                // Wired - service resolved - binding not matched 
+
+            if (endpointReference.isUnresolved() == false ){
+                // Wired - service resolved - binding not matched
                 // The service is in the same composite
                 // TODO - How do we get to here?
-                matchForwardBinding(endpointReference, 
+                matchForwardBinding(endpointReference,
                                     monitor);
-                
-                matchCallbackBinding(endpointReference, 
+
+                matchCallbackBinding(endpointReference,
                                      monitor);
             } else {
                 // 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 
+
+                // 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, 
+
+                matchForwardBinding(endpointReference,
                         monitor);
-    
-                matchCallbackBinding(endpointReference, 
+
+                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 
-    //        reference side. 
+
+    // TODO - EPR - In OASIS case there are no bindings to match with on the
+    //        reference side.
     private void matchForwardBinding(EndpointReference2 endpointReference,
                                      Monitor monitor) {
-        
+
         Endpoint2 endpoint = endpointReference.getTargetEndpoint();
 
         List<Binding> matchedReferenceBinding = new ArrayList<Binding>();
@@ -240,7 +234,7 @@
         for (Binding referenceBinding : endpointReference.getReference().getBindings()) {
             for (Endpoint2 serviceEndpoint : endpoint.getService().getEndpoints()) {
 
-                if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() && 
+                if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() &&
                     hasCompatiblePolicySets(referenceBinding, serviceEndpoint.getBinding())) {
 
                     matchedReferenceBinding.add(referenceBinding);
@@ -253,10 +247,10 @@
             // No matching binding
             endpointReference.setBinding(null);
             endpointReference.setUnresolved(true);
-            warning(monitor, 
-                    "NoMatchingBinding", 
+            warning(monitor,
+                    "NoMatchingBinding",
                     endpointReference.getReference(),
-                    endpointReference.getReference().getName(), 
+                    endpointReference.getReference().getName(),
                     endpoint.getService().getName());
             return;
         } else {
@@ -283,7 +277,7 @@
                 if (referenceBinding.getURI() == null) {
                     clonedBinding.setURI(serviceEndpoint.getBinding().getURI());
                 }
-                
+
                 // TODO - EPR can we remove this?
                 if (clonedBinding instanceof OptimizableBinding) {
                     OptimizableBinding optimizableBinding = (OptimizableBinding)clonedBinding;
@@ -293,9 +287,9 @@
                 }
 
                 endpointReference.setBinding(clonedBinding);
-                
+
                 Endpoint2 clonedEndpoint = (Endpoint2)serviceEndpoint.clone();
-                
+
                 endpointReference.setTargetEndpoint(clonedEndpoint);
                 endpointReference.setUnresolved(false);
 
@@ -303,68 +297,68 @@
                 // do nothing
             }
         }
-    } 
-    
+    }
+
     // TODO - EPR
     // Find the callback endpoint for the endpoint reference by matching
     // callback bindings between reference and service
-    private void matchCallbackBinding(EndpointReference2 endpointReference, 
+    private void matchCallbackBinding(EndpointReference2 endpointReference,
                                      Monitor monitor) {
 
         // if no callback on the interface or we are creating a self reference do nothing
-        if (endpointReference.getReference().getInterfaceContract() == null || 
+        if (endpointReference.getReference().getInterfaceContract() == null ||
             endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null ||
             endpointReference.getReference().getName().startsWith("$self$.")){
                 return;
         }
-        
+
         Endpoint2 endpoint = endpointReference.getTargetEndpoint();
-        
+
         List<Endpoint2> callbackEndpoints = endpointReference.getReference().getCallbackService().getEndpoints();
         List<EndpointReference2> callbackEndpointReferences = endpoint.getCallbackEndpointReferences();
-        
+
         List<Endpoint2> matchedEndpoint = new ArrayList<Endpoint2>();
-        
+
         if ((callbackEndpoints != null) &&  (callbackEndpointReferences != null)){
             // Find the corresponding bindings from the service side
             for (EndpointReference2 epr : callbackEndpointReferences) {
                 for (Endpoint2 ep : callbackEndpoints) {
-    
+
                     if (epr.getBinding().getClass() == ep.getBinding().getClass() &&
                         hasCompatiblePolicySets(epr.getBinding(), ep.getBinding())) {
-                        
-                        matchedEndpoint.add(ep);              
+
+                        matchedEndpoint.add(ep);
                     }
                 }
             }
         }
-        
+
         if (matchedEndpoint.isEmpty()) {
             // No matching binding
             endpointReference.setCallbackEndpoint(null);
             endpointReference.setUnresolved(true);
-            warning(monitor, 
-                    "NoMatchingCallbackBinding", 
+            warning(monitor,
+                    "NoMatchingCallbackBinding",
                     endpointReference.getReference(),
-                    endpointReference.getReference().getName(), 
+                    endpointReference.getReference().getName(),
                     endpoint.getService().getName());
             return;
         } else {
             // default to using the first matched binding
             int selectedEndpoint = 0;
-            
+
             for (int i = 0; i < matchedEndpoint.size(); i++){
                 // If binding.sca is present, use it
                 if (SCABinding.class.isInstance(matchedEndpoint.get(i).getBinding())) {
                     selectedEndpoint = i;
                 }
             }
-            
+
             endpointReference.setCallbackEndpoint(matchedEndpoint.get(selectedEndpoint));
             endpointReference.setUnresolved(false);
         }
-    }     
-    
+    }
+
     private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) {
         boolean isCompatible = true;
         if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) {
@@ -384,5 +378,5 @@
             }
         }
         return isCompatible;
-    }    
+    }
 }

Modified: tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java?rev=782804&r1=782803&r2=782804&view=diff
==============================================================================
--- tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java (original)
+++ tuscany/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java Mon Jun  8 21:50:12 2009
@@ -6,68 +6,76 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.endpoint.impl;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
 
-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.EndpointRegistry;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.runtime.EndpointListener;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
 
 public class EndpointRegistryImpl implements EndpointRegistry {
-
+    private final Logger logger = Logger.getLogger(EndpointRegistryImpl.class.getName());
     //public static final EndpointRegistryImpl INSTANCE = new EndpointRegistryImpl();
     //public static EndpointRegistryImpl getInstance() {
     //    return INSTANCE;
     //}
-    
+
     static List<Endpoint2> endpoints = new ArrayList<Endpoint2>();
     static List<EndpointReference2> endpointreferences = new ArrayList<EndpointReference2>();
-    
+
+    private List<EndpointListener> listeners = new CopyOnWriteArrayList<EndpointListener>();
+
     public EndpointRegistryImpl(ExtensionPointRegistry extensionPoints) {
     }
-    
+
     public void addEndpoint(Endpoint2 endpoint) {
         endpoints.add(endpoint);
-        System.out.println("EndpointRegistry: Add endpoint - " + endpoint.toString());
+        for (EndpointListener listener : listeners) {
+            listener.endpointAdded(endpoint);
+        }
+        logger.info("EndpointRegistry: Add endpoint - " + endpoint.toString());
     }
 
     public void addEndpointReference(EndpointReference2 endpointReference) {
         endpointreferences.add(endpointReference);
-        System.out.println("EndpointRegistry: Add endpoint reference - " + endpointReference.toString());
+        logger.info("EndpointRegistry: Add endpoint reference - " + endpointReference.toString());
     }
 
     public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
         List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
-        
-        System.out.println("EndpointRegistry: Find endpoint for reference - " + endpointReference.toString());
-        
+
+        logger.info("EndpointRegistry: Find endpoint for reference - " + endpointReference.toString());
+
         if (endpointReference.getReference() != null) {
             Endpoint2 targetEndpoint = endpointReference.getTargetEndpoint();
             for (Endpoint2 endpoint : endpoints) {
                 // TODO: implement more complete matching
                 if (endpoint.getComponentName().equals(targetEndpoint.getComponentName())) {
-                    if ( (targetEndpoint.getServiceName() != null) && 
-                         (endpoint.getServiceName().equals(targetEndpoint.getServiceName())) ){
+                    if ((targetEndpoint.getServiceName() != null) && (endpoint.getServiceName().equals(targetEndpoint
+                        .getServiceName()))) {
                         foundEndpoints.add(endpoint);
-                        System.out.println("EndpointRegistry: Found endpoint with matching service  - " + endpoint.toString());
+                        logger.info("EndpointRegistry: Found endpoint with matching service  - " + endpoint.toString());
                     } else if (targetEndpoint.getServiceName() == null) {
                         foundEndpoints.add(endpoint);
-                        System.out.println("EndpointRegistry: Found endpoint with matching component  - " + endpoint.toString());
+                        logger.info("EndpointRegistry: Found endpoint with matching component  - " + endpoint
+                            .toString());
                     }
                     // else the service name doesn't match
                 }
@@ -82,12 +90,15 @@
 
     public void removeEndpoint(Endpoint2 endpoint) {
         endpoints.remove(endpoint);
-        System.out.println("EndpointRegistry: Remove endpoint - " + endpoint.toString());
+        for (EndpointListener listener : listeners) {
+            listener.endpointRemoved(endpoint);
+        }
+        logger.info("EndpointRegistry: Remove endpoint - " + endpoint.toString());
     }
 
     public void removeEndpointReference(EndpointReference2 endpointReference) {
         endpointreferences.remove(endpointReference);
-        System.out.println("EndpointRegistry: Remove endpoint reference - " + endpointReference.toString());
+        logger.info("EndpointRegistry: Remove endpoint reference - " + endpointReference.toString());
     }
 
     public List<EndpointReference2> getEndpointRefereneces() {
@@ -98,4 +109,46 @@
         return endpoints;
     }
 
+    public void addListener(EndpointListener listener) {
+        listeners.add(listener);
+    }
+
+    public List<EndpointListener> getListeners() {
+        return listeners;
+    }
+
+    public void removeListener(EndpointListener listener) {
+        listeners.remove(listener);
+    }
+
+    public Endpoint2 getEndpoint(String uri) {
+        for (Endpoint2 ep : endpoints) {
+            String epURI =
+                ep.getComponent().getURI() + "#" + ep.getService().getName() + "/" + ep.getBinding().getName();
+            if (epURI.equals(uri)) {
+                return ep;
+            }
+            if (ep.getBinding().getName() == null || ep.getBinding().getName().equals(ep.getService().getName())) {
+                epURI = ep.getComponent().getURI() + "#" + ep.getService().getName();
+                if (epURI.equals(uri)) {
+                    return ep;
+                }
+            }
+        }
+        return null;
+
+    }
+
+    public void updateEndpoint(String uri, Endpoint2 endpoint) {
+        Endpoint2 oldEndpoint = getEndpoint(uri);
+        if (oldEndpoint == null) {
+            throw new IllegalArgumentException("Endpoint is not found: " + uri);
+        }
+        endpoints.remove(oldEndpoint);
+        addEndpoint(endpoint);
+        for (EndpointListener listener : listeners) {
+            listener.endpointUpdated(oldEndpoint, endpoint);
+        }
+    }
+
 }

Modified: tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=782804&r1=782803&r2=782804&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java (original)
+++ tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java Mon Jun  8 21:50:12 2009
@@ -45,6 +45,7 @@
 import org.oasisopen.sca.CallableReference;
 import org.oasisopen.sca.ServiceReference;
 import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.ServiceUnavailableException;
 
 /**
  * An SCA Node that is managed by the NodeManager
@@ -106,16 +107,16 @@
             if( compositeActivator.getDomainComposite() != null ) {
 	            List<Composite> composites = compositeActivator.getDomainComposite().getIncludes();
 	            for (Composite composite : composites) {
-	
+
 	                // Stop the composite
 	                compositeActivator.stop(composite);
-	
+
 	                // Deactivate the composite
 	                compositeActivator.deactivate(composite);
-	
+
 	            } // end for
 	            composites.clear();
-            } // end if 
+            } // end if
 
             manager.removeNode(configuration);
             this.compositeActivator = null;
@@ -168,7 +169,7 @@
         }
 
         if (component == null) {
-            throw new ServiceRuntimeException("The service " + name + " has not been contributed to the domain");
+            throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain");
         }
         RuntimeComponentContext componentContext = null;
 
@@ -206,7 +207,7 @@
     public ExtensionPointRegistry getExtensionPoints() {
         return manager.getExtensionPoints();
     }
-    
+
     /**
      * Get the service endpoints in this Node
      * TODO: needs review, works for the very simple testcase but i expect there are



Mime
View raw message