// - will find it here if the system has constructed the callback binding based on the forward binding
//
// 2 and 3 are conflated in the distributed case as be write any derived callback bindings out into the
// callback structure as the endpoint is serialized across the domain
RuntimeEndpoint callbackEndpoint = null;
// 1/ look in callback endpoints at the reference
// - exploiting the assumption that the user will specific callback bindings of
// the same type as the forward binding
match1:
for(Endpoint loopCallbackEndpoint : callbackService.getEndpoints()){
if(loopCallbackEndpoint.getBinding().getType().equals(endpointReference.getBinding().getType())){
callbackEndpoint = (RuntimeEndpoint)loopCallbackEndpoint;
break match1;
}
}
// if no callback endpoint was found then create a new callback endpoint
if (callbackEndpoint == null ){
callbackEndpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint();
callbackEndpoint.setComponent(endpointReference.getComponent());
callbackEndpoint.setService(callbackService);
Binding forwardBinding = endpointReference.getBinding();
Binding callbackBinding = null;
// 2/ look in the service callback structure
Callback serviceCallback = endpointReference.getTargetEndpoint().getService().getCallback();
if (serviceCallback != null){
for(Binding loopCallbackBinding : serviceCallback.getBindings()){
if(loopCallbackBinding.getType().equals(endpointReference.getBinding().getType())){
callbackBinding = loopCallbackBinding;
break;
}
}
}
// 3/ look in the service endpoint callback reference structure
ComponentReference callbackReference = endpointReference.getTargetEndpoint().getService().getCallbackReference();
if (callbackReference != null){
for (EndpointReference loopEndpointReference : callbackReference.getEndpointReferences()){
if (loopEndpointReference.getBinding().getType().equals(endpointReference.getBinding().getType())){
callbackBinding = loopEndpointReference.getBinding();
break;
}
}
}
// if all else fails clone the forward binding
// TODO - do we ever get here?
if (callbackBinding == null){
try {
callbackBinding = (Binding)forwardBinding.clone();
} catch (CloneNotSupportedException ex){
}
}
// get the callback binding URI by looking at the SCA binding
// that will have been added at build time
callbackBinding.setURI(null);
for (Endpoint endpoint : callbackService.getEndpoints()){
if (endpoint.getBinding().getType().equals(SCABinding.TYPE)){
callbackBinding.setURI(endpoint.getBinding().getURI());
}
}
callbackEndpoint.setBinding(callbackBinding);
callbackService.getBindings().add(callbackBinding);
callbackEndpoint.setUnresolved(false);
callbackService.getEndpoints().add(callbackEndpoint);
// build it
build(callbackEndpoint);