RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
component.setName("default");
component.setURI("default");
runtime.getCompositeActivator().configureComponentContext(component);
composite.getComponents().add(component);
RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
reference.setName("default");
ModelFactoryExtensionPoint factories =
runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
reference.setInterfaceContract(interfaceContract);
component.getReferences().add(reference);
reference.setComponent(component);
SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
SCABinding binding = scaBindingFactory.createSCABinding();
// find the service endpoint somewhere else in the domain
try {
String endpointURL = findServiceEndpoint(domainModel.getDomainURI(),
targetURI,
binding.getClass().getName());
if (endpointURL.equals(SERVICE_NOT_REGISTERED)){
logger.log(Level.WARNING, "Created a sevice reference for service that is not yet started: Service " + targetURI);
} else {
targetURI = endpointURL;
}
} catch (DomainException ex){
throw new ServiceRuntimeException(ex);
}
binding.setURI(targetURI);
reference.getBindings().add(binding);
return new ServiceReferenceImpl<B>(businessInterface, component, reference, binding, runtime
.getProxyFactory(), runtime.getCompositeActivator());
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}