Hi,
There are two issues behind:
1) For a reference with multiplicity 1..1, there should be one and only one
target and that's why wireList.get(0) is used. To find the corresponding
wire for a given binding, we have a better way:
RuntimeComponentReference.getRuntimeWire(Binding binding).
2) Potentially, a reference with multiplicity 1..1 could have multiple
bindings. When we take the binding selection into consideration, there
should be only one resolved binding. Should it be done when we flatten the
model?
Thanks,
Raymond
----- Original Message -----
From: "Simon Laws" <[EMAIL PROTECTED]>
To: "tuscany-dev" <[email protected]>
Sent: Tuesday, May 29, 2007 1:52 PM
Subject: Wire binding selection?
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
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]