[jboss-cvs] JBossAS SVN: r97043 - in projects/kernel/trunk/kernel/src: main/java/org/jboss/beans/metadata/plugins and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 26 13:20:49 EST 2009


Author: kabir.khan at jboss.com
Date: 2009-11-26 13:20:49 -0500 (Thu, 26 Nov 2009)
New Revision: 97043

Added:
   projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersIgnored.xml
   projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersNotIgnoredByDefault.xml
Modified:
   projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/api/annotations/Inject.java
   projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
   projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
   projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
   projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java
   projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/InjectionPointQualifiersTestCase.java
   projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase.java
Log:
[JBKERNEL-63] Include bean qualifiers by default when using injection point qualifiers, with the option to turn them off

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/api/annotations/Inject.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/api/annotations/Inject.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/api/annotations/Inject.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -110,4 +110,11 @@
     * @return is this instance valid
     */
    boolean valid() default true;
+   
+   /**
+    * Whether we should only add qualifiers from the injection point (true) or include the ones from the bean and MDR as well (false)
+    * 
+    *  @return if we should ignore the bean/MDR qualifiers
+    */
+   boolean ignoreBeanQualifiers() default false;
 }

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -44,6 +44,7 @@
 import org.jboss.kernel.plugins.dependency.SearchClassContextDependencyItem;
 import org.jboss.kernel.plugins.dependency.SearchQualifiedClassDependencyItem;
 import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.test.kernel.qualifiers.support.Bean;
 import org.jboss.util.JBossStringBuilder;
 
 /**
@@ -65,6 +66,9 @@
    /** Used as the key to get the injected context when qualifiers are present */
    protected ClassAndQualifierKey classAndQualifierMatcher;
    
+   /** If qualifiers are used, true if we should ignore the qualifiers on the bean and only take into account the qualifiers on this injection point*/ 
+   protected boolean ignoreBeanQualifiers;
+   
    /** Qualifiers specified on the injection point. If not present the context's wanted qualifiers from the MDR metadata is used */
    protected Set<RelatedClassMetaData> qualifiers;
 
@@ -165,6 +169,25 @@
    }
 
    /**
+    * Get the ignoreBeanQualifiers
+    * @return the ignoreBeanQualifiers
+    */
+   public boolean isIgnoreBeanQualifiers()
+   {
+      return ignoreBeanQualifiers;
+   }
+
+   /**
+    * Set the ignoreBeanQualifiers
+    * @param ignoreBeanQualifiers the ignoreBeanQualifiers to set
+    */
+   @XmlAttribute(name="ignoreBeanQualifiers")
+   public void setIgnoreBeanQualifiers(boolean ignoreBeanQualifiers)
+   {
+      this.ignoreBeanQualifiers = ignoreBeanQualifiers;
+   }
+
+   /**
     * Add install/callback item.
     *
     * @param name the callback name
@@ -394,7 +417,7 @@
             for (RelatedClassMetaData rcmd : qualifiers)
                qualifierObjects.addAll(rcmd.getEnabled());
          }
-         classAndQualifierMatcher = new ClassAndQualifierKey(dependentState, context, qualifierObjects, injectionClass);
+         classAndQualifierMatcher = new ClassAndQualifierKey(dependentState, context, ignoreBeanQualifiers, qualifierObjects, injectionClass);
          return new SearchQualifiedClassDependencyItem(context.getName(), 
                classAndQualifierMatcher,
                whenRequired, 

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -1102,7 +1102,7 @@
       return new AbstractInjectionValueMetaData(name);
    }
 
-   public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search, Object...qualifiers)
+   public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search, boolean ignoreBeanQualifiers, Object...qualifiers)
    {
       AbstractInjectionValueMetaData result = createAbstractInjectionValueMetaData();
       if (whenRequired != null)
@@ -1126,6 +1126,7 @@
             qualifierSet.add(qmd);
          }
          result.setQualifiers(qualifierSet);
+         result.setIgnoreBeanQualifiers(ignoreBeanQualifiers);
       }
       return result;
    }

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -2111,8 +2111,9 @@
     * but looks at the target property/parameter type for autowiring
     *
     * @see BeanMetaData#isAutowireCandidate()
-    * @param the qualifiers to use to narrow down beans of the matching type. These will override the ones specified for the 
-    * whole bean in {@link #addRequiredQualifiers(Object...)} 
+    * @param the qualifiers to use to narrow down beans of the matching type. These will come in addition to the bean level ones 
+    * specified in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * level in the MDR 
     * @return the contextual injection
     */
    public ValueMetaData createContextualInject(Object...qualifiers)
