diff options
Diffstat (limited to 'branches/sca-java-1.3/modules/assembly/src/main/java/org/apache')
16 files changed, 1154 insertions, 499 deletions
diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java index f38346663a..2eb1bf21b0 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java @@ -47,6 +47,24 @@ public interface Reference extends AbstractReference, Contract { void setWiredByImpl(boolean wiredByImpl); /** + * Returns a boolean value, "false" by default, which indicates whether + * the configuration of this reference is a promotion override for + * another more deeply nested reference. + * + * @return true if the reference is a promotion override + */ + boolean isPromotionOverride(); + + /** + * Sets a boolean value, "false" by default, which indicates whether + * the configuration of this reference is a promotion override for + * another more deeply nested reference. + * + * @param promotionOverride whether the reference is a promotion override + */ + void setPromotionOverride(boolean promotionOverride); + + /** * Returns the targets of this reference. * * @return the targets of this reference. diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java index 853c11c2ee..648977792a 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java @@ -38,6 +38,7 @@ 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.CompositeService; +import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.OptimizableBinding; @@ -95,7 +96,7 @@ public abstract class BaseConfigurationBuilderImpl { protected void configureComponents(Composite composite) throws CompositeBuilderException { configureComponents(composite, null); configureSourcedProperties(composite, null); - configureBindingURIs(composite, null, null); + //configureBindingURIs(composite, null, null); } /** @@ -138,7 +139,7 @@ public abstract class BaseConfigurationBuilderImpl { SCABinding scaBinding = createSCABinding(); service.getBindings().add(scaBinding); } - +/* // Initialize binding names and URIs for (Binding binding : service.getBindings()) { @@ -155,6 +156,7 @@ public abstract class BaseConfigurationBuilderImpl { } } } +*/ } // Initialize reference bindings @@ -164,7 +166,7 @@ public abstract class BaseConfigurationBuilderImpl { SCABinding scaBinding = createSCABinding(); reference.getBindings().add(scaBinding); } - +/* // Set binding names for (Binding binding : reference.getBindings()) { if (binding.getName() == null) { @@ -179,6 +181,7 @@ public abstract class BaseConfigurationBuilderImpl { } } } +*/ } // Initialize all component services and references @@ -252,7 +255,7 @@ public abstract class BaseConfigurationBuilderImpl { SCABinding scaBinding = createSCABinding(); componentService.getBindings().add(scaBinding); } - +/* // Set binding names for (Binding binding : componentService.getBindings()) { @@ -268,6 +271,7 @@ public abstract class BaseConfigurationBuilderImpl { } } } +*/ } // Initialize reference bindings @@ -278,7 +282,7 @@ public abstract class BaseConfigurationBuilderImpl { SCABinding scaBinding = createSCABinding(); componentReference.getBindings().add(scaBinding); } - +/* // Set binding names for (Binding binding : componentReference.getBindings()) { if (binding.getName() == null) { @@ -292,6 +296,7 @@ public abstract class BaseConfigurationBuilderImpl { } } } +*/ } } } @@ -801,208 +806,6 @@ public abstract class BaseConfigurationBuilderImpl { } /** - * Activate composite services in nested composites. - * - * @param composite - * @param problems - */ - protected void configureCompositeServices(Composite composite) { - - // Process nested composites recursively - configureNestedCompositeServices(composite); - - // Process top level composite services - for (Service service : composite.getServices()) { - CompositeService compositeService = (CompositeService)service; - - // Get the inner most promoted service - ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (promotedService != null) { - Component promotedComponent = getPromotedComponent(compositeService); - - // Default to use the interface from the promoted service - if (compositeService.getInterfaceContract() == null && promotedService.getInterfaceContract() != null) { - compositeService.setInterfaceContract(promotedService.getInterfaceContract()); - } - - // Create a new component service to represent this composite - // service on the promoted component - ComponentService newComponentService = assemblyFactory.createComponentService(); - newComponentService.setName("$promoted$." + compositeService.getName()); - promotedComponent.getServices().add(newComponentService); - newComponentService.setService(promotedService.getService()); - // set the bindings using the top level bindings to override the - // lower level bindings - if (bindingsSpecifiedManually(compositeService.getBindings())){ - newComponentService.getBindings() - .addAll(compositeService.getBindings()); - } else { - for (Binding binding : promotedService.getBindings()){ - try { - newComponentService.getBindings().add((Binding)binding.clone()); - } catch(CloneNotSupportedException ex){ - // this binding can't be used in the promoted service - } - } - } - newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); - if (compositeService.getInterfaceContract() != null && compositeService - .getInterfaceContract().getCallbackInterface() != null) { - newComponentService.setCallback(assemblyFactory.createCallback()); - if ((compositeService.getCallback() != null) && - (bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){ - newComponentService.getCallback().getBindings() - .addAll(compositeService.getCallback().getBindings()); - } else if ((promotedService.getCallback() != null) && - (bindingsSpecifiedManually(promotedService.getCallback().getBindings()))){ - for (Binding binding : promotedService.getCallback().getBindings()){ - try { - newComponentService.getCallback().getBindings().add((Binding)binding.clone()); - } catch(CloneNotSupportedException ex){ - // this binding can't be used in the promoted service - } - } - } - } - - // Change the composite service to now promote the newly - // created component service directly - compositeService.setPromotedComponent(promotedComponent); - compositeService.setPromotedService(newComponentService); - } - } - } - - /** - * Activate composite services in nested composites. - * - * @param composite - * @param problems - */ - private void configureNestedCompositeServices(Composite composite) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // First process nested composites - configureNestedCompositeServices((Composite)implementation); - - // Process the component services declared on components - // in this composite - for (ComponentService componentService : component.getServices()) { - Service implService = componentService.getService(); - if (implService != null && implService instanceof CompositeService) { - CompositeService compositeService = (CompositeService)implService; - - // Get the inner most promoted service - ComponentService promotedService = - ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (promotedService != null) { - Component promotedComponent = getPromotedComponent(compositeService); - - // Default to use the interface from the promoted - // service - if (compositeService.getInterfaceContract() == null) { - compositeService.setInterfaceContract(promotedService - .getInterfaceContract()); - } - if (componentService.getInterfaceContract() == null) { - componentService.setInterfaceContract(promotedService - .getInterfaceContract()); - } - - // Create a new component service to represent this - // composite service on the promoted component - ComponentService newComponentService = - assemblyFactory.createComponentService(); - newComponentService.setName("$promoted$." + componentService.getName()); - promotedComponent.getServices().add(newComponentService); - newComponentService.setService(promotedService.getService()); - - // set the bindings using the top level bindings to override the - // lower level bindings - if (bindingsSpecifiedManually(componentService.getBindings())){ - newComponentService.getBindings() - .addAll(componentService.getBindings()); - } else if (bindingsSpecifiedManually(compositeService.getBindings())){ - newComponentService.getBindings() - .addAll(compositeService.getBindings()); - } else { - for (Binding binding : promotedService.getBindings()){ - try { - newComponentService.getBindings().add((Binding)binding.clone()); - } catch(CloneNotSupportedException ex){ - // this binding can't be used in the promoted service - } - } - } - - newComponentService.setInterfaceContract(componentService - .getInterfaceContract()); - - if (componentService.getInterfaceContract() != null && - componentService.getInterfaceContract().getCallbackInterface() != null) { - - newComponentService.setCallback(assemblyFactory.createCallback()); - - // set the bindings using the top level bindings to override the - // lower level bindings - if ((componentService.getCallback() != null) && - (bindingsSpecifiedManually(componentService.getCallback().getBindings()))){ - newComponentService.getCallback().getBindings() - .addAll(componentService.getCallback().getBindings()); - } else if ((compositeService.getCallback() != null) && - (bindingsSpecifiedManually(compositeService.getCallback().getBindings()))){ - newComponentService.getCallback().getBindings() - .addAll(compositeService.getCallback().getBindings()); - } else if ((promotedService.getCallback() != null) && - (bindingsSpecifiedManually(promotedService.getCallback().getBindings()))){ - for (Binding binding : promotedService.getCallback().getBindings()){ - try { - newComponentService.getCallback().getBindings().add((Binding)binding.clone()); - } catch(CloneNotSupportedException ex){ - // this binding can't be used in the promoted service - } - } - } - } - - // Change the composite service to now promote the - // newly created component service directly - compositeService.setPromotedComponent(promotedComponent); - compositeService.setPromotedService(newComponentService); - } - } - } - } - } - } - - /** - * If the bindings are specified in the composite file return true as they should - * otherwise return false - * - * @param bindings - * @return true if the bindings were specified manually - */ - private boolean bindingsSpecifiedManually(List<Binding> bindings){ - - if (bindings.size() > 1){ - return true; - } else if ((bindings.size() == 1) && - (bindings.get(0) instanceof AutomaticBinding) && - (((AutomaticBinding)bindings.get(0)).getIsAutomatic() == true )){ - return false; - } else if (bindings.size() == 1) { - return true; - } else { - return false; - } - } - - /** * @param composite */ private void configureSourcedProperties(Composite composite, List<ComponentProperty> propertySettings) { @@ -1032,34 +835,6 @@ public abstract class BaseConfigurationBuilderImpl { } } - /** - * Follow a service promotion chain down to the inner most (non composite) - * component. - * - * @param compositeService - * @return - */ - protected static Component getPromotedComponent(CompositeService compositeService) { - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - Service service = componentService.getService(); - if (componentService.getName() != null && service instanceof CompositeService) { - - // Continue to follow the service promotion chain - return getPromotedComponent((CompositeService)service); - - } else { - - // Found a non-composite service - return compositeService.getPromotedComponent(); - } - } else { - - // No promoted service - return null; - } - } - private ComponentProperty getComponentPropertyByName(String propertyName, List<ComponentProperty> properties) { if (properties != null) { for (ComponentProperty aProperty : properties) { @@ -1074,8 +849,8 @@ public abstract class BaseConfigurationBuilderImpl { private SCABinding createSCABinding() { SCABinding scaBinding = scaBindingFactory.createSCABinding(); - // mark the bindings that are added automatically so that theu can - // can be disregarded for overriding purposes + // mark the bindings that are added automatically so that they can + // be disregarded for overriding purposes if (scaBinding instanceof AutomaticBinding){ ((AutomaticBinding)scaBinding).setIsAutomatic(true); } @@ -1092,6 +867,16 @@ public abstract class BaseConfigurationBuilderImpl { } /** + * Called by CompositeBindingURIBuilderImpl + * + * @param composite the composite to be configured + */ + protected void configureBindingURIsAndNames(Composite composite) throws CompositeBuilderException { + configureBindingURIs(composite, null, null); + configureBindingNames(composite); + } + + /** * Fully resolve the binding URIs based on available information. This includes information * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, * from any associated policies and from the default information for each binding type. @@ -1108,7 +893,13 @@ public abstract class BaseConfigurationBuilderImpl { * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, * from any associated policies and from the default information for each binding type. * - * TODO: Share the URL calculation algorithm with the configureComponents() method above + * NOTE: This method repeats some of the processing performed by the configureComponents() + * method above. The duplication is needed because NodeConfigurationServiceImpl + * calls this method without previously calling configureComponents(). In the + * normal builder sequence used by CompositeBuilderImpl, both of these methods + * are called. + * + * TODO: Share the URL calculation algorithm with the configureComponents() method above * although keeping the configureComponents() methods signature as is because when * a composite is actually build in a node the node default information is currently * available @@ -1209,23 +1000,96 @@ public abstract class BaseConfigurationBuilderImpl { } } } + + /** + * Add default names for callback bindings and reference bindings. Needs to be + * separate from configureBindingURIs() because configureBindingURIs() is called + * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl. + */ + private void configureBindingNames(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // Process nested composite + configureBindingNames((Composite)implementation); + } + } + + // Initialize composite service callback binding names + for (Service service : composite.getServices()) { + + if (service.getCallback() != null) { + for (Binding binding : service.getCallback().getBindings()) { + constructBindingName(service, binding); + } + } + } + + // Initialize composite reference binding names + for (Reference reference : composite.getReferences()) { + + for (Binding binding : reference.getBindings()) { + constructBindingName(reference, binding); + } + + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + } + } + } + + // Initialize component service and reference binding names + for (Component component : composite.getComponents()) { + + // Initialize component service callback binding names + for (ComponentService service : component.getServices()) { + + if (service.getCallback() != null) { + for (Binding binding : service.getCallback().getBindings()) { + constructBindingName(service, binding); + } + } + } + + // Initialize component reference binding names + for (ComponentReference reference : component.getReferences()) { + + // Initialize binding names + for (Binding binding : reference.getBindings()) { + constructBindingName(reference, binding); + } + + if (reference.getCallback() != null) { + for (Binding binding : reference.getCallback().getBindings()) { + constructBindingName(reference, binding); + } + } + } + } + } /** - * If a binding name is not provided by the user construct it based on the service name + * If a binding name is not provided by the user, construct it based on the service + * or reference name * - * @param service + * @param contract the service or reference * @param binding */ - private void constructBindingName(Service service, Binding binding) throws CompositeBuilderException{ + private void constructBindingName(Contract contract, Binding binding) { // set the default binding name if one is required - // if there is no name on the binding then set it to the service name + // if there is no name on the binding then set it to the service or reference name if (binding.getName() == null){ - binding.setName(service.getName()); + binding.setName(contract.getName()); } // Check that multiple bindings do not have the same name - for (Binding otherBinding : service.getBindings()) { + for (Binding otherBinding : contract.getBindings()) { if (otherBinding == binding) { // Skip the current binding continue; @@ -1235,7 +1099,8 @@ public abstract class BaseConfigurationBuilderImpl { continue; } if (binding.getName().equals(otherBinding.getName())) { - warning("MultipleBindingsForService", binding, service.getName(), binding.getName()); + warning(contract instanceof Service ? "MultipleBindingsForService" : "MultipleBindingsForReference", + binding, contract.getName(), binding.getName()); } } } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java index 544240d07e..c5faa46f85 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java @@ -939,218 +939,6 @@ class BaseWireBuilderImpl { // Clear the list of wires composite.getWires().clear(); } - - /** - * Wire composite references in nested composites. - * - * @param composite - * @param problems - */ - protected void wireCompositeReferences(Composite composite) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - wireCompositeReferences((Composite)implementation); - } - } - - // Process composite references declared in this composite - for (Reference reference : composite.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - List<ComponentReference> promotedReferences = getPromotedComponentReferences(compositeReference); - for (ComponentReference promotedReference : promotedReferences) { - - reconcileReferenceBindings(compositeReference, promotedReference); - if (compositeReference.getInterfaceContract() != null && // can be null in unit tests - compositeReference.getInterfaceContract().getCallbackInterface() != null) { - SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); - if (promotedReference.getCallback() != null) { - promotedReference.getCallback().getBindings().clear(); - } else { - promotedReference.setCallback(assemblyFactory.createCallback()); - } - if (scaCallbackBinding != null) { - promotedReference.getCallback().getBindings().add(scaCallbackBinding); - } - if (compositeReference.getCallback() != null) { - promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback() - .getBindings()); - } - } - } - } - - // Process the component references declared on components - // in this composite - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - for (ComponentReference componentReference : component.getReferences()) { - Reference implReference = componentReference.getReference(); - if (implReference != null && implReference instanceof CompositeReference) { - CompositeReference compositeReference = (CompositeReference)implReference; - List<ComponentReference> promotedReferences = - getPromotedComponentReferences(compositeReference); - for (ComponentReference promotedReference : promotedReferences) { - - // Override the configuration of the promoted reference - reconcileReferenceBindings(componentReference, promotedReference); - if (componentReference.getInterfaceContract() != null && // can be null in unit tests - componentReference.getInterfaceContract().getCallbackInterface() != null) { - SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); - if (promotedReference.getCallback() != null) { - promotedReference.getCallback().getBindings().clear(); - } else { - promotedReference.setCallback(assemblyFactory.createCallback()); - } - if (scaCallbackBinding != null) { - promotedReference.getCallback().getBindings().add(scaCallbackBinding); - } - if (componentReference.getCallback() != null) { - promotedReference.getCallback().getBindings().addAll(componentReference - .getCallback().getBindings()); - } - } - - // Wire the promoted reference to the actual - // non-composite component services - if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference - .getMultiplicity() == Multiplicity.ONE_ONE) { - // promotedReference.getTargets().clear(); - } - for (ComponentService target : componentReference.getTargets()) { - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - // Find the promoted component service - ComponentService componentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (componentService != null) { - promotedReference.getTargets().add(componentService); - } - } else { - - // Wire to a non-composite target service - promotedReference.getTargets().add(target); - } - } - } - } - } - } else { - for (ComponentReference componentReference : component.getReferences()) { - - // Wire the component reference to the actual - // non-composite component services - List<ComponentService> targets = componentReference.getTargets(); - for (int i = 0, n = targets.size(); i < n; i++) { - ComponentService target = targets.get(i); - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - targets.set(i, componentService); - } - } - } - } - } - } - } - - /** - * Follow a reference promotion chain down to the inner most (non composite) - * component references. - * - * @param compositeReference - * @return - */ - private List<ComponentReference> getPromotedComponentReferences(CompositeReference compositeReference) { - List<ComponentReference> componentReferences = new ArrayList<ComponentReference>(); - collectPromotedComponentReferences(compositeReference, componentReferences); - return componentReferences; - } - - /** - * Follow a reference promotion chain down to the inner most (non composite) - * component references. - * - * @param compositeReference - * @param componentReferences - * @return - */ - private void collectPromotedComponentReferences(CompositeReference compositeReference, - List<ComponentReference> componentReferences) { - for (ComponentReference componentReference : compositeReference.getPromotedReferences()) { - Reference reference = componentReference.getReference(); - if (reference instanceof CompositeReference) { - - // Continue to follow the reference promotion chain - collectPromotedComponentReferences((CompositeReference)reference, componentReferences); - - } else if (reference != null) { - - // Found a non-composite reference - componentReferences.add(componentReference); - } - } - } - - /** - * Override the bindings for a promoted reference from an outer component - * reference - * - * @param reference - * @param promotedReference - */ - private void reconcileReferenceBindings(Reference reference, ComponentReference promotedReference) { - List<Binding> bindings = new ArrayList<Binding>(); - - // collect the top level bindings first - for (Binding binding : reference.getBindings()) { - if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { - bindings.add(binding); - } - } - - // if there are not top level bindings to override the promoted bindings - // then collect the promoted bindings - if (bindings.size() == 0){ - for (Binding binding : promotedReference.getBindings()) { - if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { - bindings.add(binding); - } - } - } - - promotedReference.getBindings().clear(); - promotedReference.getBindings().addAll(bindings); - - if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) { - if (promotedReference.getBindings().size() > 1) { - warning("ComponentReferenceMoreWire", promotedReference, promotedReference.getName()); - } - } - Set<Binding> callbackBindings = new HashSet<Binding>(); - if (promotedReference.getCallback() != null) { - callbackBindings.addAll(promotedReference.getCallback().getBindings()); - } - if (reference.getCallback() != null) { - callbackBindings.addAll(reference.getCallback().getBindings()); - } - promotedReference.setCallback(assemblyFactory.createCallback()); - for (Binding binding : callbackBindings) { - if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { - promotedReference.getCallback().getBindings().add(binding); - } - } - } private void addPoliciesFromPromotedService(CompositeService compositeService) { //inherit intents and policies from promoted service diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java index 0c45f7bc9d..1769e7eee9 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java @@ -48,16 +48,8 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { } private void buildReferenceBindings(Composite composite) { - - // build bindings recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - buildReferenceBindings((Composite)implementation); - } - } - // find all the component reference bindings + // find all the component reference bindings (starting at top level) for (Component component : composite.getComponents()) { for (ComponentReference componentReference : component.getReferences()) { for (Binding binding : componentReference.getBindings()) { @@ -67,6 +59,14 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { } } } + + // build bindings recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + buildReferenceBindings((Composite)implementation); + } + } } } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java new file mode 100644 index 0000000000..e2677e5a82 --- /dev/null +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java @@ -0,0 +1,162 @@ +/* + * 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.assembly.builder.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +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.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that handles the creation of promoted composite services. + * + * @version $Rev$ $Date$ + */ +public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + private Monitor monitor; + + public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory, Monitor monitor) { + this.assemblyFactory = assemblyFactory; + this.monitor = monitor; + } + + public void build(Composite composite) throws CompositeBuilderException { + wireCompositeReferences(composite); + } + + /** + * Wire composite references in nested composites. + * + * @param composite + * @param problems + */ + private void wireCompositeReferences(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireCompositeReferences((Composite)implementation); + } + } + + // Process component references declared on components in this composite + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + for (ComponentReference componentReference : component.getReferences()) { + Reference implReference = componentReference.getReference(); + if (implReference != null && implReference instanceof CompositeReference) { + + // If the component reference is wired, it is a promotion override + if (!componentReference.getEndpoints().isEmpty()) { + componentReference.setPromotionOverride(true); + } + + // If the component reference is a promotion override, override the + // configuration of the promoted reference + if (componentReference.isPromotionOverride()) { + CompositeReference compositeReference = (CompositeReference)implReference; + List<ComponentReference> promotedReferences = + ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + ReferenceConfigurationUtil.reconcileReferenceBindings( + componentReference, promotedReference, assemblyFactory, monitor); + if (componentReference.getInterfaceContract() != null && // can be null in unit tests + componentReference.getInterfaceContract().getCallbackInterface() != null) { + SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); + if (promotedReference.getCallback() != null) { + promotedReference.getCallback().getBindings().clear(); + } else { + promotedReference.setCallback(assemblyFactory.createCallback()); + } + if (scaCallbackBinding != null) { + promotedReference.getCallback().getBindings().add(scaCallbackBinding); + } + if (componentReference.getCallback() != null) { + promotedReference.getCallback().getBindings().addAll(componentReference + .getCallback().getBindings()); + } + } + + // Wire the promoted reference to the actual non-composite component services + if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) { + // promotedReference.getTargets().clear(); + } + for (ComponentService target : componentReference.getTargets()) { + if (target.getService() instanceof CompositeService) { + + // Wire to the actual component service + // promoted by a composite service + CompositeService compositeService = (CompositeService)target.getService(); + // Find the promoted component service + ComponentService componentService = + ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (componentService != null) { + promotedReference.getTargets().add(componentService); + } + } else { + + // Wire to a non-composite target service + promotedReference.getTargets().add(target); + } + } + } + } + } + } + } else { + for (ComponentReference componentReference : component.getReferences()) { + + // Wire the component reference to the actual + // non-composite component services + List<ComponentService> targets = componentReference.getTargets(); + for (int i = 0, n = targets.size(); i < n; i++) { + ComponentService target = targets.get(i); + if (target.getService() instanceof CompositeService) { + + // Wire to the actual component service + // promoted by a composite service + CompositeService compositeService = (CompositeService)target.getService(); + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + targets.set(i, componentService); + } + } + } + } + } + } + } + +} diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java new file mode 100644 index 0000000000..53e6eda1eb --- /dev/null +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java @@ -0,0 +1,99 @@ +/* + * 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.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +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.Service; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the creation of promoted services. + * + * @version $Rev$ $Date$ + */ +public class ComponentServicePromotionBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public ComponentServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process nested composites recursively + configureNestedCompositeServices(composite); + } + + private void configureNestedCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeServices((Composite)implementation); + + // Process the component services declared on components in this composite + for (ComponentService componentService : component.getServices()) { + Service implService = componentService.getService(); + if (implService != null && implService instanceof CompositeService) { + CompositeService compositeService = (CompositeService)implService; + + // Get the innermost promoted service + ComponentService promotedService = + ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); + + // Create a new component service to represent this + // component service on the promoted component + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$." + component.getName() + "." + componentService.getName()); + promotedComponent.getServices().add(newComponentService); + newComponentService.setService(promotedService.getService()); + newComponentService.getBindings().addAll(componentService.getBindings()); + newComponentService.setInterfaceContract(componentService.getInterfaceContract()); + + if (componentService.getInterfaceContract() != null && + componentService.getInterfaceContract().getCallbackInterface() != null) { + newComponentService.setCallback(assemblyFactory.createCallback()); + newComponentService.getCallback().getBindings() + .addAll(componentService.getCallback().getBindings()); + } + + // Change the composite service to now promote the + // newly created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + } + } + } + +} diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java new file mode 100644 index 0000000000..4c2c369f3e --- /dev/null +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java @@ -0,0 +1,50 @@ +/* + * 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.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * A composite builder that handles the configuration of binding URIs. + * + * @version $Rev$ $Date$ + */ +public class CompositeBindingURIBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { + + public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + } + + public void build(Composite composite) throws CompositeBuilderException { + configureBindingURIsAndNames(composite); + } + +} diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java index fb427e5afc..0e8585cc91 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -42,15 +42,19 @@ import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; public class CompositeBuilderImpl implements CompositeBuilder { private static final Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName()); private CompositeBuilder compositeIncludeBuilder; - private CompositeBuilder componentWireBuilder; + private CompositeBuilder componentReferenceWireBuilder; + private CompositeBuilder componentReferencePromotionWireBuilder; private CompositeBuilder compositeReferenceWireBuilder; private CompositeBuilder compositeCloneBuilder; private CompositeBuilder componentConfigurationBuilder; private CompositeBuilder compositeServiceConfigurationBuilder; + private CompositeBuilder compositeReferenceConfigurationBuilder; + private CompositeBuilder compositeBindingURIBuilder; + private CompositeBuilder componentServicePromotionBuilder; + private CompositeBuilder compositeServicePromotionBuilder; private CompositeBuilder compositePromotionBuilder; private CompositeBuilder compositePolicyBuilder; private CompositeBuilder componentServiceBindingBuilder; - private CompositeBuilder compositeServiceBindingBuilder; private CompositeBuilder componentReferenceBindingBuilder; /** @@ -94,15 +98,19 @@ public class CompositeBuilderImpl implements CompositeBuilder { } compositeIncludeBuilder = new CompositeIncludeBuilderImpl(monitor); - componentWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); - compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); + componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); + componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, monitor); + compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, monitor); compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor); componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); - compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory); + compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory); + compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); + compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(monitor); - compositeServiceBindingBuilder = new CompositeServiceBindingBuilderImpl(monitor); componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(monitor); } @@ -123,17 +131,29 @@ public class CompositeBuilderImpl implements CompositeBuilder { // Compute the policies across the model hierarchy compositePolicyBuilder.build(composite); - // Build component service binding-related information - componentServiceBindingBuilder.build(composite); - - // Build composite service binding-related information - compositeServiceBindingBuilder.build(composite); - // Configure composite services compositeServiceConfigurationBuilder.build(composite); + // Configure composite references + compositeReferenceConfigurationBuilder.build(composite); + + // Configure binding URIs + compositeBindingURIBuilder.build(composite); + + // Create promoted component services + componentServicePromotionBuilder.build(composite); + + // Create promoted composite services + compositeServicePromotionBuilder.build(composite); + + // Build component service binding-related information + componentServiceBindingBuilder.build(composite); + // Wire the components - componentWireBuilder.build(composite); + componentReferenceWireBuilder.build(composite); + + // Wire the promoted component references + componentReferencePromotionWireBuilder.build(composite); // Wire the composite references compositeReferenceWireBuilder.build(composite); diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java new file mode 100644 index 0000000000..41462b151d --- /dev/null +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java @@ -0,0 +1,224 @@ +/* + * 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.assembly.builder.impl; + +import java.util.List; +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.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the configuration of composite references. + * + * @version $Rev: 651179 $ $Date: 2008-04-24 08:21:13 +0100 (Thu, 24 Apr 2008) $ + */ +public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeReferenceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process nested composites recursively + configureNestedCompositeReferences(composite); + + // Process top level composite references + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + + // Get the next lower level promoted reference + List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences(); + if (!promotedRefs.isEmpty()) { + if (promotedRefs.size() == 1) { + ComponentReference promotedReference = promotedRefs.get(0); + + // Set the bindings using the top level bindings to override the lower level bindings + if (bindingsSpecifiedManually(compositeReference.getBindings())) { + compositeReference.setPromotionOverride(true); + } else if (bindingsSpecifiedManually(promotedReference.getBindings()) ) { + compositeReference.getBindings().clear(); + for (Binding binding : promotedReference.getBindings()) { + try { + compositeReference.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + if (compositeReference.getInterfaceContract() != null && + compositeReference.getInterfaceContract().getCallbackInterface() != null) { + if (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) { + compositeReference.setPromotionOverride(true); + } else if (promotedReference.getCallback() != null && + bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) { + if (compositeReference.getCallback() != null) { + compositeReference.getCallback().getBindings().clear(); + } else { + compositeReference.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedReference.getCallback().getBindings()) { + try { + compositeReference.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + } + } else { + // This composite reference promotes multiple component references. + // Because the component reference bindings can all be different, we don't + // copy any of them up to this composite reference, which will therefore always + // have its own binding, even if it's only the default SCA binding. + if (bindingsSpecifiedManually(compositeReference.getBindings()) || + (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings()))) { + compositeReference.setPromotionOverride(true); + } + } + } + } + } + + private void configureNestedCompositeReferences(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeReferences((Composite)implementation); + + // Process the component references declared on components in this composite + for (ComponentReference componentReference : component.getReferences()) { + Reference implReference = componentReference.getReference(); + if (implReference != null && implReference instanceof CompositeReference) { + CompositeReference compositeReference = (CompositeReference)implReference; + + // Get the next lower level promoted reference + List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences(); + if (!promotedRefs.isEmpty()) { + if (promotedRefs.size() == 1) { + ComponentReference promotedReference = promotedRefs.get(0); + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeReference.getBindings()) && + bindingsSpecifiedManually(promotedReference.getBindings()) ) { + compositeReference.getBindings().clear(); + for (Binding binding : promotedReference.getBindings()) { + try { + compositeReference.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + if (bindingsSpecifiedManually(componentReference.getBindings())) { + componentReference.setPromotionOverride(true); + } else if (bindingsSpecifiedManually(compositeReference.getBindings()) ) { + componentReference.getBindings().clear(); + componentReference.getBindings().addAll(compositeReference.getBindings()); + } + if (componentReference.getInterfaceContract() != null && + componentReference.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) && + promotedReference.getCallback() != null && + bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) { + if (compositeReference.getCallback() != null) { + compositeReference.getCallback().getBindings().clear(); + } else { + compositeReference.setCallback(assemblyFactory.createCallback()); + } + compositeReference.getCallback().getBindings().addAll( + promotedReference.getCallback().getBindings()); + } + if (componentReference.getCallback() != null && + bindingsSpecifiedManually(componentReference.getCallback().getBindings())) { + componentReference.setPromotionOverride(true); + } else if (compositeReference.getCallback() != null && + bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) { + if (componentReference.getCallback() != null) { + componentReference.getCallback().getBindings().clear(); + } else { + componentReference.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : compositeReference.getCallback().getBindings()) { + try { + componentReference.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted reference + } + } + } + } + } else { + // This component reference promotes multiple lower-level component references. + // Because the lower-level component reference bindings can all be different, + // we don't copy any of them up to this component reference, which will therefore + // always have its own binding, even if it's only the default SCA binding. + if (bindingsSpecifiedManually(componentReference.getBindings()) || + (componentReference.getCallback() != null && + bindingsSpecifiedManually(componentReference.getCallback().getBindings()))) { + componentReference.setPromotionOverride(true); + } + } + } + } + } + } + } + } + + /** + * If the bindings are specified in the composite file return true as they should + * otherwise return false + * + * @param bindings + * @return true if the bindings were specified manually + */ + private boolean bindingsSpecifiedManually(List<Binding> bindings) { + + if (bindings.size() > 1) { + return true; + } else if (bindings.size() == 1 && + bindings.get(0) instanceof AutomaticBinding && + ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) { + return false; + } else if (bindings.size() == 1) { + return true; + } else { + return false; + } + } + +} diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java index 56b3fc79dd..be579387ca 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java @@ -19,12 +19,18 @@ package org.apache.tuscany.sca.assembly.builder.impl; +import java.util.List; + import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.EndpointFactory; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -32,13 +38,56 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public class CompositeReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder { +public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + private Monitor monitor; - public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) { - super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); + public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, Monitor monitor) { + this.assemblyFactory = assemblyFactory; + this.monitor = monitor; } + /** + * Wire composite references in a deployment composite. + * + * @param composite + */ public void build(Composite composite) throws CompositeBuilderException { - wireCompositeReferences(composite); + + // Process composite references declared in this composite + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + + // If the composite reference is a promotion override, override the + // configuration of the promoted reference. + //FIXME: Policy configuration or wiring of domain-level composite references + // doesn't cause a promotion override, unless the composite reference has + // additional bindings. Do we need to detect this and force an override? + if (compositeReference.isPromotionOverride()) { + List<ComponentReference> promotedReferences = + ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + ReferenceConfigurationUtil.reconcileReferenceBindings( + compositeReference, promotedReference, assemblyFactory, monitor); + if (compositeReference.getInterfaceContract() != null && // can be null in unit tests + compositeReference.getInterfaceContract().getCallbackInterface() != null) { + SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); + if (promotedReference.getCallback() != null) { + promotedReference.getCallback().getBindings().clear(); + } else { + promotedReference.setCallback(assemblyFactory.createCallback()); + } + if (scaCallbackBinding != null) { + promotedReference.getCallback().getBindings().add(scaCallbackBinding); + } + if (compositeReference.getCallback() != null) { + promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback() + .getBindings()); + } + } + } + } + } } + } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java index fc4c63ae46..51e2da2d64 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java @@ -62,7 +62,7 @@ public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { for (Service service : composite.getServices()) { for (Binding binding : service.getBindings()) { if (binding instanceof BindingBuilderExtension) { - Component component = BaseConfigurationBuilderImpl.getPromotedComponent((CompositeService)service); + Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service); ((BindingBuilderExtension)binding).getBuilder().build(component, service, binding, monitor); } } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java index 7303570ac8..a3f31ea2fa 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java @@ -19,32 +19,176 @@ package org.apache.tuscany.sca.assembly.builder.impl; +import java.util.List; 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.ComponentService; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.AutomaticBinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.SCADefinitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; /** * A composite builder that handles the configuration of composite services. * * @version $Rev$ $Date$ */ -public class CompositeServiceConfigurationBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { - - public CompositeServiceConfigurationBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - InterfaceContractMapper interfaceContractMapper, - SCADefinitions policyDefinitions, - Monitor monitor) { - super(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); +public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeServiceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; } public void build(Composite composite) throws CompositeBuilderException { - configureCompositeServices(composite); + + // Process nested composites recursively + configureNestedCompositeServices(composite); + + // Process top level composite services + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the next lower level promoted service + ComponentService promotedService = compositeService.getPromotedService(); + if (promotedService != null) { + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeService.getBindings()) && + bindingsSpecifiedManually(promotedService.getBindings())) { + compositeService.getBindings().clear(); + for (Binding binding : promotedService.getBindings()) { + try { + compositeService.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (compositeService.getInterfaceContract() != null && + compositeService.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) && + promotedService.getCallback() != null && + bindingsSpecifiedManually(promotedService.getCallback().getBindings())) { + if (compositeService.getCallback() != null) { + compositeService.getCallback().getBindings().clear(); + } else { + compositeService.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedService.getCallback().getBindings()) { + try { + compositeService.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + } + } + } + } + + private void configureNestedCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + configureNestedCompositeServices((Composite)implementation); + + // Process the component services declared on components in this composite + for (ComponentService componentService : component.getServices()) { + Service implService = componentService.getService(); + if (implService != null && implService instanceof CompositeService) { + CompositeService compositeService = (CompositeService)implService; + + // Get the next lower level promoted service + ComponentService promotedService = compositeService.getPromotedService(); + if (promotedService != null) { + + // Set the bindings using the top level bindings to override the lower level bindings + if (!bindingsSpecifiedManually(compositeService.getBindings()) && + bindingsSpecifiedManually(promotedService.getBindings()) ) { + compositeService.getBindings().clear(); + for (Binding binding : promotedService.getBindings()) { + try { + compositeService.getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (!bindingsSpecifiedManually(componentService.getBindings()) && + bindingsSpecifiedManually(compositeService.getBindings()) ) { + componentService.getBindings().clear(); + componentService.getBindings().addAll(compositeService.getBindings()); + } + if (componentService.getInterfaceContract() != null && + componentService.getInterfaceContract().getCallbackInterface() != null) { + if (!(compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) && + promotedService.getCallback() != null && + bindingsSpecifiedManually(promotedService.getCallback().getBindings())) { + if (compositeService.getCallback() != null) { + compositeService.getCallback().getBindings().clear(); + } else { + compositeService.setCallback(assemblyFactory.createCallback()); + } + for (Binding binding : promotedService.getCallback().getBindings()) { + try { + compositeService.getCallback().getBindings().add((Binding)binding.clone()); + } catch (CloneNotSupportedException ex) { + // this binding can't be used in the promoted service + } + } + } + if (!(componentService.getCallback() != null && + bindingsSpecifiedManually(componentService.getCallback().getBindings())) && + compositeService.getCallback() != null && + bindingsSpecifiedManually(compositeService.getCallback().getBindings())) { + if (componentService.getCallback() != null) { + componentService.getCallback().getBindings().clear(); + } else { + componentService.setCallback(assemblyFactory.createCallback()); + } + componentService.getCallback().getBindings().addAll( + compositeService.getCallback().getBindings()); + } + } + } + } + } + } + } + } + + /** + * If the bindings are specified in the composite file return true as they should + * otherwise return false + * + * @param bindings + * @return true if the bindings were specified manually + */ + private boolean bindingsSpecifiedManually(List<Binding> bindings) { + + if (bindings.size() > 1) { + return true; + } else if (bindings.size() == 1 && + bindings.get(0) instanceof AutomaticBinding && + ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) { + return false; + } else if (bindings.size() == 1) { + return true; + } else { + return false; + } } } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java new file mode 100644 index 0000000000..39d2cec396 --- /dev/null +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java @@ -0,0 +1,77 @@ +/* + * 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.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +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.Service; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; + +/** + * A composite builder that handles the creation of promoted composite services. + * + * @version $Rev$ $Date$ + */ +public class CompositeServicePromotionBuilderImpl implements CompositeBuilder { + private AssemblyFactory assemblyFactory; + + public CompositeServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Process top level composite services + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the innermost promoted service + ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); + + // Create a new component service to represent this composite + // service on the promoted component + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$." + compositeService.getName()); + promotedComponent.getServices().add(newComponentService); + newComponentService.setService(promotedService.getService()); + newComponentService.getBindings().addAll(compositeService.getBindings()); + newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); + if (compositeService.getInterfaceContract() != null && + compositeService.getInterfaceContract().getCallbackInterface() != null) { + newComponentService.setCallback(assemblyFactory.createCallback()); + newComponentService.getCallback().getBindings() + .addAll(compositeService.getCallback().getBindings()); + } + + // Change the composite service to now promote the newly + // created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + +} diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java index 5d3d8a3a04..878799f989 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java @@ -18,11 +18,21 @@ */ package org.apache.tuscany.sca.assembly.builder.impl; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; /** * This class encapsulates utility methods to deal with reference definitions @@ -30,6 +40,21 @@ import org.apache.tuscany.sca.assembly.OptimizableBinding; * @version $Rev$ $Date$ */ abstract class ReferenceConfigurationUtil { + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private static void warning(Monitor monitor, String message, Object model, String... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(ReferenceConfigurationUtil.class.getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + static boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { if (definedMul != overridenMul) { switch (definedMul) { @@ -92,4 +117,100 @@ abstract class ReferenceConfigurationUtil { } return true; } + + /** + * Follow a reference promotion chain down to the innermost (non composite) + * component references. + * + * @param compositeReference + * @return + */ + static List<ComponentReference> getPromotedComponentReferences(CompositeReference compositeReference) { + List<ComponentReference> componentReferences = new ArrayList<ComponentReference>(); + collectPromotedComponentReferences(compositeReference, componentReferences); + return componentReferences; + } + + /** + * Follow a reference promotion chain down to the innermost (non composite) + * component references. + * + * @param compositeReference + * @param componentReferences + * @return + */ + private static void collectPromotedComponentReferences(CompositeReference compositeReference, + List<ComponentReference> componentReferences) { + for (ComponentReference componentReference : compositeReference.getPromotedReferences()) { + Reference reference = componentReference.getReference(); + if (reference instanceof CompositeReference) { + + // Continue to follow the reference promotion chain + collectPromotedComponentReferences((CompositeReference)reference, componentReferences); + + } else if (reference != null) { + + // Found a non-composite reference + componentReferences.add(componentReference); + } + } + } + + /** + * Override the bindings for a promoted reference from an outer component + * reference + * + * @param reference + * @param promotedReference + */ + static void reconcileReferenceBindings(Reference reference, + ComponentReference promotedReference, + AssemblyFactory assemblyFactory, + Monitor monitor) { + List<Binding> bindings = new ArrayList<Binding>(); + + // collect the top level bindings first + for (Binding binding : reference.getBindings()) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + bindings.add(binding); + } + } + + // if there are not top level bindings to override the promoted bindings + // then collect the promoted bindings + if (bindings.size() == 0){ + for (Binding binding : promotedReference.getBindings()) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + bindings.add(binding); + } + } + } else { + // TUSCANY-2324: if bindings are being replaced, use the matching interface contract + promotedReference.setInterfaceContract(reference.getInterfaceContract()); + } + + promotedReference.getBindings().clear(); + promotedReference.getBindings().addAll(bindings); + + if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || + promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) { + if (promotedReference.getBindings().size() > 1) { + warning(monitor, "ComponentReferenceMoreWire", promotedReference, promotedReference.getName()); + } + } + Set<Binding> callbackBindings = new HashSet<Binding>(); + if (promotedReference.getCallback() != null) { + callbackBindings.addAll(promotedReference.getCallback().getBindings()); + } + if (reference.getCallback() != null) { + callbackBindings.addAll(reference.getCallback().getBindings()); + } + promotedReference.setCallback(assemblyFactory.createCallback()); + for (Binding binding : callbackBindings) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + promotedReference.getCallback().getBindings().add(binding); + } + } + } + } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java index 5a8d373eb2..41a8b3f8ba 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java @@ -18,6 +18,7 @@ */ package org.apache.tuscany.sca.assembly.builder.impl; +import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Service; @@ -56,4 +57,32 @@ abstract class ServiceConfigurationUtil { return null; } } + + /** + * Follow a service promotion chain down to the innermost (non-composite) component. + * + * @param compositeService + * @return + */ + static Component getPromotedComponent(CompositeService compositeService) { + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + Service service = componentService.getService(); + if (componentService.getName() != null && service instanceof CompositeService) { + + // Continue to follow the service promotion chain + return getPromotedComponent((CompositeService)service); + + } else { + + // Found a non-composite service + return compositeService.getPromotedComponent(); + } + } else { + + // No promoted service + return null; + } + } + } diff --git a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java index 297a7c3a99..12dda94b7a 100644 --- a/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java +++ b/branches/sca-java-1.3/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java @@ -40,6 +40,7 @@ public class ReferenceImpl extends AbstractReferenceImpl implements Reference, C private List<ComponentService> targets = new ArrayList<ComponentService>(); private Callback callback; private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); + private boolean promotionOverride; public List<PolicySet> getApplicablePolicySets() { return applicablePolicySets; @@ -93,6 +94,14 @@ public class ReferenceImpl extends AbstractReferenceImpl implements Reference, C this.wiredByImpl = wiredByImpl; } + public boolean isPromotionOverride() { + return promotionOverride; + } + + public void setPromotionOverride(boolean promotionOverride) { + this.promotionOverride = promotionOverride; + } + public List<PolicySet> getPolicySets() { return policySets; } |