// Lookup the component in the domain
Component component = components.get(componentName);
if (component == null) {
throw new ServiceRuntimeException("Component not found: " + componentName);
}
ComponentContext 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) {
ComponentService promotedService = null;
for (ComponentService componentService : component.getServices()) {
if (serviceName == null || serviceName.equals(componentService.getName())) {
CompositeService compositeService = (CompositeService)componentService.getService();
if (compositeService != null) {
promotedService = compositeService.getPromotedService();
SCABinding scaBinding = promotedService.getBinding(SCABinding.class);
if (scaBinding != null) {
Component promotedComponent = scaBinding.getComponent();
if (serviceName != null) {
serviceName = "$promoted$." + serviceName;
}
componentContext = (ComponentContext)promotedComponent;
}
}
break;
}
}
if (componentContext == null) {
throw new ServiceRuntimeException("Composite service not found: " + name);
}
} else {
componentContext = (ComponentContext)component;
}
ServiceReference<B> serviceReference;
if (serviceName != null) {
serviceReference = componentContext.createSelfReference(businessInterface, serviceName);
} else {
serviceReference = componentContext.createSelfReference(businessInterface);
}
return serviceReference;
}