[seam-commits] Seam SVN: r12491 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/annotations and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Apr 14 06:27:47 EDT 2010
Author: swd847
Date: 2010-04-14 06:27:46 -0400 (Wed, 14 Apr 2010)
New Revision: 12491
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/internal/
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/internal/ApplyQualifiers.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/generic/generic-beans.xml
Log:
added xml configured generic beans
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/internal/ApplyQualifiers.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/internal/ApplyQualifiers.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/annotations/internal/ApplyQualifiers.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -0,0 +1,14 @@
+package org.jboss.seam.xml.annotations.internal;
+
+/**
+ * marker annotation that is only applied through XML
+ *
+ * It is replaced with qualifiers read from a generic bean type
+ *
+ * @author stuart
+ *
+ */
+public @interface ApplyQualifiers
+{
+
+}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -6,8 +6,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -19,9 +17,11 @@
import java.util.Map.Entry;
import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
@@ -29,8 +29,8 @@
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Inject;
+import org.jboss.seam.xml.annotations.internal.ApplyQualifiers;
import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.core.GenericBeanResult;
import org.jboss.seam.xml.core.XmlConfiguredBean;
@@ -43,7 +43,6 @@
import org.jboss.seam.xml.parser.SaxNode;
import org.jboss.seam.xml.util.FileDataReader;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.ReflectionUtils;
import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -276,6 +275,13 @@
return ret;
}
+ /**
+ * installs a set of secondary beans for a given generic bean, the secondary
+ * beans have the same qualifiers added to them as the generic bean, in
+ * addition the generic beans qualifiers are added whereever the
+ * ApplyQualiers annotation is found
+ *
+ */
public List<AnnotatedType<?>> processGenericBeans(BeanResult<?> bean, GenericBeanResult genericBeans, BeanManager beanManager)
{
List<AnnotatedType<?>> ret = new ArrayList<AnnotatedType<?>>();
@@ -283,10 +289,6 @@
// ret.add(rootType);
Set<Annotation> qualifiers = new HashSet<Annotation>();
- Set<Class> allBeans = new HashSet<Class>();
- allBeans.add(genericBeans.getGenericBean());
- allBeans.addAll(genericBeans.getSecondaryBeans());
-
for (Annotation i : rootType.getAnnotations())
{
if (beanManager.isQualifier(i.annotationType()))
@@ -294,110 +296,70 @@
qualifiers.add(i);
}
}
-
- for (Class<?> c : genericBeans.getSecondaryBeans())
+ for (BeanResult<?> c : genericBeans.getSecondaryBeans())
{
- NewAnnotatedTypeBuilder<?> gb = new NewAnnotatedTypeBuilder(c, true);
- for (Annotation a : qualifiers)
+
+ AnnotatedType<?> type = c.getBuilder().create();
+ NewAnnotatedTypeBuilder<?> gb = new NewAnnotatedTypeBuilder(type);
+ // we always apply qualifiers to the actual type
+ for (Annotation q : qualifiers)
{
- gb.addToClass(a);
+ gb.addToClass(q);
}
- for (Field f : ReflectionUtils.getFields(c))
+ for (AnnotatedField<?> f : type.getFields())
{
-
- if (allBeans.contains(f.getType()))
+ if (f.isAnnotationPresent(ApplyQualifiers.class))
{
- if (f.isAnnotationPresent(Produces.class) || f.isAnnotationPresent(Inject.class))
+ for (Annotation q : qualifiers)
{
- for (Annotation a : qualifiers)
- {
- gb.addToField(f, a);
- }
+ gb.addToField(f.getJavaMember(), q);
}
}
}
- // now deal with the methods
- for (Method m : ReflectionUtils.getMethods(c))
+ for (AnnotatedMethod<?> m : type.getMethods())
{
- // if this method is eligable for injection we need to check the
- // parameters
- boolean inject = false;
- if (m.isAnnotationPresent(Produces.class))
+ if (m.isAnnotationPresent(ApplyQualifiers.class))
{
- inject = true;
- // if it is a producer add qualifiers
- if (allBeans.contains(m.getReturnType()))
+ for (Annotation q : qualifiers)
{
- for (Annotation a : qualifiers)
- {
- gb.addToMethod(m, a);
- }
+ gb.addToMethod(m.getJavaMember(), q);
}
}
- // even if it is not a producer it may be a disposer or an observer
- if (!inject)
+
+ for (AnnotatedParameter<?> p : m.getParameters())
{
- for (int i = 0; i < m.getParameterTypes().length; ++i)
+ if (p.isAnnotationPresent(ApplyQualifiers.class))
{
- Annotation[] an = m.getParameterAnnotations()[i];
- for (Annotation a : an)
+ for (Annotation q : qualifiers)
{
- if (a.annotationType() == Disposes.class || a.annotationType() == Observes.class)
- {
- inject = true;
- break;
- }
+ gb.addToMethodParameter(m.getJavaMember(), p.getPosition(), q);
}
- if (inject)
- {
- break;
- }
}
}
- // if we need to apply qualifiers to the parameters
- if (inject)
+ }
+
+ for (AnnotatedConstructor<?> con : type.getConstructors())
+ {
+ if (con.isAnnotationPresent(ApplyQualifiers.class))
{
- for (int i = 0; i < m.getParameterTypes().length; ++i)
+ for (Annotation q : qualifiers)
{
- Class<?> type = m.getParameterTypes()[i];
- if (allBeans.contains(type))
- {
- for (Annotation a : qualifiers)
- {
- gb.addToMethodParameter(m, i, a);
- }
- }
+ gb.addToConstructor((Constructor) con.getJavaMember(), q);
}
}
- }
- // now deal with constructors
- for (Constructor<?> con : c.getDeclaredConstructors())
- {
- // if this constructor is eligible for injection we need to check
- // the
- // parameters
- boolean inject = false;
- if (con.isAnnotationPresent(Inject.class))
- {
- inject = true;
- }
- // if we need to apply qualifiers to the parameters
- if (inject)
+ for (AnnotatedParameter<?> p : con.getParameters())
{
- for (int i = 0; i < con.getParameterTypes().length; ++i)
+ if (p.isAnnotationPresent(ApplyQualifiers.class))
{
- Class<?> type = con.getParameterTypes()[i];
- if (allBeans.contains(type))
+ for (Annotation q : qualifiers)
{
- for (Annotation a : qualifiers)
- {
- gb.addToConstructorParameter((Constructor) con, i, a);
- }
+ gb.addToConstructorParameter((Constructor) con.getJavaMember(), p.getPosition(), q);
}
}
}
}
+
ret.add(gb.create());
}
return ret;
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -10,7 +10,7 @@
{
NewAnnotatedTypeBuilder<X> builder;
Class<X> type;
- boolean override, extend;
+ BeanResultType beanType = BeanResultType.ADD;
public BeanResult(Class<X> type, boolean readAnnotations)
{
@@ -28,23 +28,14 @@
return type;
}
- public boolean isOverride()
+ public BeanResultType getBeanType()
{
- return override;
+ return beanType;
}
- public void setOverride(boolean override)
+ public void setBeanType(BeanResultType beanType)
{
- this.override = override;
+ this.beanType = beanType;
}
- public boolean isExtend()
- {
- return extend;
- }
-
- public void setExtend(boolean extend)
- {
- this.extend = extend;
- }
}
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.core;
+
+public enum BeanResultType
+{
+ ADD, OVERRIDE, SPECIALISE;
+}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/GenericBeanResult.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -7,12 +7,12 @@
{
final Class genericBean;
- final Set<Class> secondaryBeans;
+ final Set<BeanResult<?>> secondaryBeans;
- public GenericBeanResult(Class<?> genericBean, Set<Class> secondaryBeans)
+ public GenericBeanResult(Class<?> genericBean, Set<BeanResult<?>> secondaryBeans)
{
this.genericBean = genericBean;
- this.secondaryBeans = new HashSet<Class>(secondaryBeans);
+ this.secondaryBeans = new HashSet<BeanResult<?>>(secondaryBeans);
}
public Class getGenericBean()
@@ -20,7 +20,7 @@
return genericBean;
}
- public Set<Class> getSecondaryBeans()
+ public Set<BeanResult<?>> getSecondaryBeans()
{
return secondaryBeans;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -22,6 +22,7 @@
import javax.interceptor.InterceptorBinding;
import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.BeanResultType;
import org.jboss.seam.xml.core.GenericBeanResult;
import org.jboss.seam.xml.core.XmlResult;
import org.jboss.seam.xml.fieldset.FieldValueObject;
@@ -115,7 +116,7 @@
{
ret.addBean(tp);
}
- if (tp.isOverride() || tp.isExtend())
+ if (tp.getBeanType() != BeanResultType.ADD)
{
ret.addVeto(tp.getType());
}
@@ -171,10 +172,15 @@
else if (rb.getType() == XmlItemType.GENERIC_BEAN)
{
GenericBeanXmlItem item = (GenericBeanXmlItem) rb;
- Set<Class> classes = new HashSet<Class>();
+ Set<BeanResult<?>> classes = new HashSet<BeanResult<?>>();
for (ClassXmlItem c : rb.getChildrenOfType(ClassXmlItem.class))
{
- classes.add(c.getJavaClass());
+ BeanResult<?> br = buildAnnotatedType(c);
+ if (br.getBeanType() != BeanResultType.ADD)
+ {
+ ret.addVeto(br.getType());
+ }
+ classes.add(br);
}
ret.addGenericBean(new GenericBeanResult(item.getJavaClass(), classes));
}
@@ -284,8 +290,14 @@
{
throw new XmlConfigurationException("A bean may not both <override> and <extend> an existing bean", rb.getDocument(), rb.getLineno());
}
- result.setOverride(override);
- result.setExtend(extend);
+ if (override)
+ {
+ result.setBeanType(BeanResultType.OVERRIDE);
+ }
+ else if (extend)
+ {
+ result.setBeanType(BeanResultType.SPECIALISE);
+ }
for (AnnotationXmlItem item : rb.getChildrenOfType(AnnotationXmlItem.class))
{
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-04-14 10:27:46 UTC (rev 12491)
@@ -23,7 +23,7 @@
{
CompositeNamespaceElementResolver delegate;
- static final String[] namspaces = { "java.lang", "java.util", "javax.annotation", "javax.inject", "javax.enterprise.inject", "javax.enterprise.context", "javax.enterprise.event", "javax.decorator", "javax.interceptor" };
+ static final String[] namspaces = { "java.lang", "java.util", "javax.annotation", "javax.inject", "javax.enterprise.inject", "javax.enterprise.context", "javax.enterprise.event", "javax.decorator", "javax.interceptor", "org.jboss.seam.xml.annotations.internal" };
public RootNamespaceElementResolver()
{
Modified: modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/generic/generic-beans.xml
===================================================================
--- modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/generic/generic-beans.xml 2010-04-14 10:14:00 UTC (rev 12490)
+++ modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/generic/generic-beans.xml 2010-04-14 10:27:46 UTC (rev 12491)
@@ -3,7 +3,13 @@
xmlns:test="urn:java:org.jboss.seam.xml.test.generic">
<genericBean class="org.jboss.seam.xml.test.generic.GenericMain" >
- <test:GenericDependant/>
+ <test:GenericDependant>
+ <ApplyQualifiers/>
+ <specializes/>
+ <test:instance>
+ <ApplyQualifiers/>
+ </test:instance>
+ </test:GenericDependant>
</genericBean>
<test:GenericMain>
More information about the seam-commits
mailing list