Reference componentTypeRef = reference.getReference();
InterfaceContract sourceContract =
componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
sourceContract = sourceContract.makeUnidirectional(false);
EndpointReference wireSource =
new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
ComponentService callbackService = reference.getCallbackService();
if (callbackService != null) {
// select a reference callback binding to pass with invocations on this wire
Binding callbackBinding = null;
for (Binding binding : callbackService.getBindings()) {
// first look for a callback binding whose name matches the reference binding name
if (refBinding.getName().startsWith(binding.getName())) {
callbackBinding = binding;
break;
}
}
// if no callback binding found, try again based on reference binding type
if (callbackBinding == null) {
callbackBinding = callbackService.getBinding(refBinding.getClass());
}
InterfaceContract callbackContract = callbackService.getInterfaceContract();
EndpointReference callbackEndpoint =
new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
callbackContract);
wireSource.setCallbackEndpoint(callbackEndpoint);
}
EndpointReference wireTarget =
new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract);
RuntimeWire wire =
new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor,
messageFactory, conversationManager);