[jboss-cvs] JBossAS SVN: r99064 - in projects/kernel/trunk/kernel/src/main/java/org/jboss: kernel/plugins/dependency and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 6 07:07:04 EST 2010
Author: alesj
Date: 2010-01-06 07:07:03 -0500 (Wed, 06 Jan 2010)
New Revision: 99064
Added:
projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/QualifierMatcher.java
Removed:
projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierMatcher.java
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/ContextualInjectionDependencyItem.java
projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/AbstractKernelController.java
projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java
Log:
Make QualifierMatcher return plain ControllerContext.
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 2010-01-06 11:23:22 UTC (rev 99063)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -46,7 +46,7 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.kernel.plugins.dependency.ClassAndQualifierKey;
-import org.jboss.kernel.plugins.dependency.ClassAndQualifierMatcher;
+import org.jboss.kernel.plugins.dependency.QualifierMatcher;
import org.jboss.kernel.plugins.dependency.QualifiersMdrUtil;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.util.JBossStringBuilder;
@@ -423,8 +423,8 @@
return new ContextualInjectionDependencyItem(this, context.getName(), injectionClass, whenRequired, dependentState, search);
else
{
- ClassAndQualifierMatcher classAndQualifierMatcher = createClassAndQualifierMatcher(injectionClass, allQualifiers);
- return new ContextualInjectionDependencyItem(this, context.getName(), classAndQualifierMatcher, whenRequired, dependentState, search);
+ QualifierMatcher qualifierMatcher = createClassAndQualifierMatcher(injectionClass, allQualifiers);
+ return new ContextualInjectionDependencyItem(this, context.getName(), qualifierMatcher, whenRequired, dependentState, search);
}
}
@@ -489,7 +489,7 @@
* @param injectionClass the class
* @return the created key
*/
- ClassAndQualifierMatcher createClassAndQualifierMatcher(Class<?> injectionClass, Set<Object> allQualifiers) throws Exception
+ QualifierMatcher createClassAndQualifierMatcher(Class<?> injectionClass, Set<Object> allQualifiers) throws Exception
{
QualifierPoint point = determineQualifierPoint();
if (point == null)
Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/ContextualInjectionDependencyItem.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/ContextualInjectionDependencyItem.java 2010-01-06 11:23:22 UTC (rev 99063)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/beans/metadata/plugins/ContextualInjectionDependencyItem.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -32,7 +32,7 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.graph.LookupStrategy;
import org.jboss.dependency.spi.graph.SearchInfo;
-import org.jboss.kernel.plugins.dependency.ClassAndQualifierMatcher;
+import org.jboss.kernel.plugins.dependency.QualifierMatcher;
/**
* A dependency item for looking up by class, or by class and qualifiers
@@ -56,7 +56,7 @@
this.injectionValueMetaData = injectionValueMetaData;
}
- public ContextualInjectionDependencyItem(AbstractInjectionValueMetaData injectionValueMetaData, Object name, ClassAndQualifierMatcher key, ControllerState whenRequired, ControllerState dependentState, SearchInfo search)
+ public ContextualInjectionDependencyItem(AbstractInjectionValueMetaData injectionValueMetaData, Object name, QualifierMatcher key, ControllerState whenRequired, ControllerState dependentState, SearchInfo search)
{
super(name, key, whenRequired, dependentState);
this.type = LookupType.KEY;
@@ -70,7 +70,7 @@
{
super.setIDependOn(injectionValueMetaData.createClassAndQualifierMatcher((Class<?>)getIDependOn(), null));
}
- ((ClassAndQualifierMatcher)getIDependOn()).addQualifiersFromAnnotations(qualifiers);
+ ((QualifierMatcher)getIDependOn()).addQualifiersFromAnnotations(qualifiers);
}
/**
Modified: projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/AbstractKernelController.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/AbstractKernelController.java 2010-01-06 11:23:22 UTC (rev 99063)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/AbstractKernelController.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -107,9 +107,7 @@
public KernelRegistryEntry getEntry(Object name)
{
List<KernelControllerContext> list;
- if (name instanceof ClassAndQualifierMatcher)
- return ((ClassAndQualifierMatcher)name).search(this);
- else if (name instanceof Matcher)
+ if (name instanceof Matcher)
list = matchSupplies((Matcher)name);
else
list = suppliers.get(name);
@@ -152,6 +150,14 @@
ControllerContext context = super.getContext(name, state);
if (context != null)
return context;
+
+ // simple qualifier matcher
+ if (name instanceof QualifierMatcher)
+ {
+ QualifierMatcher qm = (QualifierMatcher)name;
+ return qm.search(this);
+ }
+
if (state == null || ControllerState.INSTALLED.equals(state) || getStates().isAfterState(state, ControllerState.INSTALLED))
{
org.jboss.kernel.spi.registry.KernelRegistry registry = kernel.getRegistry();
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 2010-01-06 11:23:22 UTC (rev 99063)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierKey.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+*/
package org.jboss.kernel.plugins.dependency;
import java.lang.annotation.Annotation;
@@ -39,45 +39,59 @@
import org.jboss.util.JBossStringBuilder;
/**
- * If an injection point uses contextual injection and also has qualifiers attached,
+ * If an injection point uses contextual injection and also has qualifiers attached,
* this will be used when trying to find a matching context in the controller
- *
+ *
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public class ClassAndQualifierKey extends JBossObject implements ClassAndQualifierMatcher
+public class ClassAndQualifierKey extends JBossObject implements QualifierMatcher
{
- /** The type of class we are looking for */
+ /**
+ * The type of class we are looking for
+ */
protected final Class<?> type;
-
- /** The state of the dependency */
+
+ /**
+ * The state of the dependency
+ */
protected final ControllerState dependentState;
-
- /** The context containing the wanted qualifiers */
+
+ /**
+ * The context containing the wanted qualifiers
+ */
protected final KernelControllerContext context;
-
- /** The qualifiers defined on the injection point */
+
+ /**
+ * The qualifiers defined on the injection point
+ */
protected final Set<Object> injectionPointQualifiers;
-
- /** If injection point qualifiers are specified, set this to true to ignore any qualifiers from bean level */
- protected final boolean ignoreBeanQualifiers;
-
- /** The injection point type that this lookup will be done for */
+
+ /**
+ * If injection point qualifiers are specified, set this to true to ignore any qualifiers from bean level
+ */
+ protected final boolean ignoreBeanQualifiers;
+
+ /**
+ * The injection point type that this lookup will be done for
+ */
protected final QualifierPoint injectionPointType;
-
- /** The parent nodes, with the lowest node first */
+
+ /**
+ * The parent nodes, with the lowest node first
+ */
protected final List<MetaDataVisitorNode> parentNodes;
-
+
/**
* Constructor
- *
- * @param dependentState the state the dependency must be in
- * @param context the controller context owning this dependency
- * @param ignoreBeanQualifiers if injection point qualifiers are specified, set this to true to ignore any qualifiers from bean level
- * @param parentNodes the nodes containing the injection. Lowest level come first in the list
+ *
+ * @param dependentState the state the dependency must be in
+ * @param context the controller context owning this dependency
+ * @param ignoreBeanQualifiers if injection point qualifiers are specified, set this to true to ignore any qualifiers from bean level
+ * @param injectionPointType injection point type
+ * @param parentNodes the nodes containing the injection. Lowest level come first in the list
* @param injectionPointQualifiers the qualifiers applying only to this injection point
- * @param type the type of class we are looking for
- *
+ * @param type the type of class we are looking for
*/
public ClassAndQualifierKey(ControllerState dependentState, KernelControllerContext context, boolean ignoreBeanQualifiers, QualifierPoint injectionPointType, List<MetaDataVisitorNode> parentNodes, Set<Object> injectionPointQualifiers, Class<?> type)
{
@@ -92,6 +106,7 @@
/**
* Get the parentNodes
+ *
* @return the parentNodes
*/
public List<MetaDataVisitorNode> getParentNodes()
@@ -101,28 +116,28 @@
/**
* Add qualifiers coming from injection point annotations
- *
+ *
* @param annotations the qualifier annotations
*/
public void addQualifiersFromAnnotations(Set<Annotation> annotations)
{
injectionPointQualifiers.addAll(annotations);
}
-
+
/**
* Look for a context in the controller that most closely matches the type
* and qualifiers contained in this key
- *
+ *
* @param controller the controller
*/
- public KernelControllerContext search(KernelController controller)
+ public ControllerContext search(KernelController controller)
{
Set<ControllerContext> contexts = controller.getContexts(type, dependentState);
-
+
if (contexts == null || contexts.size() == 0)
return null;
-
- Set<Object> requiredQualifiers = null;
+
+ Set<Object> requiredQualifiers;
if (injectionPointQualifiers != null)
{
if (ignoreBeanQualifiers)
@@ -139,54 +154,51 @@
{
requiredQualifiers = QualifiersMdrUtil.mergeRequiredQualifiersFromMdr(context, injectionPointType);
}
-
+
Set<Object> optionalQualifiers = ignoreBeanQualifiers ? null : QualifiersMdrUtil.mergeOptionalQualifiersFromMdr(context, injectionPointType);
if ((requiredQualifiers == null || requiredQualifiers.size() == 0) && (optionalQualifiers == null || optionalQualifiers.size() == 0))
return getFirstContext(contexts);
-
+
List<ControllerContext> found = getContextWithAllRequiredAndMostOptionalQualifiers(requiredQualifiers, optionalQualifiers, contexts);
-
+
return getFirstContext(found);
}
-
- private KernelControllerContext getFirstContext(Collection<? extends ControllerContext> contexts)
+
+ private ControllerContext getFirstContext(Collection<? extends ControllerContext> contexts)
{
if (contexts.size() == 0)
return null;
-
+
KernelControllerContext found = null;
if (contexts.size() > 0)
{
for (ControllerContext context : contexts)
{
- if (context instanceof KernelControllerContext)
+ if (found != null)
{
- if (found != null)
+ log.warn("Multiple beans match qualifiers and class [enable trace log for details]: " + type);
+ if (log.isTraceEnabled())
{
- log.warn("Multiple beans match qualifiers and class [enable trace log for details]: " + type);
- if (log.isTraceEnabled())
- {
- log.trace(this + ". Matching contexts: " + contexts);
- }
- return null;
+ log.trace(this + ". Matching contexts: " + contexts);
}
- found = (KernelControllerContext)context;
+ return null;
}
+ found = (KernelControllerContext)context;
}
}
-
+
return found;
}
-
+
private List<ControllerContext> getContextWithAllRequiredAndMostOptionalQualifiers(Set<Object> requiredQualifiers, Set<Object> optionalQualifiers, Collection<ControllerContext> contexts)
{
int max = 0;
List<ControllerContext> found = new ArrayList<ControllerContext>();
-
+
for (ControllerContext context : contexts)
{
Set<Object> suppliedQualifiers = QualifiersMdrUtil.mergeSuppliedQualifiersFromMdr(context);
-
+
int matches = 0;
boolean allRequired = true;
Deleted: projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierMatcher.java
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierMatcher.java 2010-01-06 11:23:22 UTC (rev 99063)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierMatcher.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -1,40 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.kernel.plugins.dependency;
-
-import java.lang.annotation.Annotation;
-import java.util.Set;
-
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-
-/**
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public interface ClassAndQualifierMatcher
-{
- KernelControllerContext search(KernelController controller);
-
- void addQualifiersFromAnnotations(Set<Annotation> annotations);
-}
Copied: projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/QualifierMatcher.java (from rev 99060, projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/ClassAndQualifierMatcher.java)
===================================================================
--- projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/QualifierMatcher.java (rev 0)
+++ projects/kernel/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/QualifierMatcher.java 2010-01-06 12:07:03 UTC (rev 99064)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.kernel.plugins.dependency;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+
+/**
+ * Qualifier matcher.
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface QualifierMatcher
+{
+ /**
+ * Find matching controller context, null if not found.
+ *
+ * @param controller the controller
+ * @return matching context or null
+ */
+ ControllerContext search(KernelController controller);
+
+ /**
+ * Add qualifiers from annotations.
+ *
+ * TODO -- is this really needed on this interface?
+ *
+ * @param annotations the annotations
+ */
+ void addQualifiersFromAnnotations(Set<Annotation> annotations);
+}
More information about the jboss-cvs-commits
mailing list