in modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java [111:200]
private void configureNestedCompositeReferences(Composite composite) {
// Process nested composites recursively
for (Component component : composite.getComponents()) {
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
// First process nested composites
configureNestedCompositeReferences((Composite)implementation);
// Process the component references declared on components in this composite
for (ComponentReference componentReference : component.getReferences()) {
Reference implReference = componentReference.getReference();
if (implReference != null && implReference instanceof CompositeReference) {
CompositeReference compositeReference = (CompositeReference)implReference;
// Get the next lower level promoted reference
List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
if (!promotedRefs.isEmpty()) {
if (promotedRefs.size() == 1) {
ComponentReference promotedReference = promotedRefs.get(0);
// Set the bindings using the top level bindings to override the lower level bindings
if (!bindingsSpecifiedManually(compositeReference.getBindings()) &&
bindingsSpecifiedManually(promotedReference.getBindings()) ) {
compositeReference.getBindings().clear();
for (Binding binding : promotedReference.getBindings()) {
try {
compositeReference.getBindings().add((Binding)binding.clone());
} catch (CloneNotSupportedException ex) {
// this binding can't be used in the promoted reference
}
}
}
if (bindingsSpecifiedManually(componentReference.getBindings())) {
componentReference.setPromotionOverride(true);
} else if (bindingsSpecifiedManually(compositeReference.getBindings()) ) {
componentReference.getBindings().clear();
componentReference.getBindings().addAll(compositeReference.getBindings());
}
if (componentReference.getInterfaceContract() != null &&
componentReference.getInterfaceContract().getCallbackInterface() != null) {
if (!(compositeReference.getCallback() != null &&
bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) &&
promotedReference.getCallback() != null &&
bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
if (compositeReference.getCallback() != null) {
compositeReference.getCallback().getBindings().clear();
} else {
compositeReference.setCallback(assemblyFactory.createCallback());
}
compositeReference.getCallback().getBindings().addAll(
promotedReference.getCallback().getBindings());
}
if (componentReference.getCallback() != null &&
bindingsSpecifiedManually(componentReference.getCallback().getBindings())) {
componentReference.setPromotionOverride(true);
} else if (compositeReference.getCallback() != null &&
bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
if (componentReference.getCallback() != null) {
componentReference.getCallback().getBindings().clear();
} else {
componentReference.setCallback(assemblyFactory.createCallback());
}
for (Binding binding : compositeReference.getCallback().getBindings()) {
try {
componentReference.getCallback().getBindings().add((Binding)binding.clone());
} catch (CloneNotSupportedException ex) {
// this binding can't be used in the promoted reference
}
}
}
}
} else {
// This component reference promotes multiple lower-level component references.
// Because the lower-level component reference bindings can all be different,
// we don't copy any of them up to this component reference, which will therefore
// always have its own binding, even if it's only the default SCA binding.
if (bindingsSpecifiedManually(componentReference.getBindings()) ||
(componentReference.getCallback() != null &&
bindingsSpecifiedManually(componentReference.getCallback().getBindings()))) {
componentReference.setPromotionOverride(true);
}
}
}
}
}
}
}
}