While debugging through the code for other reasons I came across the
following at
org.apache.tuscany.sca.implementation.java.invocation.JavaComponentInfo line
192.
if (ref.getMultiplicity() == Multiplicity.ONE_N ||
ref.getMultiplicity() == Multiplicity.ZERO_N) {
List<ObjectFactory<?>> factories = new
ArrayList<ObjectFactory<?>>();
for (int i = 0; i < wireList.size (); i++) {
ObjectFactory<?> factory = createWireFactory(
element.getType(), wireList.get(i));
factories.add(factory);
}
configuration.setObjectFactories(element, factories);
} else {
if (wireList == null && ref.getMultiplicity() ==
Multiplicity.ONE_ONE) {
throw new IllegalStateException("Required reference
is missing: " + ref.getName());
}
if (wireList != null && !wireList.isEmpty()) {
ObjectFactory<?> factory = createWireFactory(
element.getType (), wireList.get(0));
configuration.setObjectFactory(element, factory);
}
}
The part of particular interest is the line marked >>>>> at the bottom. The
wire factory created here is used later when injecting the proxy into the
component reference. What I'm interested in is why it takes the first wire
only and in what circustances there will be more than one wire in the
wireList.
I note from the
org.apache.tuscany.sca.core.runtime.ComponentActivatorImplcreateRuntimeWires
method that a wire is created for each binding in each
reference. In this case I suspect that when we create the wire factory we
should be selecting the binding based on what is most appropriate rather
than which is the first one. For example.
If the reference has a "local" target (where local means a target in the
same composite)
If there is more than one
Find all those that match bindings on the target service
If there is more than one
Use the SCA binding if available
Otherwise use the first alternative binding
Otherwise
Use the fist binding on the list
Looking a little higher up the code it would seem that multiple wires are
also created where the cardinality of the reference is greater than one.
I may have interpreted the code here incorrectly. If so can someone explain
how multiple bindings are processed?
Thanks
Simon