[jboss-dev-forums] [JBoss Microcontainer Development] - Re: Supporting qualifiers in MC

kabir.khan@jboss.com do-not-reply at jboss.com
Thu Nov 19 10:43:41 EST 2009


I have something working for qualifiers now. The demanded qualifiers are currently only on bean-level (coarse-grained). I've added these methods to BeanMetaData:


  |    /**
  |     * Get the qualifers exposed by this bean
  |     * 
  |     * @return a set of the qualifiers
  |     */
  |    Set<QualifierMetaData> getQualifiers();
  |    
  |    /**
  |     * Get the qualifiers that will be used by default for properties and parameters 
  |     * that don't have explicit qualifiers on their value dependency metadata
  |     * 
  |     * @return a set of the qualifiers
  |     */
  |    Set<QualifierMetaData> getDefaultQualifiers();
  | 
QuailifierMetaData:

  | /**
  |  * MetaData describing the qualifiers
  |  * 
  |  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  |  * @version $Revision: 1.1 $
  |  */
  | public interface QualifierMetaData extends JBossInterface, MetaDataVisitorNode
  | {
  |    /**
  |     * Get the qualifier
  |     * @return the qualifier
  |     */
  |    Object getQualifier();
  | }
  | 

If a bean uses autowiring for it's injection and has "default qualifiers" a ClassAndQualifierKey is used to do the lookups from AbstractInjectionValue and   SearchQualifiedClassDependencyItem (similar to SearchClassDependencyItem, but takes the ClassAndQualifierKey instead of the plain class. The calls from AIV and SQCPI end up here in AbstractKernelController

  |    public KernelRegistryEntry getEntry(Object name)
  |    {
  |       List<KernelControllerContext> list;
  |       
  | +     if (name instanceof ClassAndQualifierKey)
  | +        return ((ClassAndQualifierKey)name).search(this);
  |       if (name instanceof Matcher)
  |          list = matchSupplies((Matcher)name);
  |       else
  |          list = suppliers.get(name);
  | 
  |       if (list != null && list.isEmpty() == false)
  |          return list.get(0);
  |       else if (name instanceof Class)
  |          return getContextByClass((Class<?>) name);
  |       else
  |          return null;
  |    }
  | 

The ClassAndQualifierKey contains the logic to find the context with the qualifiers, and here briefly is what it does

  | class ClassAndQualifierKey
  | {
  |    Class<?> type;
  |    ControllerState dependentState;
  |    Set<Object> qualifiers;
  | 
  |    public KernelControllerContext search(KernelController controller)
  |    {
  | 	Set<KernelControllerContext> contexts = controller.getContexts(type, dependentState);
  |         for (KernelControllerContext context : contexts)
  |         {
  |            for (Object myqualifier : qualifiers)
  |            {
  |               for (QualifierMetaData qualifier : context.getQualifierMetaData())
  |               {
  |                  //check myqualifier vs qualifier.getQualifier()
  |               }
  |            }
  |         }
  |    }
  | }
  | 

As you can see I am not using MDR at all yet at this stage. Where do you see MDR fitting in? Is the idea to add all contexts that have a qualifier to somewhere in MDR and to be able to query that to avoid iterating over all contexts, or do you have something else in mind? I think I am missing what you guys mean by filtering in that other thread

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266584#4266584

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266584



More information about the jboss-dev-forums mailing list