Map<String, Reference> references,
Map<String, ComponentReference> componentReferences) {
// Connect each component reference to the corresponding reference
for (ComponentReference componentReference : component.getReferences()) {
Reference reference = references.get(componentReference.getName());
if (reference != null) {
componentReference.setReference(reference);
} else {
if (!componentReference.getName().startsWith("$self$.")) {
warning("Reference not found for component reference: " + component.getName()
+ "/"
+ componentReference.getName(), component);
}
}
}
// 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 (!ReferenceUtil.isValidMultiplicityOverride(reference.getMultiplicity(),
componentReference
.getMultiplicity())) {
warning("Component reference multiplicity incompatible with reference multiplicity: " + component
.getName()
+ "/"
+ componentReference.getName(),
component);
}
} else {
componentReference.setMultiplicity(reference.getMultiplicity());
}
// Reconcile interface
if (componentReference.getInterfaceContract() != null) {
if (!componentReference.getInterfaceContract().equals(reference
.getInterfaceContract())) {
if (!interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
componentReference
.getInterfaceContract())) {
warning("Component reference interface incompatible with reference interface: " + component
.getName()
+ "/"
+ componentReference.getName(),
component);
}
}
} else {
componentReference.setInterfaceContract(reference.getInterfaceContract());
}
// 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());
}
}
}
}