@@ -2121,6 +2122,25 @@
    }
 
    /**
+    * Create contextual injection, using the default
+    * whenRequired state of {@link ControllerState#CONFIGURED} and the default dependentState of
+    * {@link ControllerState#INSTANTIATED}. This does not need to specify the name of the bean, 
+    * but looks at the target property/parameter type for autowiring
+    *
+    * @see BeanMetaData#isAutowireCandidate()
+    * 
+    * @param ignoreBeanQualifiers Whether we should ignore bean level qualifiers and only use the ones specified here. Default is false
+    * @param the qualifiers to use to narrow down beans of the matching type. These will override or come in addition to the bean level ones
+    * specified in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)}and to the ones from higher 
+    * levels in the MDR, depending on the value of ignoreBeanQualifiers
+    * @return the contextual injection
+    */
+   public ValueMetaData createContextualInject(boolean ignoreBeanQualifiers, Object...qualifiers)
+   {
+      return createContextualInject(null, null, ignoreBeanQualifiers, qualifiers);
+   }
+
+   /**
     * Create contextual injection. This does not need to specify the name of the bean, 
     * but looks at the target property/parameter type for autowiring
     *
@@ -2141,8 +2161,9 @@
     * @see BeanMetaData#isAutowireCandidate()
     * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
     * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
-    * @param the qualifiers to use to narrow down beans of the matching type. These will override the ones specified for the 
-    * whole bean in {@link #addRequiredQualifiers(Object...)} 
+    * @param the qualifiers to use to narrow down beans of the matching type. These will come in addition to the ones 
+    * in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * levels in the MDR 
     * @return the contextual injection
     */
    public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, Object...qualifiers)
@@ -2155,6 +2176,24 @@
     * but looks at the target property/parameter type for autowiring
     *
     * @see BeanMetaData#isAutowireCandidate()
+    * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
+    * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
+    * @param ignoreBeanQualifiers Whether we should ignore bean level qualifiers and only use the ones specified here. Default is false
+    * @param the qualifiers to use to narrow down beans of the matching type. These will override or come in addition to the bean level ones
+    * specified in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * levels in the MDR  depending on the value of ignoreBeanQualifiers
+    * @return the contextual injection
+    */
+   public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, boolean ignoreBeanQualifiers, Object...qualifiers)
+   {
+      return createContextualInject(whenRequired, dependentState, null, null, ignoreBeanQualifiers, qualifiers);
+   }
+
+   /**
+    * Create contextual injection. This does not need to specify the name of the bean, 
+    * but looks at the target property/parameter type for autowiring
+    *
+    * @see BeanMetaData#isAutowireCandidate()
     * @see BeanMetaData#getAutowireType()
     * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
     * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
@@ -2164,7 +2203,7 @@
     */
    public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option)
    {
-      return createContextualInject(whenRequired, dependentState, autowire, option, null, null);
+      return createContextualInject(whenRequired, dependentState, autowire, option, null, false, (Object[])null);
    }
 
    /**
@@ -2177,8 +2216,9 @@
     * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
     * @param autowire the autowire type. If null, the type is {@link AutowireType#BY_CLASS} 
     * @param option the inject option
-    * @param the qualifiers to use to narrow down beans of the matching type. These will override the ones specified for the 
-    * whole bean in {@link #addRequiredQualifiers(Object...)} 
+    * @param the qualifiers to use to narrow down beans of the matching type. These will come in addition to the ones 
+    * in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * levels in the MDR  
     * @return the contextual injection
     */
    public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, Object...qualifiers)
