summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/core/src
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-07-04 13:20:49 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-07-04 13:20:49 +0000
commitd26b0327e3efe5d9c202d6991163619f51fab605 (patch)
treefe8f71953166666022cb56af892be27431444aa9 /java/sca/modules/core/src
parentae1b4d8e700214361d0d6275badf78e478bb9632 (diff)
Fix up the change made at r673687 which didn't anticipate that binding uris in serialized callable references may have absolute uris in them. I.e. they don't match target component names and hence the target component may be null.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@674044 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core/src')
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java75
1 files changed, 59 insertions, 16 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
index 621045e7d0..f4e8a221b3 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
@@ -31,9 +31,11 @@ import javax.xml.stream.XMLStreamReader;
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.CompositeService;
import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
@@ -297,8 +299,19 @@ public class CallableReferenceImpl<B> implements CallableReference<B>, Externali
final Component targetComponent = resolveComponentURI(bindingURI);
// Find the Service
- final ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
-
+ ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
+
+ // if the target service is a promoted service then find the
+ // service it promotes
+ if ((targetService != null) && (targetService.getService() instanceof CompositeService)) {
+ CompositeService compositeService = (CompositeService) targetService.getService();
+ // Find the promoted component service
+ ComponentService promotedComponentService = getPromotedComponentService(compositeService);
+ if (promotedComponentService != null && !promotedComponentService.isUnresolved()) {
+ targetService = promotedComponentService;
+ }
+ }
+
OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
optimizableBinding.setTargetComponent(targetComponent);
optimizableBinding.setTargetComponentService(targetService);
@@ -353,6 +366,34 @@ public class CallableReferenceImpl<B> implements CallableReference<B>, Externali
}
}
}
+
+ /**
+ * Follow a service promotion chain down to the inner most (non composite)
+ * component service.
+ *
+ * @param topCompositeService
+ * @return
+ */
+ private ComponentService getPromotedComponentService(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 getPromotedComponentService((CompositeService)service);
+
+ } else {
+
+ // Found a non-composite service
+ return componentService;
+ }
+ } else {
+
+ // No promoted service
+ return null;
+ }
+ }
/**
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
@@ -518,22 +559,24 @@ public class CallableReferenceImpl<B> implements CallableReference<B>, Externali
* @return The Service with the specified serviceName or null if no such Service found.
*/
protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) {
- if (bindingURI.startsWith("/")) {
- bindingURI = bindingURI.substring(1);
- }
-
- final String componentURI = targetComponent.getURI();
- final String serviceName;
- if (componentURI.equals(bindingURI)) {
- // No service specified
- serviceName = "";
- } else {
- // Get the Service name from the Binding URI
- serviceName = bindingURI.substring(componentURI.length() + 1);
- }
-
+
ComponentService targetService = null;
+
if (targetComponent != null) {
+ if (bindingURI.startsWith("/")) {
+ bindingURI = bindingURI.substring(1);
+ }
+
+ final String componentURI = targetComponent.getURI();
+ final String serviceName;
+ if (componentURI.equals(bindingURI)) {
+ // No service specified
+ serviceName = "";
+ } else {
+ // Get the Service name from the Binding URI
+ serviceName = bindingURI.substring(componentURI.length() + 1);
+ }
+
if ("".equals(serviceName)) {
targetService = ComponentContextHelper.getSingleService(targetComponent);
} else {