Weld SVN: r6796 - in extensions/trunk/impl/src: main/java/org/jboss/weld/extensions/bean/generic and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-24 09:02:56 -0400 (Sat, 24 Jul 2010)
New Revision: 6796
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
Log:
refactor on AnnotatedTypeBuilder
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-07-24 12:23:29 UTC (rev 6795)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-07-24 13:02:56 UTC (rev 6796)
@@ -32,8 +32,6 @@
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
-import org.jboss.weld.extensions.util.Reflections;
-
/**
* Class for constructing a new AnnotatedType. A new instance of builder must be
* used for each annotated type.
@@ -47,116 +45,34 @@
*/
public class AnnotatedTypeBuilder<X>
{
-
- public static <X> AnnotatedTypeBuilder<X> newInstance(Class<X> underlying)
- {
- return new AnnotatedTypeBuilder<X>(underlying);
- }
-
- public static <X> AnnotatedTypeBuilder<X> newInstance(AnnotatedType<X> underlying)
- {
- return new AnnotatedTypeBuilder<X>(underlying);
- }
-
- private final Class<X> underlyingType;
+ private Class<X> javaClass;
private final AnnotationBuilder typeAnnotations;
-
+
private final Map<Constructor<?>, AnnotationBuilder> constructors;
private final Map<Constructor<?>, Map<Integer, AnnotationBuilder>> constructorParameters;
private Map<Constructor<?>, Map<Integer, Type>> constructorParameterTypes;
-
+
private final Map<Field, AnnotationBuilder> fields;
private final Map<Field, Type> fieldTypes;
-
+
private final Map<Method, AnnotationBuilder> methods;
private final Map<Method, Map<Integer, AnnotationBuilder>> methodParameters;
private final Map<Method, Map<Integer, Type>> methodParameterTypes;
- protected AnnotatedTypeBuilder(Class<X> underlyingType)
+ public AnnotatedTypeBuilder()
{
- this.underlyingType = underlyingType;
this.typeAnnotations = new AnnotationBuilder();
this.constructors = new HashMap<Constructor<?>, AnnotationBuilder>();
- this.constructorParameters = new HashMap<Constructor<?>, Map<Integer,AnnotationBuilder>>();
- this.constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer,Type>>();
+ this.constructorParameters = new HashMap<Constructor<?>, Map<Integer, AnnotationBuilder>>();
+ this.constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer, Type>>();
this.fields = new HashMap<Field, AnnotationBuilder>();
this.fieldTypes = new HashMap<Field, Type>();
this.methods = new HashMap<Method, AnnotationBuilder>();
- this.methodParameters = new HashMap<Method, Map<Integer,AnnotationBuilder>>();
- this.methodParameterTypes = new HashMap<Method, Map<Integer,Type>>();
+ this.methodParameters = new HashMap<Method, Map<Integer, AnnotationBuilder>>();
+ this.methodParameterTypes = new HashMap<Method, Map<Integer, Type>>();
}
- protected AnnotatedTypeBuilder(AnnotatedType<X> underlyingType)
- {
- this(underlyingType.getJavaClass());
-
- }
-
- public AnnotatedTypeBuilder<X> readAnnotationsFromUnderlyingType()
- {
- for (Annotation annotation : underlyingType.getAnnotations())
- {
- typeAnnotations.add(annotation);
- }
-
- for (Field field : Reflections.getAllFields(underlyingType))
- {
- AnnotationBuilder annotationBuilder = new AnnotationBuilder();
- fields.put(field, annotationBuilder);
- field.setAccessible(true);
- for (Annotation annotation : field.getAnnotations())
- {
- annotationBuilder.add(annotation);
- }
- }
-
- for (Method method : Reflections.getAllMethods(underlyingType))
- {
- AnnotationBuilder annotationBuilder = new AnnotationBuilder();
- method.setAccessible(true);
- methods.put(method, annotationBuilder);
- for (Annotation annotation : method.getAnnotations())
- {
- annotationBuilder.add(annotation);
- }
- Map<Integer, AnnotationBuilder> parameters = new HashMap<Integer, AnnotationBuilder>();
- methodParameters.put(method, parameters);
- for (int i = 0; i < method.getParameterTypes().length; ++i)
- {
- AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
- parameters.put(i, parameterAnnotationBuilder);
- for (Annotation annotation : method.getParameterAnnotations()[i])
- {
- parameterAnnotationBuilder.add(annotation);
- }
- }
- }
-
- for (Constructor<?> constructor : underlyingType.getDeclaredConstructors())
- {
- AnnotationBuilder annotationBuilder = new AnnotationBuilder();
- constructor.setAccessible(true);
- constructors.put(constructor, annotationBuilder);
- for (Annotation annotation : constructor.getAnnotations())
- {
- annotationBuilder.add(annotation);
- }
- Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
- constructorParameters.put(constructor, mparams);
- for (int i = 0; i < constructor.getParameterTypes().length; ++i)
- {
- AnnotationBuilder parameterAnnotationBuilder = new AnnotationBuilder();
- mparams.put(i, parameterAnnotationBuilder);
- for (Annotation annotation : constructor.getParameterAnnotations()[i])
- {
- parameterAnnotationBuilder.add(annotation);
- }
- }
- }
- return this;
- }
-
public AnnotatedTypeBuilder<X> addToClass(Annotation annotation)
{
typeAnnotations.add(annotation);
@@ -342,7 +258,7 @@
}
return this;
}
-
+
public <T extends Annotation> AnnotatedTypeBuilder<X> redefineMembers(Class<T> annotationType, MemberAnnotationRedefiner<T> redefinition)
{
for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
@@ -374,24 +290,41 @@
}
/**
- * merges the annotations from an existing AnnotatedType. If they both have
- * the same annotation on an element overwriteExisting determines which one
- * to keep
+ * Reads in from an existing AnnotatedType. Any elements not present are
+ * added. The javaClass will be read in. If the annotation already exists on
+ * that element in the builder the read annotation will be used.
*
- * @param type
- * @param overwriteExisting
- * @return
+ * @param type The type to read from
*/
- public AnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
+ public AnnotatedTypeBuilder<X> readFromType(AnnotatedType<X> type)
{
- mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
+ return readFromType(type, true);
+ }
+
+ /**
+ * Reads in from an existing AnnotatedType. Any elements not present are
+ * added. The javaClass will be read in if overwrite is true. If the
+ * annotation already exists on that element in the builder, overwrite
+ * determines whether the original or read annotation will be used.
+ *
+ * @param type The type to read from
+ * @param overwrite If true, the read annotation will replace any existing
+ * annotation
+ */
+ public AnnotatedTypeBuilder<X> readFromType(AnnotatedType<X> type, boolean overwrite)
+ {
+ if (javaClass == null || overwrite)
+ {
+ this.javaClass = type.getJavaClass();
+ }
+ mergeAnnotationsOnElement(type, overwrite, typeAnnotations);
for (AnnotatedField<? super X> field : type.getFields())
- {
+ {
if (fields.get(field.getJavaMember()) == null)
{
fields.put(field.getJavaMember(), new AnnotationBuilder());
}
- mergeAnnotationsOnElement(field, overwriteExisting, fields.get(field.getJavaMember()));
+ mergeAnnotationsOnElement(field, overwrite, fields.get(field.getJavaMember()));
}
for (AnnotatedMethod<? super X> method : type.getMethods())
{
@@ -399,7 +332,7 @@
{
methods.put(method.getJavaMember(), new AnnotationBuilder());
}
- mergeAnnotationsOnElement(method, overwriteExisting, methods.get(method.getJavaMember()));
+ mergeAnnotationsOnElement(method, overwrite, methods.get(method.getJavaMember()));
for (AnnotatedParameter<? super X> p : method.getParameters())
{
if (methodParameters.get(method.getJavaMember()) == null)
@@ -408,9 +341,9 @@
}
if (methodParameters.get(method.getJavaMember()).get(p.getPosition()) == null)
{
- methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
+ methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
}
- mergeAnnotationsOnElement(p, overwriteExisting, methodParameters.get(method.getJavaMember()).get(p.getPosition()));
+ mergeAnnotationsOnElement(p, overwrite, methodParameters.get(method.getJavaMember()).get(p.getPosition()));
}
}
for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
@@ -419,7 +352,7 @@
{
constructors.put(constructor.getJavaMember(), new AnnotationBuilder());
}
- mergeAnnotationsOnElement(constructor, overwriteExisting, constructors.get(constructor.getJavaMember()));
+ mergeAnnotationsOnElement(constructor, overwrite, constructors.get(constructor.getJavaMember()));
for (AnnotatedParameter<? super X> p : constructor.getParameters())
{
if (constructorParameters.get(constructor.getJavaMember()) == null)
@@ -430,7 +363,7 @@
{
constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
}
- mergeAnnotationsOnElement(p, overwriteExisting, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
+ mergeAnnotationsOnElement(p, overwrite, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
}
}
return this;
@@ -496,7 +429,7 @@
}
}
- return new AnnotatedTypeImpl<X>(underlyingType, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
+ return new AnnotatedTypeImpl<X>(javaClass, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
}
public void overrideFieldType(Field field, Type type)
@@ -522,4 +455,15 @@
constructorParameterTypes.get(constructor).put(position, type);
}
+ public Class<X> getJavaClass()
+ {
+ return javaClass;
+ }
+
+ public AnnotatedTypeBuilder<X> setJavaClass(Class<X> javaClass)
+ {
+ this.javaClass = javaClass;
+ return this;
+ }
+
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-24 12:23:29 UTC (rev 6795)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-24 13:02:56 UTC (rev 6796)
@@ -72,7 +72,7 @@
// A map of a generic annotation type to all instances of that type found on beans
private final Map<Class<?>, Set<Annotation>> concreteGenerics;
-
+
private final Synthetic.Provider syntheticProvider;
GenericBeanExtension()
@@ -126,7 +126,7 @@
}
}
}
-
+
// make note of any producer method that produce generic beans
for (AnnotatedMethod<?> method : type.getMethods())
{
@@ -172,12 +172,11 @@
ProducerInjectionTarget<T> it = new ProducerInjectionTarget<T>(event.getInjectionTarget(), beanManager, setters, producersOnClass, syntheticProvider);
event.setInjectionTarget(it);
}
-
-
+
}
/**
- * Installs the generic beans.
+ * Install the generic beans and generic configuration beans
*/
void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager)
{
@@ -197,13 +196,12 @@
}
}
- // TODO Do we need to do something this complex, can't we just register the relevant beans?
private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager, AfterBeanDiscovery event)
{
- Synthetic genericBeanSyntheticQualifier = syntheticProvider.get(concrete);
+ Synthetic genericBeanQualifier = syntheticProvider.get(concrete);
- AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(annotatedType).readAnnotationsFromUnderlyingType();
- builder.addToClass(genericBeanSyntheticQualifier);
+ AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(annotatedType);
+ builder.addToClass(genericBeanQualifier);
for (AnnotatedField<? super X> field : annotatedType.getFields())
{
if (field.isAnnotationPresent(Inject.class))
@@ -217,19 +215,19 @@
}
else
{
- // check to see if we should be injecting a generic bean
- // we do this by checking if there are any beans that can be
- // injected into this point
- // if there is not then we assume it is a generic injection
- // point
- // this has the downside that if it is actually a deployment
- // error then it will confuse the user
- // TODO IMprove this
+ /*
+ * check to see if we should be injecting a generic bean we do
+ * this by checking if there are any beans that can be injected
+ * into this point if there is not then we assume it is a generic
+ * injection point this has the downside that if it is actually a
+ * deployment error then it will confuse the user
+ */
+ // TODO Improve this
Annotation[] qualifiers = getQualifiers(field.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qualifiers);
if (beans.isEmpty())
{
- builder.addToField(field.getJavaMember(), genericBeanSyntheticQualifier);
+ builder.addToField(field.getJavaMember(), genericBeanQualifier);
}
}
}
@@ -261,7 +259,7 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToMethod(method.getJavaMember(), genericBeanSyntheticQualifier);
+ builder.addToMethod(method.getJavaMember(), genericBeanQualifier);
}
}
}
@@ -278,7 +276,7 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), genericBeanSyntheticQualifier);
+ builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), genericBeanQualifier);
}
}
}
@@ -286,29 +284,25 @@
BeanBuilder<X> beanBuilder = new BeanBuilder<X>(beanManager).defineBeanFromAnnotatedType(builder.create());
return beanBuilder.create();
}
-
+
private Bean<Annotation> createConfigurationBean(BeanManager beanManager, final Annotation genericConfiguration, Annotation syntheticQualifier)
{
- BeanBuilder<Annotation> builder = new BeanBuilder<Annotation>(beanManager)
- .setJavaClass(genericConfiguration.annotationType())
- .setTypes(Arrays2.<Type>asSet(genericConfiguration.annotationType(), Object.class))
- .setScope(Dependent.class)
- .setQualifiers(Arrays2.asSet(syntheticQualifier))
- // TODO make this passivation capable?
- .setBeanLifecycle(new BeanLifecycle<Annotation>()
- {
-
- public void destroy(Bean<Annotation> bean, Annotation arg0, CreationalContext<Annotation> arg1)
+ BeanBuilder<Annotation> builder = new BeanBuilder<Annotation>(beanManager).setJavaClass(genericConfiguration.annotationType()).setTypes(Arrays2.<Type> asSet(genericConfiguration.annotationType(), Object.class)).setScope(Dependent.class).setQualifiers(Arrays2.asSet(syntheticQualifier))
+ // TODO make this passivation capable?
+ .setBeanLifecycle(new BeanLifecycle<Annotation>()
{
- // No-op
- }
-
- public Annotation create(Bean<Annotation> bean, CreationalContext<Annotation> arg0)
- {
- return genericConfiguration;
- }
- });
-
+
+ public void destroy(Bean<Annotation> bean, Annotation arg0, CreationalContext<Annotation> arg1)
+ {
+ // No-op
+ }
+
+ public Annotation create(Bean<Annotation> bean, CreationalContext<Annotation> arg0)
+ {
+ return genericConfiguration;
+ }
+ });
+
return builder.create();
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-07-24 12:23:29 UTC (rev 6795)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-07-24 13:02:56 UTC (rev 6796)
@@ -69,7 +69,7 @@
return;
}
- AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).mergeAnnotations(pat.getAnnotatedType(), true);
+ AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(pat.getAnnotatedType());
// support for @Named packages
Package pkg = pat.getAnnotatedType().getJavaClass().getPackage();
@@ -145,7 +145,7 @@
{
if (constructor.isAnnotationPresent(Constructs.class))
{
- AnnotatedTypeBuilder<X> annotatedTypeBuilder = AnnotatedTypeBuilder.newInstance(pat.getAnnotatedType()).mergeAnnotations(pat.getAnnotatedType(), true);
+ AnnotatedTypeBuilder<X> annotatedTypeBuilder = new AnnotatedTypeBuilder<X>().readFromType(pat.getAnnotatedType());
// remove class-level @Named annotation
annotatedTypeBuilder.removeFromClass(Named.class);
// remove bean constructors annotated @Inject
Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java 2010-07-24 12:23:29 UTC (rev 6795)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java 2010-07-24 13:02:56 UTC (rev 6796)
@@ -48,9 +48,9 @@
{
// Test that the generic configuration injection wiring is working!
assert baz1.getGarply() != null;
- assert baz1.getGarply().equals("hello1");
+ assert baz1.getGarply().value().equals("hello1");
assert baz2.getGarply() != null;
- assert baz2.getGarply().equals("hello2");
+ assert baz2.getGarply().value().equals("hello2");
assert baz1.getBar() != null;
assert baz1.getBar().getInjectedGarply() != null;
assert baz1.getBar().getInjectedGarply().value().equals("hello1");
13 years, 10 months
Weld SVN: r6795 - in extensions/trunk: impl/src/main/java/org/jboss/weld/extensions/bean and 4 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-24 08:23:29 -0400 (Sat, 24 Jul 2010)
New Revision: 6795
Added:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Arrays2.java
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java
extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java
extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
extensions/trunk/pom.xml
Log:
reimpl as Bean rather than IT wrapper
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -23,15 +23,15 @@
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Named;
import org.jboss.weld.extensions.annotated.Annotateds;
+import org.jboss.weld.extensions.literal.DefaultLiteral;
/**
* class that can build a bean from an AnnotatedType.
@@ -42,38 +42,43 @@
public class BeanBuilder<T>
{
- private final AnnotatedType<T> type;
private final BeanManager beanManager;
- private InjectionTarget<T> injectionTarget;
+
+ private Class<? extends T> javaClass;
private String name;
private Set<Annotation> qualifiers;
private Class<? extends Annotation> scope;
private Set<Class<? extends Annotation>> stereotypes;
- private Set<Type> types = new HashSet<Type>();
- private boolean alternative = false;
- private boolean nullable = false;
+ private Set<Type> types;
+ private Set<InjectionPoint> injectionPoints;
+ private boolean alternative;
+ private boolean nullable;
private BeanLifecycle<T> beanLifecycle;
boolean passivationCapable;
private String id;
- public BeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
+ public BeanBuilder(BeanManager beanManager)
{
- this.type = type;
this.beanManager = beanManager;
}
- public BeanBuilder<T> defineBeanFromAnnotatedType()
+ public BeanBuilder<T> defineBeanFromAnnotatedType(AnnotatedType<T> type)
{
+ this.javaClass = type.getJavaClass();
+ InjectionTarget<T> injectionTarget;
if (!type.getJavaClass().isInterface())
{
- this.injectionTarget = beanManager.createInjectionTarget(type);
+ injectionTarget = beanManager.createInjectionTarget(type);
}
else
{
- this.injectionTarget = new DummyInjectionTarget<T>();
+ injectionTarget = new DummyInjectionTarget<T>();
}
+ this.beanLifecycle = new BeanLifecycleImpl<T>(injectionTarget);
+ this.injectionPoints = injectionTarget.getInjectionPoints();
this.qualifiers = new HashSet<Annotation>();
this.stereotypes = new HashSet<Class<? extends Annotation>>();
+ this.types = new HashSet<Type>();
for (Annotation annotation : type.getAnnotations())
{
if (beanManager.isQualifier(annotation.annotationType()))
@@ -111,11 +116,8 @@
}
if (qualifiers.isEmpty())
{
- qualifiers.add(new AnnotationLiteral<Default>()
- {
- });
+ qualifiers.add(DefaultLiteral.INSTANCE);
}
- this.beanLifecycle = new BeanLifecycleImpl<T>();
this.id = BeanImpl.class.getName() + ":" + Annotateds.createTypeId(type);
return this;
}
@@ -124,23 +126,11 @@
{
if (!passivationCapable)
{
- return new BeanImpl<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ return new BeanImpl<T>(javaClass, name, qualifiers, scope, stereotypes, types, alternative, nullable, injectionPoints, beanLifecycle);
}
- return new PassivationCapableBeanImpl<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
-
+ return new PassivationCapableBeanImpl<T>(id, javaClass, name, qualifiers, scope, stereotypes, types, alternative, nullable, injectionPoints, beanLifecycle);
}
- public InjectionTarget<T> getInjectionTarget()
- {
- return injectionTarget;
- }
-
- public BeanBuilder<T> setInjectionTarget(InjectionTarget<T> injectionTarget)
- {
- this.injectionTarget = injectionTarget;
- return this;
- }
-
public Set<Annotation> getQualifiers()
{
return qualifiers;
@@ -218,10 +208,16 @@
return this;
}
- public AnnotatedType<T> getType()
+ public Class<? extends T> getJavaClass()
{
- return type;
+ return javaClass;
}
+
+ public BeanBuilder<T> setJavaClass(Class<? extends T> javaClass)
+ {
+ this.javaClass = javaClass;
+ return this;
+ }
public BeanManager getBeanManager()
{
@@ -260,5 +256,16 @@
this.id = id;
return this;
}
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return injectionPoints;
+ }
+
+ public BeanBuilder<T> setInjectionPoints(Set<InjectionPoint> injectionPoints)
+ {
+ this.injectionPoints = injectionPoints;
+ return this;
+ }
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -22,22 +22,30 @@
import java.util.HashSet;
import java.util.Set;
+import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
+import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.jboss.weld.extensions.util.Arrays2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
- * An immutable bean.
+ * An immutable bean which provides basic defaulting and checking of arguments.
*
* @author stuart
+ * @author Pete Muir
*
- * @param <T>
*/
public class BeanImpl<T> implements Bean<T>
{
+
+ private static final Logger log = LoggerFactory.getLogger(BeanImpl.class);
+
private final Class<?> beanClass;
- private final InjectionTarget<T> injectionTarget;
private final String name;
private final Set<Annotation> qualifiers;
private final Class<? extends Annotation> scope;
@@ -46,16 +54,79 @@
private final boolean alternative;
private final boolean nullable;
private final BeanLifecycle<T> beanLifecycle;
+ private final Set<InjectionPoint> injectionPoints;
- BeanImpl(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ /**
+ * Create a new, immutable bean. All arguments passed as collections are defensively copied.
+ *
+ * @param beanClass The Bean class, may not be null
+ * @param name The bean name
+ * @param qualifiers The bean's qualifiers, if null, a singleton set of
+ * {@link Default} is used
+ * @param scope The bean's scope, if null, the default scope of
+ * {@link Dependent} is used
+ * @param stereotypes The bean's stereotypes, if null, an empty set is used
+ * @param types The bean's types, if null, the beanClass and {@link Object}
+ * will be used
+ * @param alternative True if the bean is an alternative
+ * @param nullable True if the bean is nullable
+ * @param injectionPoints the bean's injection points, if null an empty set is used
+ * @param beanLifecycle Handler for {@link #create(CreationalContext)} and
+ * {@link #destroy(Object, CreationalContext)}
+ *
+ * @throws IllegalArgumentException if the beanClass is null
+ */
+ public BeanImpl(Class<?> beanClass, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, Set<InjectionPoint> injectionPoints, BeanLifecycle<T> beanLifecycle)
{
+ if (beanClass == null)
+ {
+ throw new IllegalArgumentException("beanClass cannot be null");
+ }
this.beanClass = beanClass;
- this.injectionTarget = injectionTarget;
this.name = name;
- this.qualifiers = new HashSet<Annotation>(qualifiers);
- this.scope = scope;
- this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
- this.types = new HashSet<Type>(types);
+ if (qualifiers == null)
+ {
+ this.qualifiers = Collections.<Annotation>singleton(DefaultLiteral.INSTANCE);
+ log.trace("No qualifers provided for bean class " + beanClass + ", using singleton set of @Default");
+ }
+ else
+ {
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ }
+ if (scope == null)
+ {
+ this.scope = Dependent.class;
+ log.trace("No scope provided for bean class " + beanClass + ", using @Dependent");
+ }
+ else
+ {
+ this.scope = scope;
+ }
+ if (stereotypes == null)
+ {
+ this.stereotypes = Collections.emptySet();
+ }
+ else
+ {
+ this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
+ }
+ if (types == null)
+ {
+ this.types = Arrays2.<Type>asSet(Object.class, beanClass);
+ log.trace("No types provided for bean class " + beanClass + ", using [java.lang.Object.class, " + beanClass.getName() + ".class]");
+ }
+ else
+ {
+ this.types = new HashSet<Type>(types);
+ }
+ if (injectionPoints == null)
+ {
+ this.injectionPoints = Collections.emptySet();
+ }
+ else
+ {
+ this.injectionPoints = new HashSet<InjectionPoint>(injectionPoints);
+ }
this.alternative = alternative;
this.nullable = nullable;
this.beanLifecycle = beanLifecycle;
@@ -68,14 +139,9 @@
public Set<InjectionPoint> getInjectionPoints()
{
- return injectionTarget.getInjectionPoints();
+ return injectionPoints;
}
- public InjectionTarget<T> getInjectionTarget()
- {
- return injectionTarget;
- }
-
public String getName()
{
return name;
@@ -120,7 +186,7 @@
{
beanLifecycle.destroy(this, arg0, arg1);
}
-
+
@Override
public String toString()
{
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -17,9 +17,12 @@
package org.jboss.weld.extensions.bean;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionTarget;
/**
- * Handler for the create/destroy methods of CustomBean
+ * Handler for the create/destroy methods of {@link BeanImpl}. By default, the
+ * {@link InjectionTarget} will be used to create and destroy the bean
*
* @author stuart
*
@@ -27,8 +30,8 @@
*/
public interface BeanLifecycle<T>
{
- public T create(BeanImpl<T> bean, CreationalContext<T> arg0);
+ public T create(Bean<T> bean, CreationalContext<T> arg0);
- public void destroy(BeanImpl<T> bean, T arg0, CreationalContext<T> arg1);
+ public void destroy(Bean<T> bean, T arg0, CreationalContext<T> arg1);
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -17,25 +17,32 @@
package org.jboss.weld.extensions.bean;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionTarget;
-public class BeanLifecycleImpl<T> implements BeanLifecycle<T>
+class BeanLifecycleImpl<T> implements BeanLifecycle<T>
{
- public BeanLifecycleImpl() {}
+ private final InjectionTarget<T> injectionTarget;
- public T create(BeanImpl<T> bean, CreationalContext<T> creationalContext)
+ BeanLifecycleImpl(InjectionTarget<T> injectionTarget)
{
- T instance = bean.getInjectionTarget().produce(creationalContext);
- bean.getInjectionTarget().inject(instance, creationalContext);
- bean.getInjectionTarget().postConstruct(instance);
+ this.injectionTarget = injectionTarget;
+ }
+
+ public T create(Bean<T> bean, CreationalContext<T> creationalContext)
+ {
+ T instance = injectionTarget.produce(creationalContext);
+ injectionTarget.inject(instance, creationalContext);
+ injectionTarget.postConstruct(instance);
return instance;
}
- public void destroy(BeanImpl<T> bean, T instance, CreationalContext<T> creationalContext)
+ public void destroy(Bean<T> bean, T instance, CreationalContext<T> creationalContext)
{
try
{
- bean.getInjectionTarget().preDestroy(instance);
+ injectionTarget.preDestroy(instance);
creationalContext.release();
}
catch (Exception e)
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -20,16 +20,16 @@
import java.lang.reflect.Type;
import java.util.Set;
-import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;
public class PassivationCapableBeanImpl<T> extends BeanImpl<T> implements PassivationCapable
{
private final String id;
- PassivationCapableBeanImpl(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ PassivationCapableBeanImpl(String id, Class<?> beanClass, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, Set<InjectionPoint> injectionPoints, BeanLifecycle<T> beanLifecycle)
{
- super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ super(beanClass, name, qualifiers, scope, stereotypes, types, alternative, nullable, injectionPoints, beanLifecycle);
this.id = id;
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -21,6 +21,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -29,6 +30,8 @@
import java.util.Set;
import java.util.Map.Entry;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
@@ -41,13 +44,14 @@
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.inject.Inject;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
+import org.jboss.weld.extensions.bean.BeanLifecycle;
+import org.jboss.weld.extensions.util.Arrays2;
import org.jboss.weld.extensions.util.Synthetic;
import org.jboss.weld.extensions.util.properties.Properties;
import org.jboss.weld.extensions.util.properties.Property;
@@ -186,7 +190,7 @@
{
for (Annotation concrete : concretes)
{
- event.addBean(redefineType(type, concrete, beanManager));
+ event.addBean(redefineType(type, concrete, beanManager, event));
}
}
}
@@ -194,12 +198,12 @@
}
// TODO Do we need to do something this complex, can't we just register the relevant beans?
- private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager)
+ private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager, AfterBeanDiscovery event)
{
- Synthetic syntheticQualifier = syntheticProvider.get(concrete);
+ Synthetic genericBeanSyntheticQualifier = syntheticProvider.get(concrete);
AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(annotatedType).readAnnotationsFromUnderlyingType();
- builder.addToClass(syntheticQualifier);
+ builder.addToClass(genericBeanSyntheticQualifier);
for (AnnotatedField<? super X> field : annotatedType.getFields())
{
if (field.isAnnotationPresent(Inject.class))
@@ -207,8 +211,9 @@
// if this is a configuration injection point
if (concrete.annotationType().isAssignableFrom(field.getJavaMember().getType()))
{
- builder.removeFromField(field.getJavaMember(), Inject.class);
- builder.addToField(field.getJavaMember(), InjectConfiguration.INSTANCE);
+ Synthetic genericConfigurationQualifier = syntheticProvider.get();
+ builder.addToField(field.getJavaMember(), genericConfigurationQualifier);
+ event.addBean(createConfigurationBean(beanManager, concrete, genericConfigurationQualifier));
}
else
{
@@ -224,7 +229,7 @@
Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qualifiers);
if (beans.isEmpty())
{
- builder.addToField(field.getJavaMember(), syntheticQualifier);
+ builder.addToField(field.getJavaMember(), genericBeanSyntheticQualifier);
}
}
}
@@ -256,7 +261,7 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToMethod(method.getJavaMember(), syntheticQualifier);
+ builder.addToMethod(method.getJavaMember(), genericBeanSyntheticQualifier);
}
}
}
@@ -273,17 +278,38 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), syntheticQualifier);
+ builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), genericBeanSyntheticQualifier);
}
}
}
}
- AnnotatedType<X> newAnnotatedType = builder.create();
- InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
-
- it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, concrete);
- BeanBuilder<X> beanBuilder = new BeanBuilder<X>(newAnnotatedType, beanManager).defineBeanFromAnnotatedType().setInjectionTarget(it);
+ BeanBuilder<X> beanBuilder = new BeanBuilder<X>(beanManager).defineBeanFromAnnotatedType(builder.create());
return beanBuilder.create();
}
+
+ private Bean<Annotation> createConfigurationBean(BeanManager beanManager, final Annotation genericConfiguration, Annotation syntheticQualifier)
+ {
+ BeanBuilder<Annotation> builder = new BeanBuilder<Annotation>(beanManager)
+ .setJavaClass(genericConfiguration.annotationType())
+ .setTypes(Arrays2.<Type>asSet(genericConfiguration.annotationType(), Object.class))
+ .setScope(Dependent.class)
+ .setQualifiers(Arrays2.asSet(syntheticQualifier))
+ // TODO make this passivation capable?
+ .setBeanLifecycle(new BeanLifecycle<Annotation>()
+ {
+
+ public void destroy(Bean<Annotation> bean, Annotation arg0, CreationalContext<Annotation> arg1)
+ {
+ // No-op
+ }
+
+ public Annotation create(Bean<Annotation> bean, CreationalContext<Annotation> arg0)
+ {
+ return genericConfiguration;
+ }
+ });
+
+ return builder.create();
+ }
}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -161,7 +161,7 @@
annotatedTypeBuilder.addToClass(ann);
}
AnnotatedType<X> construtsAnnotatedType = builder.create();
- additionalBeans.add(new BeanBuilder<X>(construtsAnnotatedType, beanManager).create());
+ additionalBeans.add(new BeanBuilder<X>(beanManager).defineBeanFromAnnotatedType(construtsAnnotatedType).create());
}
}
}
Added: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Arrays2.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Arrays2.java (rev 0)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Arrays2.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Arrays2
+{
+
+ private Arrays2() {}
+
+ public static <T> Set<T> asSet(T... array)
+ {
+ Set<T> result = new HashSet<T>();
+ for (T a : array)
+ {
+ result.add(a);
+ }
+ return result;
+ }
+
+}
Property changes on: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Arrays2.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -26,7 +26,8 @@
import javax.enterprise.util.AnnotationLiteral;
/**
- * A synthetic qualifier that can be used to replace other user-supplied configuration at deployment
+ * A synthetic qualifier that can be used to replace other user-supplied
+ * configuration at deployment
*
* @author Stuart Douglas <stuart(a)baileyroberts.com.au>
* @author Pete Muir
@@ -35,18 +36,18 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface Synthetic
{
-
+
long index();
-
+
String namespace();
-
+
public static class SyntheticLiteral extends AnnotationLiteral<Synthetic> implements Synthetic
{
-
+
private final Long index;
-
+
private final String namespace;
-
+
public SyntheticLiteral(String namespace, Long index)
{
this.namespace = namespace;
@@ -57,23 +58,29 @@
{
return index;
}
-
+
public String namespace()
{
return namespace;
}
-
+
}
-
+
+ /**
+ * Provides a unique Synthetic qualifier for the specified namespace
+ *
+ * @author pmuir
+ *
+ */
public static class Provider
{
-
+
//Map of generic Annotation instance to a SyntheticQualifier
private final Map<Annotation, Synthetic> synthetics;
private final String namespace;
-
+
private AtomicLong count;
-
+
public Provider(String namespace)
{
this.synthetics = new HashMap<Annotation, Synthetic>();
@@ -81,6 +88,13 @@
this.count = new AtomicLong();
}
+ /**
+ * Get a synthetic qualifier. The provided annotation is used to map the
+ * generated qualifier, allowing later retrieval.
+ *
+ * @param annotation
+ * @return
+ */
public Synthetic get(Annotation annotation)
{
if (!synthetics.containsKey(annotation))
@@ -89,6 +103,17 @@
}
return synthetics.get(annotation);
}
+
+ /**
+ * Get a synthetic qualifier. The qualifier will not be stored for later
+ * retrieval.
+ *
+ * @return
+ */
+ public Synthetic get()
+ {
+ return new Synthetic.SyntheticLiteral(namespace, count.getAndIncrement());
+ }
}
-
+
}
Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -36,6 +36,9 @@
@Inject
private Corge corge;
+
+ @Inject
+ private Garply garply;
public Bar getBar()
{
@@ -46,4 +49,9 @@
{
return corge;
}
+
+ public Garply getGarply()
+ {
+ return garply;
+ }
}
Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java 2010-07-24 12:23:29 UTC (rev 6795)
@@ -46,7 +46,11 @@
@Test
public void testGeneric()
{
- // Test that the generic injection wiring is working!
+ // Test that the generic configuration injection wiring is working!
+ assert baz1.getGarply() != null;
+ assert baz1.getGarply().equals("hello1");
+ assert baz2.getGarply() != null;
+ assert baz2.getGarply().equals("hello2");
assert baz1.getBar() != null;
assert baz1.getBar().getInjectedGarply() != null;
assert baz1.getBar().getInjectedGarply().value().equals("hello1");
Modified: extensions/trunk/pom.xml
===================================================================
--- extensions/trunk/pom.xml 2010-07-24 12:15:41 UTC (rev 6794)
+++ extensions/trunk/pom.xml 2010-07-24 12:23:29 UTC (rev 6795)
@@ -62,8 +62,8 @@
</ciManagement>
<properties>
- <weld.api.version>1.0-SP1</weld.api.version>
- <weld.core.version>1.0.1-Final</weld.core.version>
+ <weld.api.version>1.1-SNAPSHOT</weld.api.version>
+ <weld.core.version>1.1.0-SNAPSHOT</weld.core.version>
<slf4j.version>1.5.10</slf4j.version>
<testng.version>5.12.1</testng.version>
<jboss.test.harness.version>1.1.0-CR3</jboss.test.harness.version>
13 years, 10 months
Weld SVN: r6792 - in extensions/trunk/impl/src/test/java/org: slf4j/impl and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-24 07:18:31 -0400 (Sat, 24 Jul 2010)
New Revision: 6792
Added:
extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLogger.java
extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLoggerFactory.java
Removed:
extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLogger.java
extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLoggerFactory.java
Modified:
extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/log/LoggerInjectionTest.java
extensions/trunk/impl/src/test/java/org/slf4j/impl/StaticLoggerBinder.java
Log:
avoid Test name to stop JUnit kicking in
Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/log/LoggerInjectionTest.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/log/LoggerInjectionTest.java 2010-07-23 22:49:34 UTC (rev 6791)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/log/LoggerInjectionTest.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -28,7 +28,7 @@
import org.jboss.weld.extensions.log.Category;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.slf4j.impl.TestLoggerFactory;
+import org.slf4j.impl.LastMessageLoggerFactory;
/**
* All the tests related to the @Logger binding type and injection.
@@ -57,18 +57,18 @@
@Test
public void testBasicLogInjection()
{
- TestLoggerFactory.INSTANCE.getLogger("").reset();
+ LastMessageLoggerFactory.INSTANCE.getLogger("").reset();
sparrow.generateLogMessage();
- assert TestLoggerFactory.INSTANCE.getLogger("").getLastMessage() != null;
- assert TestLoggerFactory.INSTANCE.getLogger("").getLastMessage().equals("Sparrow");
+ assert LastMessageLoggerFactory.INSTANCE.getLogger("").getLastMessage() != null;
+ assert LastMessageLoggerFactory.INSTANCE.getLogger("").getLastMessage().equals("Sparrow");
}
@Test
public void testCategorySpecifiedLogger()
{
- TestLoggerFactory.INSTANCE.getLogger("").reset();
+ LastMessageLoggerFactory.INSTANCE.getLogger("").reset();
finch.generateLogMessage();
- assert TestLoggerFactory.INSTANCE.getLogger("").getLastMessage() != null;
- assert TestLoggerFactory.INSTANCE.getLogger("").getLastMessage().equals("Finch");
+ assert LastMessageLoggerFactory.INSTANCE.getLogger("").getLastMessage() != null;
+ assert LastMessageLoggerFactory.INSTANCE.getLogger("").getLastMessage().equals("Finch");
}
}
Copied: extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLogger.java (from rev 6781, extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLogger.java)
===================================================================
--- extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLogger.java (rev 0)
+++ extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLogger.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -0,0 +1,220 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.slf4j.impl;
+
+import org.slf4j.helpers.MarkerIgnoringBase;
+
+/**
+ * A very limited test logger which records the last info message logged
+ */
+public class LastMessageLogger extends MarkerIgnoringBase
+{
+
+ private String lastMessage;
+
+ private static final long serialVersionUID = 8313525025872406710L;
+
+ public String getLastMessage()
+ {
+ return lastMessage;
+ }
+
+ public void reset()
+ {
+ this.lastMessage = null;
+ }
+
+ public void debug(String msg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void debug(String format, Object arg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void debug(String format, Object[] argArray)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void debug(String msg, Throwable t)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void debug(String format, Object arg1, Object arg2)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error(String msg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error(String format, Object arg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error(String format, Object[] argArray)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error(String msg, Throwable t)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void error(String format, Object arg1, Object arg2)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info(String msg)
+ {
+ lastMessage = msg;
+ }
+
+ public void info(String format, Object arg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info(String format, Object[] argArray)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info(String msg, Throwable t)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void info(String format, Object arg1, Object arg2)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isDebugEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isErrorEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isInfoEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isTraceEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isWarnEnabled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void trace(String msg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void trace(String format, Object arg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void trace(String format, Object[] argArray)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void trace(String msg, Throwable t)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void trace(String format, Object arg1, Object arg2)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn(String msg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn(String format, Object arg)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn(String format, Object[] argArray)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn(String msg, Throwable t)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void warn(String format, Object arg1, Object arg2)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Copied: extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLoggerFactory.java (from rev 6781, extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLoggerFactory.java)
===================================================================
--- extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLoggerFactory.java (rev 0)
+++ extensions/trunk/impl/src/test/java/org/slf4j/impl/LastMessageLoggerFactory.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.slf4j.impl;
+
+import org.slf4j.ILoggerFactory;
+
+public class LastMessageLoggerFactory implements ILoggerFactory
+{
+
+ public final static LastMessageLoggerFactory INSTANCE = new LastMessageLoggerFactory();
+
+ private final LastMessageLogger logger = new LastMessageLogger();
+
+ public LastMessageLogger getLogger(String name)
+ {
+ return logger;
+ }
+}
Modified: extensions/trunk/impl/src/test/java/org/slf4j/impl/StaticLoggerBinder.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/slf4j/impl/StaticLoggerBinder.java 2010-07-23 22:49:34 UTC (rev 6791)
+++ extensions/trunk/impl/src/test/java/org/slf4j/impl/StaticLoggerBinder.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -53,7 +53,7 @@
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.9.RC1"; // !final
- private static final String loggerFactoryClassStr = TestLoggerFactory.class.getName();
+ private static final String loggerFactoryClassStr = LastMessageLoggerFactory.class.getName();
/**
* The ILoggerFactory instance returned by the {@link #getLoggerFactory}
@@ -62,7 +62,7 @@
private final ILoggerFactory loggerFactory;
private StaticLoggerBinder() {
- loggerFactory = TestLoggerFactory.INSTANCE;
+ loggerFactory = LastMessageLoggerFactory.INSTANCE;
}
public ILoggerFactory getLoggerFactory() {
Deleted: extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLogger.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLogger.java 2010-07-23 22:49:34 UTC (rev 6791)
+++ extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLogger.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -1,222 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.slf4j.impl;
-
-import org.junit.Ignore;
-import org.slf4j.helpers.MarkerIgnoringBase;
-
-/**
- * A very limited test logger which records the last info message logged
- */
-@Ignore
-public class TestLogger extends MarkerIgnoringBase
-{
-
- private String lastMessage;
-
- private static final long serialVersionUID = 8313525025872406710L;
-
- public String getLastMessage()
- {
- return lastMessage;
- }
-
- public void reset()
- {
- this.lastMessage = null;
- }
-
- public void debug(String msg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void debug(String format, Object arg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void debug(String format, Object[] argArray)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void debug(String msg, Throwable t)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void debug(String format, Object arg1, Object arg2)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void error(String msg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void error(String format, Object arg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void error(String format, Object[] argArray)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void error(String msg, Throwable t)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void error(String format, Object arg1, Object arg2)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void info(String msg)
- {
- lastMessage = msg;
- }
-
- public void info(String format, Object arg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void info(String format, Object[] argArray)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void info(String msg, Throwable t)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void info(String format, Object arg1, Object arg2)
- {
- // TODO Auto-generated method stub
-
- }
-
- public boolean isDebugEnabled()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isErrorEnabled()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isInfoEnabled()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isTraceEnabled()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isWarnEnabled()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void trace(String msg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void trace(String format, Object arg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void trace(String format, Object[] argArray)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void trace(String msg, Throwable t)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void trace(String format, Object arg1, Object arg2)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void warn(String msg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void warn(String format, Object arg)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void warn(String format, Object[] argArray)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void warn(String msg, Throwable t)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void warn(String format, Object arg1, Object arg2)
- {
- // TODO Auto-generated method stub
-
- }
-
-}
Deleted: extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLoggerFactory.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLoggerFactory.java 2010-07-23 22:49:34 UTC (rev 6791)
+++ extensions/trunk/impl/src/test/java/org/slf4j/impl/TestLoggerFactory.java 2010-07-24 11:18:31 UTC (rev 6792)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.slf4j.impl;
-
-import org.junit.Ignore;
-import org.slf4j.ILoggerFactory;
-
-@Ignore
-public class TestLoggerFactory implements ILoggerFactory
-{
-
- public final static TestLoggerFactory INSTANCE = new TestLoggerFactory();
-
- private final TestLogger logger = new TestLogger();
-
- public TestLogger getLogger(String name)
- {
- return logger;
- }
-}
13 years, 10 months
Weld SVN: r6791 - extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-23 18:49:34 -0400 (Fri, 23 Jul 2010)
New Revision: 6791
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
Log:
minor
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:45:30 UTC (rev 6790)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:49:34 UTC (rev 6791)
@@ -161,6 +161,7 @@
List<Property<Object>> setters = new ArrayList<Property<Object>>();
for (Member member : producersOnClass.keySet())
{
+ // TODO Need a producer method property really
Property<Object> property = Properties.createProperty(member);
setters.add(property);
}
@@ -192,6 +193,7 @@
}
}
+ // TODO Do we need to do something this complex, can't we just register the relevant beans?
private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager)
{
Synthetic syntheticQualifier = syntheticProvider.get(concrete);
13 years, 10 months
Weld SVN: r6790 - extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-23 18:45:30 -0400 (Fri, 23 Jul 2010)
New Revision: 6790
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
Log:
minor
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:41:55 UTC (rev 6789)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:45:30 UTC (rev 6790)
@@ -194,10 +194,10 @@
private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager)
{
- Synthetic newQualifier = syntheticProvider.get(concrete);
+ Synthetic syntheticQualifier = syntheticProvider.get(concrete);
AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(annotatedType).readAnnotationsFromUnderlyingType();
- builder.addToClass(newQualifier);
+ builder.addToClass(syntheticQualifier);
for (AnnotatedField<? super X> field : annotatedType.getFields())
{
if (field.isAnnotationPresent(Inject.class))
@@ -222,7 +222,7 @@
Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qualifiers);
if (beans.isEmpty())
{
- builder.addToField(field.getJavaMember(), newQualifier);
+ builder.addToField(field.getJavaMember(), syntheticQualifier);
}
}
}
@@ -254,7 +254,7 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToMethod(method.getJavaMember(), newQualifier);
+ builder.addToMethod(method.getJavaMember(), syntheticQualifier);
}
}
}
@@ -271,7 +271,7 @@
Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), newQualifier);
+ builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), syntheticQualifier);
}
}
}
13 years, 10 months
Weld SVN: r6789 - in extensions/trunk/impl/src/main/java/org/jboss/weld/extensions: util and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-23 18:41:55 -0400 (Fri, 23 Jul 2010)
New Revision: 6789
Added:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerInjectionTarget.java
Removed:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerFieldInjectionTarget.java
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Reflections.java
Log:
tidy up
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:19:51 UTC (rev 6788)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java 2010-07-23 22:41:55 UTC (rev 6789)
@@ -16,6 +16,9 @@
*/
package org.jboss.weld.extensions.bean.generic;
+import static org.jboss.weld.extensions.util.Reflections.EMPTY_ANNOTATION_ARRAY;
+import static org.jboss.weld.extensions.util.Reflections.getQualifiers;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.ArrayList;
@@ -61,7 +64,7 @@
private final Map<Class<?>, Set<AnnotatedType<?>>> genericBeans;
- private final Map<Class<?>, Map<Member, Annotation>> producerFields;
+ private final Map<Class<?>, Map<Member, Annotation>> producers;
// A map of a generic annotation type to all instances of that type found on beans
private final Map<Class<?>, Set<Annotation>> concreteGenerics;
@@ -71,7 +74,7 @@
GenericBeanExtension()
{
this.genericBeans = new HashMap<Class<?>, Set<AnnotatedType<?>>>();
- this.producerFields = new HashMap<Class<?>, Map<Member, Annotation>>();
+ this.producers = new HashMap<Class<?>, Map<Member, Annotation>>();
this.concreteGenerics = new HashMap<Class<?>, Set<Annotation>>();
this.syntheticProvider = new Synthetic.Provider("org.jboss.weld.extensions.bean.generic");
}
@@ -105,15 +108,15 @@
{
if (annotation.annotationType().isAnnotationPresent(GenericConfiguration.class))
{
- if (!producerFields.containsKey(type.getJavaClass()))
+ if (!producers.containsKey(type.getJavaClass()))
{
- producerFields.put(type.getJavaClass(), new HashMap<Member, Annotation>());
+ producers.put(type.getJavaClass(), new HashMap<Member, Annotation>());
}
if (!concreteGenerics.containsKey(annotation.annotationType()))
{
concreteGenerics.put(annotation.annotationType(), new HashSet<Annotation>());
}
- producerFields.get(type.getJavaClass()).put(field.getJavaMember(), annotation);
+ producers.get(type.getJavaClass()).put(field.getJavaMember(), annotation);
concreteGenerics.get(annotation.annotationType()).add(annotation);
}
}
@@ -129,15 +132,15 @@
{
if (annotation.annotationType().isAnnotationPresent(GenericConfiguration.class))
{
- if (!producerFields.containsKey(type.getJavaClass()))
+ if (!producers.containsKey(type.getJavaClass()))
{
- producerFields.put(type.getJavaClass(), new HashMap<Member, Annotation>());
+ producers.put(type.getJavaClass(), new HashMap<Member, Annotation>());
}
if (!concreteGenerics.containsKey(annotation.annotationType()))
{
concreteGenerics.put(annotation.annotationType(), new HashSet<Annotation>());
}
- producerFields.get(type.getJavaClass()).put(method.getJavaMember(), annotation);
+ producers.get(type.getJavaClass()).put(method.getJavaMember(), annotation);
concreteGenerics.get(annotation.annotationType()).add(annotation);
}
}
@@ -151,26 +154,27 @@
*/
<T> void processInjectionTarget(@Observes ProcessInjectionTarget<T> event, BeanManager beanManager)
{
- Class<?> javaClass = event.getAnnotatedType().getJavaClass();
- if (producerFields.containsKey(javaClass))
+ Class<?> clazz = event.getAnnotatedType().getJavaClass();
+ if (producers.containsKey(clazz))
{
- Map<Member, Annotation> producers = producerFields.get(javaClass);
+ Map<Member, Annotation> producersOnClass = producers.get(clazz);
List<Property<Object>> setters = new ArrayList<Property<Object>>();
- for (Member field : producers.keySet())
+ for (Member member : producersOnClass.keySet())
{
- Property<Object> property = Properties.createProperty(field);
+ Property<Object> property = Properties.createProperty(member);
setters.add(property);
}
- ProducerFieldInjectionTarget<T> it = new ProducerFieldInjectionTarget<T>(event.getInjectionTarget(), beanManager, setters, producers, syntheticProvider);
+ ProducerInjectionTarget<T> it = new ProducerInjectionTarget<T>(event.getInjectionTarget(), beanManager, setters, producersOnClass, syntheticProvider);
event.setInjectionTarget(it);
}
+
}
/**
* Installs the generic beans.
*/
- public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager)
+ void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager)
{
for (Entry<Class<?>, Set<AnnotatedType<?>>> entry : genericBeans.entrySet())
{
@@ -179,30 +183,30 @@
{
for (AnnotatedType<?> type : entry.getValue())
{
- for (Annotation conc : concretes)
+ for (Annotation concrete : concretes)
{
- abd.addBean(redefineType(type, conc, beanManager));
+ event.addBean(redefineType(type, concrete, beanManager));
}
}
}
}
}
- private <X> Bean<X> redefineType(AnnotatedType<X> at, Annotation conc, BeanManager beanManager)
+ private <X> Bean<X> redefineType(AnnotatedType<X> annotatedType, Annotation concrete, BeanManager beanManager)
{
- Synthetic newQualifier = syntheticProvider.get(conc);
+ Synthetic newQualifier = syntheticProvider.get(concrete);
- AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(at).readAnnotationsFromUnderlyingType();
+ AnnotatedTypeBuilder<X> builder = AnnotatedTypeBuilder.newInstance(annotatedType).readAnnotationsFromUnderlyingType();
builder.addToClass(newQualifier);
- for (AnnotatedField<? super X> f : at.getFields())
+ for (AnnotatedField<? super X> field : annotatedType.getFields())
{
- if (f.isAnnotationPresent(Inject.class))
+ if (field.isAnnotationPresent(Inject.class))
{
// if this is a configuration injection point
- if (conc.annotationType().isAssignableFrom(f.getJavaMember().getType()))
+ if (concrete.annotationType().isAssignableFrom(field.getJavaMember().getType()))
{
- builder.removeFromField(f.getJavaMember(), Inject.class);
- builder.addToField(f.getJavaMember(), InjectConfiguration.INSTANCE);
+ builder.removeFromField(field.getJavaMember(), Inject.class);
+ builder.addToField(field.getJavaMember(), InjectConfiguration.INSTANCE);
}
else
{
@@ -213,30 +217,31 @@
// point
// this has the downside that if it is actually a deployment
// error then it will confuse the user
- Annotation[] qls = getQualifiers(f.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(f.getJavaMember().getType(), qls);
+ // TODO IMprove this
+ Annotation[] qualifiers = getQualifiers(field.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
+ Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qualifiers);
if (beans.isEmpty())
{
- builder.addToField(f.getJavaMember(), newQualifier);
+ builder.addToField(field.getJavaMember(), newQualifier);
}
}
}
- else if (f.isAnnotationPresent(Produces.class))
+ else if (field.isAnnotationPresent(Produces.class))
{
// TODO: register a producer with the appropriate qualifier
}
}
- for (AnnotatedMethod<?> m : at.getMethods())
+ for (AnnotatedMethod<?> method : annotatedType.getMethods())
{
// TODO: need to properly handle Observer methods and Disposal
// methods
- if (m.isAnnotationPresent(Produces.class))
+ if (method.isAnnotationPresent(Produces.class))
{
// TODO: we need to register the producer bean, so this is not
// very useful at the moment
- for (AnnotatedParameter<?> pm : m.getParameters())
+ for (AnnotatedParameter<?> pm : method.getParameters())
{
- Class<?> paramType = m.getJavaMember().getParameterTypes()[pm.getPosition()];
+ Class<?> paramType = method.getJavaMember().getParameterTypes()[pm.getPosition()];
// check to see if we should be injecting a generic bean
// we do this by checking if there are any beans that can be
@@ -245,28 +250,28 @@
// point
// this has the downside that if it is actually a deployment
// error then it will confuse the user
- Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ Annotation[] qualifiers = getQualifiers(pm.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToMethod(m.getJavaMember(), newQualifier);
+ builder.addToMethod(method.getJavaMember(), newQualifier);
}
}
}
}
- for (AnnotatedConstructor<X> m : at.getConstructors())
+ for (AnnotatedConstructor<X> constructor : annotatedType.getConstructors())
{
- if (m.isAnnotationPresent(Inject.class))
+ if (constructor.isAnnotationPresent(Inject.class))
{
- for (AnnotatedParameter<X> pm : m.getParameters())
+ for (AnnotatedParameter<X> parameter : constructor.getParameters())
{
- Class<?> paramType = m.getJavaMember().getParameterTypes()[pm.getPosition()];
- Annotation[] qls = getQualifiers(pm.getAnnotations(), beanManager);
- Set<Bean<?>> beans = beanManager.getBeans(paramType, qls);
+ Class<?> paramType = constructor.getJavaMember().getParameterTypes()[parameter.getPosition()];
+ Annotation[] qualifiers = getQualifiers(parameter.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
+ Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
if (beans.isEmpty())
{
- builder.addToConstructorParameter(m.getJavaMember(), pm.getPosition(), newQualifier);
+ builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), newQualifier);
}
}
}
@@ -274,27 +279,9 @@
AnnotatedType<X> newAnnotatedType = builder.create();
InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
- it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, conc);
+ it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, concrete);
BeanBuilder<X> beanBuilder = new BeanBuilder<X>(newAnnotatedType, beanManager).defineBeanFromAnnotatedType().setInjectionTarget(it);
return beanBuilder.create();
}
- static Annotation[] getQualifiers(Set<Annotation> annotations, BeanManager manager)
- {
- List<Annotation> qualifiers = new ArrayList<Annotation>();
- for (Annotation a : annotations)
- {
- if (manager.isQualifier(a.annotationType()))
- {
- qualifiers.add(a);
- }
- }
- Annotation[] qls = new Annotation[qualifiers.size()];
- for (int j = 0; j < qls.length; ++j)
- {
- qls[j] = qualifiers.get(j);
- }
- return qls;
- }
-
}
Deleted: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerFieldInjectionTarget.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerFieldInjectionTarget.java 2010-07-23 22:19:51 UTC (rev 6788)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerFieldInjectionTarget.java 2010-07-23 22:41:55 UTC (rev 6789)
@@ -1,82 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean.generic;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.util.List;
-import java.util.Map;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionTarget;
-
-import org.jboss.weld.extensions.bean.ForwardingInjectionTarget;
-import org.jboss.weld.extensions.util.Synthetic;
-import org.jboss.weld.extensions.util.properties.Property;
-
-/**
- * {@link InjectionTarget} wrapper used for beans that have generic producer fields
- *
- * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
- *
- * @param <T>
- */
-public class ProducerFieldInjectionTarget<T> extends ForwardingInjectionTarget<T>
-{
- private final InjectionTarget<T> delegate;
-
- private final BeanManager beanManager;
- private final List<Property<Object>> properties;
- private final Map<Member, Annotation> producers;
- private final Synthetic.Provider syntheticProvider;
-
- public ProducerFieldInjectionTarget(InjectionTarget<T> delegate, BeanManager beanManager, List<Property<Object>> properties, Map<Member, Annotation> producers, Synthetic.Provider syntheticProvider)
- {
- this.delegate = delegate;
- this.beanManager = beanManager;
- this.properties = properties;
- this.producers = producers;
- this.syntheticProvider = syntheticProvider;
- }
-
- @Override
- protected InjectionTarget<T> delegate()
- {
- return delegate;
- }
-
- @Override
- public void inject(T instance, CreationalContext<T> ctx)
- {
- for (Property<Object> property: properties)
- {
- Synthetic qualifier = syntheticProvider.get(producers.get(property.getMember()));
- Bean<?> bean = beanManager.resolve(beanManager.getBeans(property.getBaseType(), qualifier));
- if (bean == null)
- {
- throw new UnsatisfiedResolutionException("Could not resolve bean for Generic Producer " + property.toString() + ". Type: " + property.getJavaClass() + " Qualifiers:" + qualifier);
- }
- Object value = beanManager.getReference(bean, property.getBaseType(), ctx);
- property.setValue(instance, value);
- }
- delegate().inject(instance, ctx);
- }
-
-}
Copied: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerInjectionTarget.java (from rev 6784, extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerFieldInjectionTarget.java)
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerInjectionTarget.java (rev 0)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/ProducerInjectionTarget.java 2010-07-23 22:41:55 UTC (rev 6789)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean.generic;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.jboss.weld.extensions.bean.ForwardingInjectionTarget;
+import org.jboss.weld.extensions.util.Synthetic;
+import org.jboss.weld.extensions.util.properties.Property;
+
+/**
+ * {@link InjectionTarget} wrapper used for beans that have generic producer fields
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ * @param <T>
+ */
+public class ProducerInjectionTarget<T> extends ForwardingInjectionTarget<T>
+{
+ private final InjectionTarget<T> delegate;
+
+ private final BeanManager beanManager;
+ private final List<Property<Object>> properties;
+ private final Map<Member, Annotation> producers;
+ private final Synthetic.Provider syntheticProvider;
+
+ public ProducerInjectionTarget(InjectionTarget<T> delegate, BeanManager beanManager, List<Property<Object>> properties, Map<Member, Annotation> producers, Synthetic.Provider syntheticProvider)
+ {
+ this.delegate = delegate;
+ this.beanManager = beanManager;
+ this.properties = properties;
+ this.producers = producers;
+ this.syntheticProvider = syntheticProvider;
+ }
+
+ @Override
+ protected InjectionTarget<T> delegate()
+ {
+ return delegate;
+ }
+
+ @Override
+ public void inject(T instance, CreationalContext<T> ctx)
+ {
+ for (Property<Object> property: properties)
+ {
+ Synthetic qualifier = syntheticProvider.get(producers.get(property.getMember()));
+ Bean<?> bean = beanManager.resolve(beanManager.getBeans(property.getBaseType(), qualifier));
+ if (bean == null)
+ {
+ throw new UnsatisfiedResolutionException("Could not resolve bean for Generic Producer " + property.toString() + ". Type: " + property.getJavaClass() + " Qualifiers:" + qualifier);
+ }
+ Object value = beanManager.getReference(bean, property.getBaseType(), ctx);
+ property.setValue(instance, value);
+ }
+ delegate().inject(instance, ctx);
+ }
+
+}
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Reflections.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-23 22:19:51 UTC (rev 6788)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-23 22:41:55 UTC (rev 6789)
@@ -38,6 +38,8 @@
*/
public class Reflections
{
+
+ public static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
private Reflections()
{
13 years, 10 months
Weld SVN: r6788 - extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-23 18:19:51 -0400 (Fri, 23 Jul 2010)
New Revision: 6788
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java
Log:
no longer need @Qualifier here
Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java 2010-07-23 22:18:14 UTC (rev 6787)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/util/Synthetic.java 2010-07-23 22:19:51 UTC (rev 6788)
@@ -24,7 +24,6 @@
import java.util.concurrent.atomic.AtomicLong;
import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Qualifier;
/**
* A synthetic qualifier that can be used to replace other user-supplied configuration at deployment
@@ -34,9 +33,6 @@
*
*/
@Retention(RetentionPolicy.RUNTIME)
-// even though this is not in a bean archive this is still needed to make
-// BeanImpl work
-@Qualifier
public @interface Synthetic
{
13 years, 10 months
Weld SVN: r6787 - extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-23 18:18:14 -0400 (Fri, 23 Jul 2010)
New Revision: 6787
Removed:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/InjectGeneric.java
Log:
remove unused annotation
Deleted: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/InjectGeneric.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/InjectGeneric.java 2010-07-23 22:16:42 UTC (rev 6786)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/InjectGeneric.java 2010-07-23 22:18:14 UTC (rev 6787)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean.generic;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * used to mark where a generic bean should be injected in place of the normal
- * @Inject, this may not be required in the future
- *
- * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
- *
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-@Target( { ElementType.FIELD, ElementType.PARAMETER })
-public @interface InjectGeneric
-{
-
-}
13 years, 10 months