Class BeanBuilder<T>
- java.lang.Object
-
- org.infinispan.cdi.common.util.BeanBuilder<T>
-
public class BeanBuilder<T> extends Object
A builder class for creating immutable beans. The builder can create
PassivationCapablebeans, usingAnnotateds.createTypeId(AnnotatedType)to generate the id.The builder can read from an
AnnotatedTypeand have any attribute modified. This class is not thread-safe, but the bean created by callingcreate()is.It is advised that a new bean builder is instantiated for each bean created.
- Author:
- Stuart Douglas, Pete Muir
- See Also:
ImmutableBean,ImmutablePassivationCapableBean
-
-
Constructor Summary
Constructors Constructor Description BeanBuilder(javax.enterprise.inject.spi.BeanManager beanManager)Instantiate a new bean builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanBuilder<T>addQualifier(Annotation qualifier)Add to the qualifiers used for bean creation.BeanBuilder<T>addQualifiers(Annotation... qualifiers)Add to the qualifiers used for bean creation.BeanBuilder<T>addQualifiers(Collection<Annotation> qualifiers)Add to the qualifiers used for bean creation.BeanBuilder<T>addType(Type type)Add to the type closure used for bean creation.BeanBuilder<T>addTypes(Type... types)Add to the type closure used for bean creation.BeanBuilder<T>addTypes(Collection<Type> types)Add to the type closure used for bean creation.BeanBuilder<T>alternative(boolean alternative)Define that the created bean will (or will not) be an alternative.BeanBuilder<T>beanClass(Class<?> beanClass)Define the bean class used for bean creation.BeanBuilder<T>beanLifecycle(ContextualLifecycle<T> beanLifecycle)Define theContextualLifecycleused for bean creation.javax.enterprise.inject.spi.Bean<T>create()Use the bean builder's current state to define the bean.Class<?>getBeanClass()The bean class currently defined for bean creation.ContextualLifecycle<T>getBeanLifecycle()TheContextualLifecyclecurrently defined for bean creation.javax.enterprise.inject.spi.BeanManagergetBeanManager()The bean manager in use.StringgetId()The id currently defined for bean creation.Set<javax.enterprise.inject.spi.InjectionPoint>getInjectionPoints()The injection points currently defined for bean creation.StringgetName()The name of the bean currently defined for bean creation.Set<Annotation>getQualifiers()Qualifiers currently defined for bean creation.Class<? extends Annotation>getScope()Scope currently defined for bean creation.Set<Class<? extends Annotation>>getStereotypes()Stereotypes currently defined for bean creation.StringgetToString()The string used whenObject.toString()is called on the bean.Set<Type>getTypes()Type closure currently defined for bean creation.BeanBuilder<T>id(String id)Define the id used for bean creation.BeanBuilder<T>injectionPoints(Set<javax.enterprise.inject.spi.InjectionPoint> injectionPoints)Define the injection points used for bean creation.booleanisAlternative()Whether the created bean will be an alternative.booleanisNullable()Whether the created bean will be nullable.booleanisPassivationCapable()Whether the created bean will be passivation capable.BeanBuilder<T>name(String name)Define the name of the bean used for bean creation.BeanBuilder<T>nullable(boolean nullable)Define that the created bean will (or will not) be nullable.BeanBuilder<T>passivationCapable(boolean passivationCapable)Define that the created bean will (or will not) be passivation capable.BeanBuilder<T>qualifiers(Annotation... qualifiers)Define the qualifiers used for bean creation.BeanBuilder<T>qualifiers(Set<Annotation> qualifiers)Define the qualifiers used for bean creation.BeanBuilder<T>readFromType(javax.enterprise.inject.spi.AnnotatedType<T> type)Read theAnnotatedType, creating a bean from the class and it's annotations.BeanBuilder<T>scope(Class<? extends Annotation> scope)Define the scope used for bean creation.BeanBuilder<T>stereotypes(Set<Class<? extends Annotation>> stereotypes)Define the stereotypes used for bean creation.BeanBuilder<T>toString(String toString)Define the string used whenObject.toString()is called on the bean.BeanBuilder<T>types(Type... types)Define the type closure used for bean creation.BeanBuilder<T>types(Set<Type> types)Define the type closure used for bean creation.
-
-
-
Method Detail
-
readFromType
public BeanBuilder<T> readFromType(javax.enterprise.inject.spi.AnnotatedType<T> type)
Read the
AnnotatedType, creating a bean from the class and it's annotations.By default the bean lifecycle will wrap the result of calling
BeanManager.createInjectionTarget(AnnotatedType).BeanBuilderdoes not support reading members of the class to create producers or observer methods.- Parameters:
type- the type to read
-
create
public javax.enterprise.inject.spi.Bean<T> create()
Use the bean builder's current state to define the bean.
- Returns:
- the bean
-
getQualifiers
public Set<Annotation> getQualifiers()
Qualifiers currently defined for bean creation.- Returns:
- the qualifiers current defined
-
qualifiers
public BeanBuilder<T> qualifiers(Set<Annotation> qualifiers)
Define the qualifiers used for bean creation.- Parameters:
qualifiers- the qualifiers to use
-
qualifiers
public BeanBuilder<T> qualifiers(Annotation... qualifiers)
Define the qualifiers used for bean creation.- Parameters:
qualifiers- the qualifiers to use
-
addQualifier
public BeanBuilder<T> addQualifier(Annotation qualifier)
Add to the qualifiers used for bean creation.- Parameters:
qualifiers- the additional qualifier to use
-
addQualifiers
public BeanBuilder<T> addQualifiers(Annotation... qualifiers)
Add to the qualifiers used for bean creation.- Parameters:
qualifiers- the additional qualifiers to use
-
addQualifiers
public BeanBuilder<T> addQualifiers(Collection<Annotation> qualifiers)
Add to the qualifiers used for bean creation.- Parameters:
qualifiers- the additional qualifiers to use
-
getScope
public Class<? extends Annotation> getScope()
Scope currently defined for bean creation.- Returns:
- the scope currently defined
-
scope
public BeanBuilder<T> scope(Class<? extends Annotation> scope)
Define the scope used for bean creation.- Parameters:
scope- the scope to use
-
getStereotypes
public Set<Class<? extends Annotation>> getStereotypes()
Stereotypes currently defined for bean creation.- Returns:
- the stereotypes currently defined
-
stereotypes
public BeanBuilder<T> stereotypes(Set<Class<? extends Annotation>> stereotypes)
Define the stereotypes used for bean creation.- Parameters:
stereotypes- the stereotypes to use
-
getTypes
public Set<Type> getTypes()
Type closure currently defined for bean creation.- Returns:
- the type closure currently defined
-
types
public BeanBuilder<T> types(Set<Type> types)
Define the type closure used for bean creation.- Parameters:
types- the type closure to use
-
types
public BeanBuilder<T> types(Type... types)
Define the type closure used for bean creation.- Parameters:
types- the type closure to use
-
addType
public BeanBuilder<T> addType(Type type)
Add to the type closure used for bean creation.- Parameters:
type- additional type to use
-
addTypes
public BeanBuilder<T> addTypes(Type... types)
Add to the type closure used for bean creation.- Parameters:
types- the additional types to use
-
addTypes
public BeanBuilder<T> addTypes(Collection<Type> types)
Add to the type closure used for bean creation.- Parameters:
types- the additional types to use
-
isAlternative
public boolean isAlternative()
Whether the created bean will be an alternative.- Returns:
trueif the created bean will be an alternative, otherwisefalse
-
alternative
public BeanBuilder<T> alternative(boolean alternative)
Define that the created bean will (or will not) be an alternative.- Parameters:
alternative-trueif the created bean should be an alternative, otherwisefalse
-
isNullable
public boolean isNullable()
Whether the created bean will be nullable.- Returns:
trueif the created bean will be nullable, otherwisefalse
-
nullable
public BeanBuilder<T> nullable(boolean nullable)
Define that the created bean will (or will not) be nullable.- Parameters:
nullable-trueif the created bean should be nullable, otherwisefalse
-
getBeanLifecycle
public ContextualLifecycle<T> getBeanLifecycle()
TheContextualLifecyclecurrently defined for bean creation.- Returns:
- the bean lifecycle currently defined
-
beanLifecycle
public BeanBuilder<T> beanLifecycle(ContextualLifecycle<T> beanLifecycle)
Define theContextualLifecycleused for bean creation.- Parameters:
beanLifecycle- theContextualLifecycleto use for bean creation.
-
getBeanClass
public Class<?> getBeanClass()
The bean class currently defined for bean creation.- Returns:
- the bean class currently defined.
-
beanClass
public BeanBuilder<T> beanClass(Class<?> beanClass)
Define the bean class used for bean creation.- Parameters:
beanClass- the bean class to use
-
getBeanManager
public javax.enterprise.inject.spi.BeanManager getBeanManager()
The bean manager in use. This cannot be changed for thisBeanBuilder.- Returns:
- the bean manager in use
-
getName
public String getName()
The name of the bean currently defined for bean creation.- Returns:
- the name of the bean or
nullif the bean has no name
-
name
public BeanBuilder<T> name(String name)
Define the name of the bean used for bean creation.- Parameters:
name- the name of the bean to use ornullif the bean should have no name
-
isPassivationCapable
public boolean isPassivationCapable()
Whether the created bean will be passivation capable.- Returns:
trueif the created bean will be passivation capable, otherwisefalse
-
passivationCapable
public BeanBuilder<T> passivationCapable(boolean passivationCapable)
Define that the created bean will (or will not) be passivation capable.- Parameters:
nullable-trueif the created bean should be passivation capable, otherwisefalse
-
getId
public String getId()
The id currently defined for bean creation.- Returns:
- the id currently defined.
-
id
public BeanBuilder<T> id(String id)
Define the id used for bean creation.- Parameters:
id- the id to use
-
getInjectionPoints
public Set<javax.enterprise.inject.spi.InjectionPoint> getInjectionPoints()
The injection points currently defined for bean creation.- Returns:
- the injection points currently defined.
-
injectionPoints
public BeanBuilder<T> injectionPoints(Set<javax.enterprise.inject.spi.InjectionPoint> injectionPoints)
Define the injection points used for bean creation.- Parameters:
injectionPoints- the injection points to use
-
toString
public BeanBuilder<T> toString(String toString)
Define the string used whenObject.toString()is called on the bean.- Parameters:
toString- the string to use
-
getToString
public String getToString()
The string used whenObject.toString()is called on the bean.- Returns:
- the string currently defined
-
-