@@ -2190,17 +2230,61 @@
     * Create contextual injection. This does not need to specify the name of the bean, 
     * but looks at the target property/parameter type for autowiring
     *
+    * @see BeanMetaData#isAutowireCandidate()
+    * @see BeanMetaData#getAutowireType()
     * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
     * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
+    * @param autowire the autowire type. If null, the type is {@link AutowireType#BY_CLASS} 
+    * @param option the inject option
+    * @param ignoreBeanQualifiers Whether we should ignore bean level qualifiers and only use the ones specified here. Default is false
+    * @param the qualifiers to use to narrow down beans of the matching type. These will override or come in addition to the bean level ones
+    * specified in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)}and to the ones from higher 
+    * levels in the MDR, depending on the value of ignoreBeanQualifiers
+    * @return the contextual injection
+    */
+   public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, boolean ignoreBeanQualifiers, Object...qualifiers)
+   {
+      return createContextualInject(whenRequired, dependentState, autowire, option, null, ignoreBeanQualifiers, qualifiers);
+   }
+
+
+   /**
+    * Create contextual injection. This does not need to specify the name of the bean, 
+    * but looks at the target property/parameter type for autowiring
+    *
+    * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
+    * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
     * @param autowire the autowire type
     * @param option the inject option
     * @param search the search info describing how to search for the injected bean if we have a hierarchy of 
     * {@link org.jboss.dependency.spi.Controller}s
-    * @param the qualifiers to use to narrow down beans of the matching type. These will override the ones specified for the 
-    * whole bean in {@link #addRequiredQualifiers(Object...)} 
+    * @param the qualifiers to use to narrow down beans of the matching type. These will come in addition to the ones 
+    * in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * levels in the MDR  
     * @return the contextual injection
     */
-   public abstract ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search, Object...qualifiers);
+   public ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search, Object...qualifiers)
+   {
+      return createContextualInject(whenRequired, dependentState, autowire, option, search, false, qualifiers);
+   }
+
+   /**
+    * Create contextual injection. This does not need to specify the name of the bean, 
+    * but looks at the target property/parameter type for autowiring
+    *
+    * @param whenRequired when the injection is required. If null {@link ControllerState#CONFIGURED} is used.
+    * @param dependentState the required state of the injected bean. If null {@link ControllerState#INSTALLED} is used.
+    * @param autowire the autowire type
+    * @param option the inject option
+    * @param search the search info describing how to search for the injected bean if we have a hierarchy of 
+    * {@link org.jboss.dependency.spi.Controller}s
+    * @param ignoreBeanQualifiers Whether we should ignore bean level qualifiers and only use the ones specified here. Default is false
+    * @param the qualifiers to use to narrow down beans of the matching type. These will override or come in addition to the bean level ones
+    * specified in {@link #addRequiredQualifiers(Object...)} and {@link #addOptionalQualifiers(Object...)} and to the ones from higher 
+    * levels in the MDR, depending on the value of ignoreBeanQualifiers
+    * @return the contextual injection
+    */
+   public abstract ValueMetaData createContextualInject(ControllerState whenRequired, ControllerState dependentState, AutowireType autowire, InjectOption option, SearchInfo search, boolean ignoreBeanQualifiers, Object...qualifiers);
    
    /**
     * Inject values from the context of the bean we are creating, using the default

Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -42,22 +42,26 @@
 public class ClassAndQualifierKey extends JBossObject
 {
    /** The type of class we are looking for */
-   private final Class<?> type;
+   protected final Class<?> type;
    
    /** The state of the dependency */
-   private final ControllerState dependentState;
+   protected final ControllerState dependentState;
    
    /** The context containing the wanted qualifiers */
-   private final KernelControllerContext context;
+   protected final KernelControllerContext context;
    
