Following Ales's suggestions what I now have is:
Qualifier metadata is implemented as RelatedClassMetaData, where the qualifier objects are
stored in RCMD.getEnabled(). To pick out the RCMDs that specify qualifiers I use
'RCMB#SUPPLIED_QUALIFIER' as the classname, and 'RCMB#WANTED_QUALIFIER' as
the classname for wanted qualifiers specified at bean level.
Following the population of the metadata and beaninfo in PreInstallAction (and in
InstallAction if beaninfo was null) I populate the MDR with sets of qualifiers from the
metadata. These are stored in the INSTANCE level metadata under
'RCMB#SUPPLIED_QUALIFIER' and 'RCMB#WANTED_QUALIFIER' respectively.
The search algorithm works much the same as before. ClassAndQualifierKey queries for all
the beans implementing a class, and then narrows it down depending on the wanted
qualifiers and the required qualifiers.
Before I commit, I want to add some xml configuration of qualifiers. I propose
| <bean name="bean1" class="SomeBean">
| <qualifier>a</qualifier>
| </bean>
| <bean name="bean2"class="SomeBean">
| <qualifier>a</qualifier>
| </qualifier>b</qualifier>
| </bean>
| <bean name="bean3" class="OtherBean">
| <qualifier type="default">a</qualifier>
| </bean>
|
Meaning that the bean1 supplies qualifier 'a', bean2 supplies qualifiers
'a', 'b' and bean3 uses 'a' by default when looking for other
beans to inject into it. So when injecting SomeBean instances into bean3, bean1 will be
chosen.
Next, I want to look at somehow supporting fine-grained qualifiers injection. If we have
two instances of
| class Bean{}
|
where instance 1 supplies qualifier 'A' and instance 2 supplies qualifier
'B' and we have
| class Target
| {
| Bean a;
|
| Bean b;
|
| @Constructor
| Target(@Inject Bean a)
| {
| this.a = a;
| }
|
| @Inject
| void setB()
| {
| this.b = b;
| }
| }
|
It should be possible to specify qualifiers for injected parameters and properties, so
that in this example we can say the constructor wants the Bean with qualifier 'A'
while the setter wants the Bean with the qualifier 'B'. I'll see if I can
use/expand AbstractInjectionValueMetaData to use qualifiers.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4267275#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...