}
if (component == null) {
throw new ServiceUnavailableException("The service " + name + " has not been contributed to the domain");
}
RuntimeComponentContext componentContext = null;
// If the component is a composite, then we need to find the
// non-composite component that provides the requested service
if (component.getImplementation() instanceof Composite) {
for (ComponentService componentService : component.getServices()) {
String bindingName = null;
if (serviceName != null) {
int index = serviceName.indexOf('/');
if (index != -1) {
bindingName = serviceName.substring(index + 1);
serviceName = serviceName.substring(0, index);
}
}
if (serviceName == null || serviceName.equals(componentService.getName())) {
CompositeService compositeService = (CompositeService)componentService.getService();
if (compositeService != null) {
componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
serviceName = compositeService.getPromotedService().getName();
if (bindingName != null) {
serviceName = serviceName + "/" + bindingName;
}
return componentContext.createSelfReference(businessInterface, serviceName);
}
break;
}
}
// No matching service found
throw new ServiceRuntimeException("Composite service not found: " + name);
} else {
componentContext = ((RuntimeComponent)component).getComponentContext();
if (serviceName != null) {
return componentContext.createSelfReference(businessInterface, serviceName);
} else {
return componentContext.createSelfReference(businessInterface);
}
}
}