public class BeanBuilder<T> extends Object
A builder class for creating immutable beans. The builder can create
PassivationCapable
beans.
The builder can read from an AnnotatedType
and have any attribute
modified. This class is not thread-safe, but the bean created by calling
create()
is.
It is advised that a new bean builder is instantiated for each bean created.
Modifier and Type | Field and Description |
---|---|
protected boolean |
alternative |
protected Class<?> |
beanClass |
protected ContextualLifecycle<T> |
beanLifecycle |
protected javax.enterprise.inject.spi.BeanManager |
beanManager |
protected String |
id |
protected Set<javax.enterprise.inject.spi.InjectionPoint> |
injectionPoints |
protected String |
name |
protected boolean |
nullable |
protected boolean |
passivationCapable |
protected Set<Annotation> |
qualifiers |
protected Class<? extends Annotation> |
scope |
protected Set<Class<? extends Annotation>> |
stereotypes |
protected String |
toString |
protected Set<Type> |
types |
Constructor and Description |
---|
BeanBuilder(javax.enterprise.inject.spi.BeanManager beanManager)
Instantiate a new bean builder.
|
Modifier and Type | Method and 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(Collection<Type> types)
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> |
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 the
ContextualLifecycle used 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()
The
ContextualLifecycle currently defined for bean creation. |
javax.enterprise.inject.spi.BeanManager |
getBeanManager()
The bean manager in use.
|
String |
getId()
The id currently defined for bean creation.
|
Set<javax.enterprise.inject.spi.InjectionPoint> |
getInjectionPoints()
The injection points currently defined for bean creation.
|
String |
getName()
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.
|
String |
getToString()
The string used when
Object.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.
|
boolean |
isAlternative()
Whether the created bean will be an alternative.
|
boolean |
isNullable()
Whether the created bean will be nullable.
|
boolean |
isPassivationCapable()
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 the
AnnotatedType , creating a bean from the class and it's
annotations. |
BeanBuilder<T> |
scope(Class<? extends Annotation> scope)
Define the scope used for bean creation.
|
protected void |
setDefaultBeanLifecycle(javax.enterprise.inject.spi.AnnotatedType<T> type)
Set the ContextualLifecycle and the InjectionPoints for the AnnotatedType
|
BeanBuilder<T> |
stereotypes(Set<Class<? extends Annotation>> stereotypes)
Define the stereotypes used for bean creation.
|
BeanBuilder<T> |
toString(String toString)
Define the string used when
Object.toString() is called on the bean. |
BeanBuilder<T> |
types(Set<Type> types)
Define the type closure used for bean creation.
|
BeanBuilder<T> |
types(Type... types)
Define the type closure used for bean creation.
|
protected final javax.enterprise.inject.spi.BeanManager beanManager
protected Class<?> beanClass
protected String name
protected Set<Annotation> qualifiers
protected Class<? extends Annotation> scope
protected Set<Class<? extends Annotation>> stereotypes
protected Set<javax.enterprise.inject.spi.InjectionPoint> injectionPoints
protected boolean alternative
protected boolean nullable
protected ContextualLifecycle<T> beanLifecycle
protected boolean passivationCapable
protected String id
protected String toString
public BeanBuilder(javax.enterprise.inject.spi.BeanManager beanManager)
beanManager
- the bean manager to use for creating injection targets
and determining if annotations are qualifiers, scopes or
stereotypes.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)
.
BeanBuilder
does not support reading members of the class
to create producers or observer methods.
type
- the type to readprotected void setDefaultBeanLifecycle(javax.enterprise.inject.spi.AnnotatedType<T> type)
type
- public javax.enterprise.inject.spi.Bean<T> create()
Use the bean builder's current state to define the bean.
public Set<Annotation> getQualifiers()
public BeanBuilder<T> qualifiers(Set<Annotation> qualifiers)
qualifiers
- the qualifiers to usepublic BeanBuilder<T> qualifiers(Annotation... qualifiers)
qualifiers
- the qualifiers to usepublic BeanBuilder<T> addQualifier(Annotation qualifier)
qualifier
- the additional qualifier to usepublic BeanBuilder<T> addQualifiers(Annotation... qualifiers)
qualifiers
- the additional qualifiers to usepublic BeanBuilder<T> addQualifiers(Collection<Annotation> qualifiers)
qualifiers
- the additional qualifiers to usepublic Class<? extends Annotation> getScope()
public BeanBuilder<T> scope(Class<? extends Annotation> scope)
scope
- the scope to usepublic Set<Class<? extends Annotation>> getStereotypes()
public BeanBuilder<T> stereotypes(Set<Class<? extends Annotation>> stereotypes)
stereotypes
- the stereotypes to usepublic Set<Type> getTypes()
public BeanBuilder<T> types(Set<Type> types)
types
- the type closure to usepublic BeanBuilder<T> types(Type... types)
types
- the type closure to usepublic BeanBuilder<T> addType(Type type)
type
- additional type to usepublic BeanBuilder<T> addTypes(Type... types)
types
- the additional types to usepublic BeanBuilder<T> addTypes(Collection<Type> types)
types
- the additional types to usepublic boolean isAlternative()
true
if the created bean will be an alternative,
otherwise false
public BeanBuilder<T> alternative(boolean alternative)
alternative
- true
if the created bean should be an
alternative, otherwise false
public boolean isNullable()
true
if the created bean will be nullable, otherwise
false
public BeanBuilder<T> nullable(boolean nullable)
nullable
- true
if the created bean should be nullable,
otherwise false
public ContextualLifecycle<T> getBeanLifecycle()
ContextualLifecycle
currently defined for bean creation.public BeanBuilder<T> beanLifecycle(ContextualLifecycle<T> beanLifecycle)
ContextualLifecycle
used for bean creation.beanLifecycle
- the ContextualLifecycle
to use for bean
creation.public Class<?> getBeanClass()
public BeanBuilder<T> beanClass(Class<?> beanClass)
beanClass
- the bean class to usepublic javax.enterprise.inject.spi.BeanManager getBeanManager()
BeanBuilder
.public String getName()
null
if the bean has no namepublic BeanBuilder<T> name(String name)
name
- the name of the bean to use or null
if the bean
should have no namepublic boolean isPassivationCapable()
true
if the created bean will be passivation capable,
otherwise false
public BeanBuilder<T> passivationCapable(boolean passivationCapable)
passivationCapable
- true
if the created bean should be
passivation capable, otherwise false
public String getId()
public BeanBuilder<T> id(String id)
id
- the id to usepublic Set<javax.enterprise.inject.spi.InjectionPoint> getInjectionPoints()
public BeanBuilder<T> injectionPoints(Set<javax.enterprise.inject.spi.InjectionPoint> injectionPoints)
injectionPoints
- the injection points to usepublic BeanBuilder<T> toString(String toString)
Object.toString()
is called on the bean.toString
- the string to usepublic String getToString()
Object.toString()
is called on the bean.Copyright © 2020 The Apache Software Foundation. All rights reserved.