// Connect each component reference to the corresponding reference
for (ComponentReference componentReference : component.getReferences()) {
if (componentReference.getReference() != null || componentReference.isCallback()) {
continue;
}
Reference reference = references.get(componentReference.getName());
if (reference != null) {
componentReference.setReference(reference);
} else {
if (!componentReference.getName().startsWith("$self$.")) {
error(monitor, "ReferenceNotFound", component, component.getName(), componentReference.getName());
}
}
}
// Create a component reference for each reference
if (component.getImplementation() != null) {
for (Reference reference : component.getImplementation().getReferences()) {
if (!componentReferences.containsKey(reference.getName())) {
ComponentReference componentReference =
assemblyFactory.createComponentReference();
componentReference.setIsCallback(reference.isCallback());
componentReference.setName(reference.getName());
componentReference.setReference(reference);
component.getReferences().add(componentReference);
}
}
}
// Reconcile each component reference with its reference
for (ComponentReference componentReference : component.getReferences()) {
Reference reference = componentReference.getReference();
if (reference != null) {
// Reconcile multiplicity
if (componentReference.getMultiplicity() != null) {
if (!ReferenceConfigurationUtil.isValidMultiplicityOverride(reference.getMultiplicity(),
componentReference
.getMultiplicity())) {
warning(monitor, "ReferenceIncompatibleMultiplicity", component, component.getName(), componentReference.getName());
}
} else {
componentReference.setMultiplicity(reference.getMultiplicity());
}
// Reconcile interface
InterfaceContract interfaceContract = reference.getInterfaceContract();
if (componentReference.getInterfaceContract() != null) {
if (interfaceContract != null && !componentReference.getInterfaceContract().equals(reference
.getInterfaceContract())) {
if (!interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(),
interfaceContract)) {
warning(monitor, "ReferenceIncompatibleComponentInterface", component, component.getName(), componentReference.getName());
}
}
} else {
componentReference.setInterfaceContract(interfaceContract);
}
// Reconcile bindings
if (componentReference.getBindings().isEmpty()) {
componentReference.getBindings().addAll(reference.getBindings());
}
// Reconcile callback bindings
if (componentReference.getCallback() == null) {
componentReference.setCallback(reference.getCallback());
if (componentReference.getCallback() == null) {
// Create an empty callback to avoid null check
componentReference.setCallback(assemblyFactory.createCallback());
}
} else if (componentReference.getCallback().getBindings().isEmpty() && reference
.getCallback() != null) {
componentReference.getCallback().getBindings().addAll(reference.getCallback()
.getBindings());
}
// Propagate autowire setting from the component
if (componentReference.getAutowire() == null) {
componentReference.setAutowire(component.getAutowire());
}
// Reconcile targets
if (componentReference.getTargets().isEmpty()) {
componentReference.getTargets().addAll(reference.getTargets());
}
}
}
}