public RuntimeComponentReference bindComponentReference(Class<?> businessInterface,
RuntimeComponentReference reference,
RuntimeComponent component,
RuntimeComponentService service)
throws CloneNotSupportedException, InvalidInterfaceException {
RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
InterfaceContract interfaceContract = reference.getInterfaceContract();
Reference componentTypeReference = reference.getReference();
if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) {
interfaceContract = componentTypeReference.getInterfaceContract();
}
InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
if (refInterfaceContract != interfaceContract) {
ref = (RuntimeComponentReference)reference.clone();
ref.setInterfaceContract(interfaceContract);
}
ref.setComponent(component);
ref.getTargets().add(service);
ref.getBindings().clear();
for (Binding binding : service.getBindings()) {
if (binding instanceof OptimizableBinding) {
OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
optimizableBinding.setTargetBinding(binding);
optimizableBinding.setTargetComponent(component);
optimizableBinding.setTargetComponentService(service);
ref.getBindings().add(optimizableBinding);
} else {
ref.getBindings().add(binding);
}
}
return ref;
}