[weld-commits] Weld SVN: r6804 - extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Sat Jul 24 11:38:50 EDT 2010
Author: pete.muir at jboss.org
Date: 2010-07-24 11:38:50 -0400 (Sat, 24 Jul 2010)
New Revision: 6804
Added:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableBean.java
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableProducer.java
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java
Log:
Split out helper base class, add helper base class for Producer
Added: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableBean.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableBean.java (rev 0)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableBean.java 2010-07-24 15:38:50 UTC (rev 6804)
@@ -0,0 +1,171 @@
+package org.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+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 org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.jboss.weld.extensions.util.Arrays2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A base class for implementing {@link Bean}. The base class is immutable, and
+ * uses defensive copying for collections. It uses the defaults from the spec
+ * for properties if not specified.
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractImmutableBean<T>
+{
+
+ private static final Logger log = LoggerFactory.getLogger(AbstractImmutableBean.class);
+
+ private final Class<?> beanClass;
+ private final String name;
+ private final Set<Annotation> qualifiers;
+ private final Class<? extends Annotation> scope;
+ private final Set<Class<? extends Annotation>> stereotypes;
+ private final Set<Type> types;
+ private final boolean alternative;
+ private final boolean nullable;
+ private final Set<InjectionPoint> injectionPoints;
+
+ /**
+ * 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 AbstractImmutableBean(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)
+ {
+ if (beanClass == null)
+ {
+ throw new IllegalArgumentException("beanClass cannot be null");
+ }
+ this.beanClass = beanClass;
+ this.name = name;
+ 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;
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return injectionPoints;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.unmodifiableSet(qualifiers);
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.unmodifiableSet(stereotypes);
+ }
+
+ public Set<Type> getTypes()
+ {
+ return Collections.unmodifiableSet(types);
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
+ }
+
+}
\ No newline at end of file
Property changes on: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableProducer.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableProducer.java (rev 0)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableProducer.java 2010-07-24 15:38:50 UTC (rev 6804)
@@ -0,0 +1,31 @@
+package org.jboss.weld.extensions.bean;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Producer;
+
+/**
+ * A base class for implementing {@link Producer}. The base class is immutable,
+ * and uses defensive copying for collections
+ *
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractImmutableProducer<T> implements Producer<T>
+{
+
+ private final Set<InjectionPoint> injectionPoints;
+
+ public AbstractImmutableProducer(Set<InjectionPoint> injectionPoints)
+ {
+ this.injectionPoints = injectionPoints;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return new HashSet<InjectionPoint>(injectionPoints);
+ }
+
+}
Property changes on: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/AbstractImmutableProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
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 15:05:21 UTC (rev 6803)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java 2010-07-24 15:38:50 UTC (rev 6804)
@@ -18,8 +18,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.Dependent;
@@ -28,11 +26,6 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
-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 which provides basic defaulting and checking of arguments.
*
@@ -40,22 +33,10 @@
* @author Pete Muir
*
*/
-public class BeanImpl<T> implements Bean<T>
+public class BeanImpl<T> extends AbstractImmutableBean<T> implements Bean<T>
{
- private static final Logger log = LoggerFactory.getLogger(BeanImpl.class);
-
- private final Class<?> beanClass;
- private final String name;
- private final Set<Annotation> qualifiers;
- private final Class<? extends Annotation> scope;
- private final Set<Class<? extends Annotation>> stereotypes;
- private final Set<Type> types;
- private final boolean alternative;
- private final boolean nullable;
- private final BeanLifecycle<T> beanLifecycle;
- private final Set<InjectionPoint> injectionPoints;
-
+ final BeanLifecycle<T> beanLifecycle;
/**
* Create a new, immutable bean. All arguments passed as collections are defensively copied.
*
@@ -78,105 +59,10 @@
*/
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.name = name;
- 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;
+ super(beanClass, name, qualifiers, scope, stereotypes, types, alternative, nullable, injectionPoints);
this.beanLifecycle = beanLifecycle;
}
-
- public Class<?> getBeanClass()
- {
- return beanClass;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return injectionPoints;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return Collections.unmodifiableSet(qualifiers);
- }
-
- public Class<? extends Annotation> getScope()
- {
- return scope;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return Collections.unmodifiableSet(stereotypes);
- }
-
- public Set<Type> getTypes()
- {
- return Collections.unmodifiableSet(types);
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public boolean isNullable()
- {
- return nullable;
- }
-
+
public T create(CreationalContext<T> arg0)
{
return beanLifecycle.create(this, arg0);
@@ -187,10 +73,4 @@
beanLifecycle.destroy(this, arg0, arg1);
}
- @Override
- public String toString()
- {
- return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
- }
-
}
More information about the weld-commits
mailing list