endpointRef.setReference(reference);
endpointRef.setUnresolved(false);
// create dummy endpoint. This will be replaced when policies
// are matched and bindings are configured later
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setComponent(targetComponent);
endpoint.setService(targetComponentService);
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
if (multiplicity == Multiplicity.ZERO_ONE ||
multiplicity == Multiplicity.ONE_ONE) {
break;
}
}
}
}
}
if (multiplicity == Multiplicity.ONE_N ||
multiplicity == Multiplicity.ONE_ONE) {
if (reference.getEndpointReferences().size() == 0) {
warning(monitor,
"NoComponentReferenceTarget",
reference,
reference.getName());
}
}
} else if (!reference.getTargets().isEmpty()) {
// Check that the component reference does not mix the use of
// endpoint references specified via the target attribute with
// the presence of binding elements
if (reference.getBindings().size() > 0) {
warning(monitor, "ReferenceEndPointMixWithTarget",
composite, reference.getName());
}
// Resolve targets specified on the component reference
for (ComponentService target : reference.getTargets()) {
String targetName = target.getName();
ComponentService targetComponentService = componentServices.get(targetName);
Component targetComponent;
int s = targetName.indexOf('/');
if (s == -1) {
targetComponent = components.get(targetName);
} else {
targetComponent = components.get(targetName.substring(0, s));
}
if (targetComponentService != null) {
// Check that the target component service provides
// a superset of the component reference interface
if (reference.getInterfaceContract() == null ||
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
// create endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setUnresolved(false);
// create dummy endpoint. This will be replaced when policies
// are matched and bindings are configured later
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setComponent(targetComponent);
endpoint.setService(targetComponentService);
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
warning(monitor,
"ReferenceIncompatibleInterface",
composite,
composite.getName().toString(),
reference.getName(),
targetName);
}
} else {
// add an unresolved endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setUnresolved(true);
// create an unresolved endpoint to go with it
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
warning(monitor,
"ComponentReferenceTargetNotFound",
composite,
composite.getName().toString(),
targetName);
}
}
} else if ((reference.getReference() != null)
&& (!reference.getReference().getTargets().isEmpty())) {
// Resolve targets from the corresponding reference in the
// componentType
for (ComponentService target : reference.getReference().getTargets()) {
String targetName = target.getName();
ComponentService targetComponentService = componentServices.get(targetName);
Component targetComponent;
int s = targetName.indexOf('/');
if (s == -1) {
targetComponent = components.get(targetName);
} else {
targetComponent = components.get(targetName.substring(0, s));
}
if (targetComponentService != null) {
// Check that the target component service provides
// a superset of the component reference interface
if (reference.getInterfaceContract() == null ||
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
// create endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setUnresolved(false);
// create dummy endpoint. This will be replaced when policies
// are matched and bindings are configured later
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setComponent(targetComponent);
endpoint.setService(targetComponentService);
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
warning(monitor,
"ReferenceIncompatibleInterface",
composite,
composite.getName().toString(),
reference.getName(),
targetName);
}
} else {
// add an unresolved endpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setUnresolved(true);
// create an unresolved endpoint to go with it
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
warning(monitor,
"ComponentReferenceTargetNotFound",
composite,
composite.getName().toString(),
targetName);
}
}
}
// if no endpoints have found so far the bindings become targets.
if (reference.getEndpointReferences().isEmpty()) {
for (Binding binding : reference.getBindings()) {
String uri = binding.getURI();
// user hasn't put a uri on the binding so it's not a target
// name
if (uri == null) {
// create endpoint reference for manually configured bindings
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setBinding(binding);
endpointRef.setTargetEndpoint(null);
endpointRef.setUnresolved(false);
// create a resolved endpoint to signify that this
// reference is pointing at some unwired endpoint
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setUnresolved(false);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
continue;
}
// user might have put a local target name in the uri
// see if it refers to a target we know about
// - if it does the reference binding will be matched with a
// service binding
// - if it doesn't it is assumed to be an external reference
Component targetComponent = null;
ComponentService targetComponentService = null;
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
// Resolve the target component and service
targetComponentService = componentServices.get(uri);
int s = uri.indexOf('/');
if (s == -1) {
targetComponent = components.get(uri);
} else {
targetComponent = components.get(uri.substring(0, s));
}
// if the binding URI matches a component in the
// composite then configure an endpoint reference with this component as
// the target. If not then the binding URI will be assumed to reference an
// external service
if (targetComponentService != null) {
// Check that the target component service provides
// a superset of the component reference interface
if (reference.getInterfaceContract() == null ||
interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
targetComponentService.getInterfaceContract())) {
// create enpoint reference
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setBinding(binding);
endpointRef.setUnresolved(false);
// create dummy endpoint. This will be replaced when policies
// are matched and bindings are configured later
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setComponent(targetComponent);
endpoint.setService(targetComponentService);
endpoint.setUnresolved(true);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
} else {
warning(monitor,
"ReferenceIncompatibleInterface",
composite,
composite.getName().toString(),
reference.getName(),
uri);
}
} else {
// create endpoint reference for manually configured bindings
EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
endpointRef.setComponent(component);
endpointRef.setReference(reference);
endpointRef.setBinding(binding);
endpointRef.setTargetEndpoint(null);
endpointRef.setUnresolved(false);
// create a resolved endpoint to signify that this
// reference is pointing at some unwired endpoint
Endpoint2 endpoint = assemblyFactory.createEndpoint();
endpoint.setUnresolved(false);
endpointRef.setTargetEndpoint(endpoint);
reference.getEndpointReferences().add(endpointRef);
}
}