From 31dfb8de93a4c36f7b6486fa95dc588cb3664245 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 2 Jul 2008 10:20:30 +0000 Subject: TUSCANY-2352 allow composite service bindings to override promoted service bindings git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@673348 13f79535-47bb-0310-9956-ffa450edef68 --- .../bindingoverride/BindingOverrideTestCase.java | 2 +- .../builder/impl/BaseConfigurationBuilderImpl.java | 61 ++++++++++++++++++---- .../assembly/builder/impl/BaseWireBuilderImpl.java | 16 ++++-- .../builder/impl/CompositeBuilderImpl.java | 6 +-- 4 files changed, 68 insertions(+), 17 deletions(-) (limited to 'branches/sca-java-1.3') diff --git a/branches/sca-java-1.3/itest/recursive-ws/src/test/java/bindingoverride/BindingOverrideTestCase.java b/branches/sca-java-1.3/itest/recursive-ws/src/test/java/bindingoverride/BindingOverrideTestCase.java index 027b5a6968..c6e46564f0 100644 --- a/branches/sca-java-1.3/itest/recursive-ws/src/test/java/bindingoverride/BindingOverrideTestCase.java +++ b/branches/sca-java-1.3/itest/recursive-ws/src/test/java/bindingoverride/BindingOverrideTestCase.java @@ -50,7 +50,7 @@ public class BindingOverrideTestCase{ } @Test - @Ignore("TUSCANY-2352") + //@Ignore("TUSCANY-2352") public void test() throws Exception { Assert.assertEquals("Target: Hello Target: Hello Fred!!", targetClient.hello("Fred")); } 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 571088f88d..52cba0c18c 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 @@ -21,9 +21,12 @@ package org.apache.tuscany.sca.assembly.builder.impl; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.xml.namespace.QName; @@ -36,6 +39,8 @@ 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.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; @@ -825,14 +830,27 @@ public abstract class BaseConfigurationBuilderImpl { newComponentService.setName("$promoted$." + compositeService.getName()); promotedComponent.getServices().add(newComponentService); newComponentService.setService(promotedService.getService()); - newComponentService.getBindings().addAll(compositeService.getBindings()); + // set the bindings using the top level bindings to override the + // lower level bindings + if (compositeService.getBindings().size() > 0){ + newComponentService.getBindings() + .addAll(compositeService.getBindings()); + } else { + newComponentService.getBindings() + .addAll(promotedService.getBindings()); + } newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); if (compositeService.getInterfaceContract() != null && compositeService .getInterfaceContract().getCallbackInterface() != null) { newComponentService.setCallback(assemblyFactory.createCallback()); - if (compositeService.getCallback() != null) { - newComponentService.getCallback().getBindings().addAll(compositeService - .getCallback().getBindings()); + if ((compositeService.getCallback() != null) && + (compositeService.getCallback().getBindings().size() > 0)){ + newComponentService.getCallback().getBindings() + .addAll(compositeService.getCallback().getBindings()); + } else if ((promotedService.getCallback() != null) && + (promotedService.getCallback().getBindings().size() > 0)){ + newComponentService.getBindings() + .addAll(promotedService.getBindings()); } } @@ -891,16 +909,39 @@ public abstract class BaseConfigurationBuilderImpl { newComponentService.setName("$promoted$." + componentService.getName()); promotedComponent.getServices().add(newComponentService); newComponentService.setService(promotedService.getService()); - newComponentService.getBindings() - .addAll(componentService.getBindings()); + // set the bindings using the top level bindings to override the + // lower level bindings + if (componentService.getBindings().size() > 0){ + newComponentService.getBindings() + .addAll(componentService.getBindings()); + } else if (compositeService.getBindings().size() > 0){ + newComponentService.getBindings() + .addAll(compositeService.getBindings()); + } else { + newComponentService.getBindings() + .addAll(promotedService.getBindings()); + } newComponentService.setInterfaceContract(componentService .getInterfaceContract()); - if (componentService.getInterfaceContract() != null && componentService - .getInterfaceContract().getCallbackInterface() != null) { + if (componentService.getInterfaceContract() != null && + componentService.getInterfaceContract().getCallbackInterface() != null) { + newComponentService.setCallback(assemblyFactory.createCallback()); - if (componentService.getCallback() != null) { + + // set the bindings using the top level bindings to override the + // lower level bindings + if ((componentService.getCallback() != null) && + (componentService.getCallback().getBindings().size() > 0)){ newComponentService.getCallback().getBindings() .addAll(componentService.getCallback().getBindings()); + } else if ((compositeService.getCallback() != null) && + (compositeService.getCallback().getBindings().size() > 0)){ + newComponentService.getCallback().getBindings() + .addAll(compositeService.getCallback().getBindings()); + } else if ((promotedService.getCallback() != null) && + (promotedService.getCallback().getBindings().size() > 0)){ + newComponentService.getBindings() + .addAll(promotedService.getBindings()); } } @@ -914,7 +955,7 @@ public abstract class BaseConfigurationBuilderImpl { } } } - + /** * @param composite */ 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 16132070b9..34deb0dc41 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 @@ -166,19 +166,29 @@ class BaseWireBuilderImpl { ComponentService nonCallbackService = null; int nonCallbackServices = 0; for (ComponentService componentService : component.getServices()) { - + // Index component services by component name / service name String uri = component.getName() + '/' + componentService.getName(); componentServices.put(uri, componentService); - if (!componentService.isCallback()) { + + boolean promotedService = false; + if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) { + promotedService = true; + } + + // count how many non-callback, non-promoted services there are + // if there is only one the component name also acts as the service name + if ((!componentService.isCallback()) && (!promotedService)) { - // Check how many non callback services we have + // Check how many non callback non-promoted services we have if (nonCallbackServices == 0) { nonCallbackService = componentService; } nonCallbackServices++; } + } + if (nonCallbackServices == 1) { // If we have a single non callback service, index it by // component name as well 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 76c8146654..fb427e5afc 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 @@ -128,12 +128,12 @@ public class CompositeBuilderImpl implements CompositeBuilder { // Build composite service binding-related information compositeServiceBindingBuilder.build(composite); - - // Wire the components - componentWireBuilder.build(composite); // Configure composite services compositeServiceConfigurationBuilder.build(composite); + + // Wire the components + componentWireBuilder.build(composite); // Wire the composite references compositeReferenceWireBuilder.build(composite); -- cgit v1.2.3