-   private final Set<Object> injectionPointQualifiers;
+   /** The qualifiers defined on the injection point */
+   protected final Set<Object> injectionPointQualifiers;
    
-   public ClassAndQualifierKey(ControllerState dependentState, KernelControllerContext context, Set<Object> injectionPointQualifiers, Class<?> type)
+   protected final boolean ignoreBeanQualifiers; 
+   
+   public ClassAndQualifierKey(ControllerState dependentState, KernelControllerContext context, boolean ignoreBeanQualifiers, Set<Object> injectionPointQualifiers, Class<?> type)
    {
       this.dependentState = dependentState == null ? ControllerState.INSTALLED : dependentState;
       this.context = context;
       this.injectionPointQualifiers = injectionPointQualifiers != null && injectionPointQualifiers.size() > 0 ? injectionPointQualifiers : null;
       this.type = type;
+      this.ignoreBeanQualifiers = ignoreBeanQualifiers;
    }
    
    /**
@@ -69,9 +73,26 @@
       
       if (contexts == null || contexts.size() == 0)
          return null;
-
-      Set<Object> requiredQualifiers = (injectionPointQualifiers != null) ? injectionPointQualifiers : QualifiersMdrUtil.mergeRequiredQualifiersFromMdr(context);
-      Set<Object> optionalQualifiers = QualifiersMdrUtil.mergeOptionalQualifiersFromMdr(context);
+      
+      Set<Object> requiredQualifiers = null;
+      if (injectionPointQualifiers != null)
+      {
+         if (ignoreBeanQualifiers)
+            requiredQualifiers = injectionPointQualifiers;
+         else
+         {
+            requiredQualifiers = QualifiersMdrUtil.mergeRequiredQualifiersFromMdr(context);
+            if (requiredQualifiers == null)
+               requiredQualifiers = new HashSet<Object>();
+            requiredQualifiers.addAll(injectionPointQualifiers);
+         }
+      }
+      else
+      {
+         requiredQualifiers = QualifiersMdrUtil.mergeRequiredQualifiersFromMdr(context);
+      }
+      
+      Set<Object> optionalQualifiers = ignoreBeanQualifiers ? null : QualifiersMdrUtil.mergeOptionalQualifiersFromMdr(context);
       if ((requiredQualifiers == null || requiredQualifiers.size() == 0) && (optionalQualifiers == null || optionalQualifiers.size() == 0))
          return getFirstContext(contexts);
          
@@ -109,92 +130,6 @@
       return found;
    }
    
-   private List<ControllerContext> getContextsWithAllQualifiers(Set<Object> qualifiers, Set<ControllerContext> contexts)
-   {
-      List<ControllerContext> found = new ArrayList<ControllerContext>();
-      
-      for (ControllerContext context : contexts)
-      {
-         Set<Object> suppliedQualifiers = QualifiersMdrUtil.mergeSuppliedQualifiersFromMdr(context);
-         if (suppliedQualifiers == null || suppliedQualifiers.size() == 0)
-            continue;
-         
-         boolean hasAllQualifiers = true;
-         for (Object wanted : qualifiers)
-         {
-            boolean matched = false;
-            for (Object supplied : suppliedQualifiers)
-            {
-               if (equals(supplied, wanted))
-               {
-                  matched = true;
-                  break;
-               }
-            }
-            if (!matched)
-            {
-               hasAllQualifiers = false;
-               break;
-            }
-         }
-         
-         if (hasAllQualifiers)
-            found.add(context);
-      }
-      return found;
-   }
-   
-   private List<ControllerContext> getContextsWithMostQualifiers(Set<Object> qualifiers, Collection<ControllerContext> contexts)
-   {
-      int max = 0;
-      List<ControllerContext> found = new ArrayList<ControllerContext>();
-      
-      for (ControllerContext context : contexts)
-      {
-         Set<Object> suppliedQualifiers = QualifiersMdrUtil.mergeSuppliedQualifiersFromMdr(context);
-         if (suppliedQualifiers == null || suppliedQualifiers.size() == 0)
-            continue;
-         
-         
-         int matches = 0;
-         boolean allTargetQualifiersMatched = true;
-         for (Object supplied : suppliedQualifiers)
-         {
-            boolean matched = false;
-            for (Object wanted : qualifiers)
-            {
-               if (equals(supplied, wanted))
-               {
-                  matched = true;
-                  break;
-               }
-            }
-            if (matched)
-               matches++;
-            else
-            {
-               allTargetQualifiersMatched = false;
-               break;
-            }
-         }
-         
-         if (allTargetQualifiersMatched)
-         {
-            if (matches > max)
-            {
-               found.clear();
-               found.add(context);
-               max = matches;
-            }
-            else if (matches == max)
-            {
-               found.add(context);
-            }
-         }
-      }
-      return found;
-   }
-
    private List<ControllerContext> getContextWithAllRequiredAndMostOptionalQualifiers(Set<Object> requiredQualifiers, Set<Object> optionalQualifiers, Collection<ControllerContext> contexts)
    {
       int max = 0;

Modified: projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/InjectionPointQualifiersTestCase.java
===================================================================
--- projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/InjectionPointQualifiersTestCase.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/InjectionPointQualifiersTestCase.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -259,32 +259,32 @@
       }
    }
    
-   public void testWantedBeanQualifiersIgnoredWhenPropertyQualifiersPresent() throws Throwable
+   public void testBeanRequiredQualifiersNotIgnoredByDefaultForProperty() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent(TargetPropertyBean.class, TargetType.PROPERTY);
+      testBeanRequiredQualifiersNotIgnoredByDefault(TargetPropertyBean.class, TargetType.PROPERTY);
    }
 
-   public void testWantedQualifiersIgnoredWhenConstructorQualifiersPresent() throws Throwable
+   public void testBeanRequiredQualifiersNotIgnoredByDefaultForConstructor() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
+      testBeanRequiredQualifiersNotIgnoredByDefault(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
    }
 
-   public void testWantedBeanQualifiersIgnoredWhenMethodQualifiersPresent() throws Throwable
+   public void testBeanRequiredQualifiersNotIgnoredByDefaultForMethod() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent(TargetMethodBean.class, TargetType.METHOD);
+      testBeanRequiredQualifiersNotIgnoredByDefault(TargetMethodBean.class, TargetType.METHOD);
    }
 
-   private <T extends Target> void testBeanQualifiersIgnoredWhenQualifiersPresent(Class<T> targetClass, TargetType type) throws Throwable
+   private <T extends Target> void testBeanRequiredQualifiersNotIgnoredByDefault(Class<T> targetClass, TargetType type) throws Throwable
    {
       BeanMetaDataBuilder bean1Builder = BeanMetaDataBuilder.createBuilder("bean1", Bean.class.getName());
-      bean1Builder.addSuppliedQualifiers("test");
+      bean1Builder.addSuppliedQualifiers("test", "notignored");
       KernelControllerContext bean1Context = deploy(bean1Builder.getBeanMetaData());
 
       BeanMetaDataBuilder bean2Builder = BeanMetaDataBuilder.createBuilder("bean2", Bean.class.getName());
-      bean2Builder.addSuppliedQualifiers("other");
+      bean2Builder.addSuppliedQualifiers("test");
       KernelControllerContext bean2Context = deploy(bean2Builder.getBeanMetaData());
 
-      KernelControllerContext targetContext = deploy(addWantedQualifiers(createTargetMetaData(type, "test"), "ignored"));
+      KernelControllerContext targetContext = deploy(addRequiredQualifiers(createTargetMetaData(type, "test"), "notignored"));
       try
       {
          Bean bean1 = assertBean("bean1", Bean.class);
@@ -301,24 +301,66 @@
       }
    }
 
-   public void testWantedBeanQualifiersIgnoredWhenPropertyQualifiersPresent2() throws Throwable
+   public void testBeanOptionalQualifiersNotIgnoredByDefaultForProperty() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent2(TargetPropertyBean.class, TargetType.PROPERTY);
+      testBeanOptionalQualifiersNotIgnoredByDefault(TargetPropertyBean.class, TargetType.PROPERTY);
    }
 
-   public void testWantedQualifiersIgnoredWhenConstructorQualifiersPresent2() throws Throwable
+   public void testBeanOptionalQualifiersNotIgnoredByDefaultForConstructor() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent2(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
+      testBeanOptionalQualifiersNotIgnoredByDefault(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
    }
 
-   public void testWantedBeanQualifiersIgnoredWhenMethodQualifiersPresent2() throws Throwable
+   public void testBeanOptionalQualifiersNotIgnoredByDefaultForMethod() throws Throwable
    {
-      testBeanQualifiersIgnoredWhenQualifiersPresent2(TargetMethodBean.class, TargetType.METHOD);
+      testBeanOptionalQualifiersNotIgnoredByDefault(TargetMethodBean.class, TargetType.METHOD);
    }
 
-   private <T extends Target> void testBeanQualifiersIgnoredWhenQualifiersPresent2(Class<T> targetClass, TargetType type) throws Throwable
+   private <T extends Target> void testBeanOptionalQualifiersNotIgnoredByDefault(Class<T> targetClass, TargetType type) throws Throwable
    {
       BeanMetaDataBuilder bean1Builder = BeanMetaDataBuilder.createBuilder("bean1", Bean.class.getName());
+      bean1Builder.addSuppliedQualifiers("test", "notignored");
+      KernelControllerContext bean1Context = deploy(bean1Builder.getBeanMetaData());
+
+      BeanMetaDataBuilder bean2Builder = BeanMetaDataBuilder.createBuilder("bean2", Bean.class.getName());
+      bean2Builder.addSuppliedQualifiers("test");
+      KernelControllerContext bean2Context = deploy(bean2Builder.getBeanMetaData());
+
+      KernelControllerContext targetContext = deploy(addOptionalQualifiers(createTargetMetaData(type, "test"), "notignored"));
+      try
+      {
+         Bean bean1 = assertBean("bean1", Bean.class);
+         assertBean("bean2", Bean.class);
+         T target = assertBean("target", targetClass);
+         assertNotNull(target.getBean());
+         assertSame(bean1, target.getBean());
+      }
+      finally
+      {
+         undeploy(bean1Context);
+         undeploy(bean2Context);
+         undeploy(targetContext);
+      }
+   }
+
+   public void testBeanRequiredQualifiersIgnoredForProperty() throws Throwable
+   {
+      testBeanRequiredQualifiersIgnored(TargetPropertyBean.class, TargetType.PROPERTY);
+   }
+
+   public void testBeanRequiredQualifiersIgnoredForConstructor() throws Throwable
+   {
+      testBeanRequiredQualifiersIgnored(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
+   }
+
+   public void testBeanRequiredQualifiersIgnoredForMethod() throws Throwable
+   {
+      testBeanRequiredQualifiersIgnored(TargetMethodBean.class, TargetType.METHOD);
+   }
+
+   private <T extends Target> void testBeanRequiredQualifiersIgnored(Class<T> targetClass, TargetType type) throws Throwable
+   {
+      BeanMetaDataBuilder bean1Builder = BeanMetaDataBuilder.createBuilder("bean1", Bean.class.getName());
       bean1Builder.addSuppliedQualifiers("test");
       KernelControllerContext bean1Context = deploy(bean1Builder.getBeanMetaData());
 
@@ -326,12 +368,14 @@
       bean2Builder.addSuppliedQualifiers("other");
       KernelControllerContext bean2Context = deploy(bean2Builder.getBeanMetaData());
 
-      KernelControllerContext targetContext = deploy(addWantedQualifiers(createTargetMetaData(type, "injectionpoint"), "test"));
+      KernelControllerContext targetContext = deploy(addRequiredQualifiers(createTargetMetaData(type, true, "test"), "ignored"));
       try
       {
-         assertBean("bean1", Bean.class);
+         Bean bean1 = assertBean("bean1", Bean.class);
          assertBean("bean2", Bean.class);
-         assertNoBean("target");
+         T target = assertBean("target", targetClass);
+         assertNotNull(target.getBean());
+         assertSame(bean1, target.getBean());
       }
       finally
       {
@@ -341,32 +385,88 @@
       }
    }
 
-   private BeanMetaData addWantedQualifiers(BeanMetaData bmd, Object...qualifiers)
+   public void testBeanOptionalQualifiersIgnoredForProperty() throws Throwable
    {
+      testBeanOptionalQualifiersIgnored(TargetPropertyBean.class, TargetType.PROPERTY);
+   }
+
+   public void testBeanOptionalQualifiersIgnoredForConstructor() throws Throwable
+   {
+      testBeanOptionalQualifiersIgnored(TargetConstructorBean.class, TargetType.CONSTRUCTOR);
+   }
+
+   public void testBeanOptionalQualifiersIgnoredForMethod() throws Throwable
+   {
+      testBeanOptionalQualifiersIgnored(TargetMethodBean.class, TargetType.METHOD);
+   }
+
+   private <T extends Target> void testBeanOptionalQualifiersIgnored(Class<T> targetClass, TargetType type) throws Throwable
+   {
+      BeanMetaDataBuilder bean1Builder = BeanMetaDataBuilder.createBuilder("bean1", Bean.class.getName());
+      bean1Builder.addSuppliedQualifiers("test", "ignored");
+      KernelControllerContext bean1Context = deploy(bean1Builder.getBeanMetaData());
+
+      BeanMetaDataBuilder bean2Builder = BeanMetaDataBuilder.createBuilder("bean2", Bean.class.getName());
+      bean2Builder.addSuppliedQualifiers("test");
+      KernelControllerContext bean2Context = deploy(bean2Builder.getBeanMetaData());
+
+      KernelControllerContext targetContext = deploy(addOptionalQualifiers(createTargetMetaData(type, true, "test"), "ignored"));
+      try
+      {
+         assertBean("bean1", Bean.class);
+         Bean bean2 = assertBean("bean2", Bean.class);
+         T target = assertBean("target", targetClass);
+         assertNotNull(target.getBean());
+         assertSame(bean2, target.getBean());
+      }
+      finally
+      {
+         undeploy(bean1Context);
+         undeploy(bean2Context);
+         undeploy(targetContext);
+      }
+   }
+
+   private BeanMetaData addRequiredQualifiers(BeanMetaData bmd, Object...qualifiers)
+   {
       BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(bmd);
-      builder.addRequiredQualifiers(builder, qualifiers);
+      builder.addRequiredQualifiers(qualifiers);
       return builder.getBeanMetaData();
    }
 
+   private BeanMetaData addOptionalQualifiers(BeanMetaData bmd, Object...qualifiers)
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(bmd);
+      builder.addOptionalQualifiers(qualifiers);
+      return builder.getBeanMetaData();
+   }
+
    private BeanMetaData createTargetMetaData(TargetType type, Object...qualifiers)
    {
+      return createTargetMetaData(type, false, qualifiers);
+   }
+   
+
+   private BeanMetaData createTargetMetaData(TargetType type, boolean ignoreBeanQualifiers, Object...qualifiers)
+   {
+
       BeanMetaDataBuilder targetBuilder = null;
       if (type == TargetType.PROPERTY)
       {
          targetBuilder = BeanMetaDataBuilder.createBuilder("target", TargetPropertyBean.class.getName());
-         targetBuilder.addPropertyMetaData("bean", targetBuilder.createContextualInject(qualifiers));
+         targetBuilder.addPropertyMetaData("bean", targetBuilder.createContextualInject(ignoreBeanQualifiers, qualifiers));
       }
       else if (type == TargetType.CONSTRUCTOR)
       {
          targetBuilder = BeanMetaDataBuilder.createBuilder("target", TargetConstructorBean.class.getName());
-         targetBuilder.addConstructorParameter(Bean.class.getName(), targetBuilder.createContextualInject(qualifiers));
+         targetBuilder.addConstructorParameter(Bean.class.getName(), targetBuilder.createContextualInject(ignoreBeanQualifiers, qualifiers));
       }
       else
       {
          targetBuilder = BeanMetaDataBuilder.createBuilder("target", TargetMethodBean.class.getName());
-         targetBuilder.addInstall("installBean", Bean.class.getName(), targetBuilder.createContextualInject(qualifiers));
+         targetBuilder.addInstall("installBean", Bean.class.getName(), targetBuilder.createContextualInject(ignoreBeanQualifiers, qualifiers));
       }
-
+      
       return targetBuilder.getBeanMetaData();
    }
    

Modified: projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase.java
===================================================================
--- projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase.java	2009-11-26 17:06:39 UTC (rev 97042)
+++ projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase.java	2009-11-26 18:20:49 UTC (rev 97043)
@@ -145,4 +145,20 @@
       TargetMethodBean target = assertBean("target", TargetMethodBean.class);
       assertEquals(bean, target.getBean());
    }
+   
+   public void testBeanQualifiersNotIgnoredByDefault()
+   {
+      Bean bean = assertBean("bean1", Bean.class);
+      assertBean("bean2", Bean.class);
+      TargetPropertyBean target = assertBean("target", TargetPropertyBean.class);
+      assertEquals(bean, target.getBean());
+   }
+   
+   public void testBeanQualifiersIgnored()
+   {
+      assertBean("bean1", Bean.class);
+      Bean bean = assertBean("bean2", Bean.class);
+      TargetPropertyBean target = assertBean("target", TargetPropertyBean.class);
+      assertEquals(bean, target.getBean());
+   }
 }

Added: projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersIgnored.xml
===================================================================
--- projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersIgnored.xml	                        (rev 0)
+++ projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersIgnored.xml	2009-11-26 18:20:49 UTC (rev 97043)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   
+   <bean name="bean1" class="org.jboss.test.kernel.qualifiers.support.Bean">
+      <qualifier>test</qualifier>
+      <qualifier>ignored</qualifier>
+   </bean>
+
+   <bean name="bean2" class="org.jboss.test.kernel.qualifiers.support.Bean">
+      <qualifier>test</qualifier>
+   </bean>
+   
+   <bean name="target" class="org.jboss.test.kernel.qualifiers.support.TargetPropertyBean">
+      <qualifier type="Required">ignored</qualifier>
+      <property name="bean">
+         <inject ignoreBeanQualifiers="true">
+            <qualifier>test</qualifier>
+         </inject>
+      </property>
+   </bean>
+   
+</deployment>

Added: projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersNotIgnoredByDefault.xml
===================================================================
--- projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersNotIgnoredByDefault.xml	                        (rev 0)
+++ projects/kernel/trunk/kernel/src/test/resources/org/jboss/test/kernel/qualifiers/test/QualifiersXmlTestCase#testBeanQualifiersNotIgnoredByDefault.xml	2009-11-26 18:20:49 UTC (rev 97043)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   
+   <bean name="bean1" class="org.jboss.test.kernel.qualifiers.support.Bean">
+      <qualifier>test</qualifier>
+      <qualifier>notignored</qualifier>
+   </bean>
+
+   <bean name="bean2" class="org.jboss.test.kernel.qualifiers.support.Bean">
+      <qualifier>test</qualifier>
+   </bean>
+   
+   <bean name="target" class="org.jboss.test.kernel.qualifiers.support.TargetPropertyBean">
+      <qualifier type="Required">notignored</qualifier>
+      <property name="bean">
+         <inject>
+            <qualifier>test</qualifier>
+         </inject>
+      </property>
+   </bean>
+   
+</deployment>




More information about the jboss-cvs-commits mailing list