*/
private synchronized void resolve() throws Exception {
if (scdl != null && component == null && reference == null) {
ComponentContextHelper componentContextHelper = ComponentContextHelper.getCurrentComponentContextHelper();
if (componentContextHelper != null) {
CompositeActivator currentActivator = ComponentContextHelper.getCurrentCompositeActivator();
this.compositeActivator = currentActivator;
Component c = componentContextHelper.fromXML(scdl);
this.component = (RuntimeComponent)c;
currentActivator.configureComponentContext(this.component);
this.reference = (RuntimeComponentReference)c.getReferences().get(0);
this.reference.setComponent(this.component);
URI uri = URI.create("/" + componentURI);
for (Binding binding : reference.getBindings()) {
if (binding instanceof WireableBinding) {
String targetURI = uri.resolve(binding.getURI()).toString();
int index = targetURI.lastIndexOf('/');
String serviceName = targetURI.substring(index + 1);
targetURI = targetURI.substring(1, index);
Component targetComponet = compositeActivator.resolve(targetURI);
ComponentService targetService = null;
if (targetComponet != null) {
if ("".equals(serviceName)) {
targetService = ComponentContextHelper.getSingleService(targetComponet);
} else {
for (ComponentService service : targetComponet.getServices()) {
if (service.getName().equals(serviceName)) {
targetService = service;
break;
}
}
}
}
WireableBinding wireableBinding = (WireableBinding)binding;
wireableBinding.setTargetComponent(targetComponet);
wireableBinding.setTargetComponentService(targetService);
if (targetService != null) {
for (Binding serviceBinding : targetService.getBindings()) {
if (serviceBinding.getClass() == binding.getClass()) {
wireableBinding.setTargetBinding(serviceBinding);
break;
}
}
}
}
}
// FIXME: The SCA spec is not clear how we should handle multiplicty for CallableReference
if (binding == null) {
binding = reference.getBinding(SCABinding.class);
if (binding == null) {
binding = reference.getBindings().get(0);
}
}
Interface i = reference.getInterfaceContract().getInterface();
if (i instanceof JavaInterface) {
JavaInterface javaInterface = (JavaInterface)i;
if (javaInterface.isUnresolved()) {
javaInterface.setJavaClass(Thread.currentThread().getContextClassLoader()
.loadClass(javaInterface.getName()));
currentActivator.getJavaInterfaceFactory().createJavaInterface(javaInterface,
javaInterface.getJavaClass());
}
this.businessInterface = (Class<B>)javaInterface.getJavaClass();
}
this.proxyFactory = currentActivator.getProxyFactory();
}
}
}