org.jboss.seam.solder.bean
Class BeanBuilder<T>

java.lang.Object
  extended by org.jboss.seam.solder.bean.BeanBuilder<T>

public class BeanBuilder<T>
extends Object

A builder class for creating immutable beans. The builder can create PassivationCapable beans, using Annotateds.createTypeId(AnnotatedType) to generate the id.

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.

Author:
Stuart Douglas, Pete Muir
See Also:
ImmutableBean, ImmutablePassivationCapableBean

Constructor Summary
BeanBuilder(BeanManager beanManager)
          Instantiate a new bean builder.
 
Method Summary
 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.
 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.
 BeanManager getBeanManager()
          The bean manager in use.
 String getId()
          The id currently defined for bean creation.
 Set<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<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(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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanBuilder

public BeanBuilder(BeanManager beanManager)
Instantiate a new bean builder.

Parameters:
beanManager - the bean manager to use for creating injection targets and determining if annotations are qualifiers, scopes or stereotypes.
Method Detail

readFromType

public BeanBuilder<T> readFromType(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.

Parameters:
type - the type to read

create

public 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:
true if the created bean will be an alternative, otherwise false

alternative

public BeanBuilder<T> alternative(boolean alternative)
Define that the created bean will (or will not) be an alternative.

Parameters:
alternative - true if the created bean should be an alternative, otherwise false

isNullable

public boolean isNullable()
Whether the created bean will be nullable.

Returns:
true if the created bean will be nullable, otherwise false

nullable

public BeanBuilder<T> nullable(boolean nullable)
Define that the created bean will (or will not) be nullable.

Parameters:
nullable - true if the created bean should be nullable, otherwise false

getBeanLifecycle

public ContextualLifecycle<T> getBeanLifecycle()
The ContextualLifecycle currently defined for bean creation.

Returns:
the bean lifecycle currently defined

beanLifecycle

public BeanBuilder<T> beanLifecycle(ContextualLifecycle<T> beanLifecycle)
Define the ContextualLifecycle used for bean creation.

Parameters:
beanLifecycle - the ContextualLifecycle to 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 BeanManager getBeanManager()
The bean manager in use. This cannot be changed for this BeanBuilder.

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 null if 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 or null if the bean should have no name

isPassivationCapable

public boolean isPassivationCapable()
Whether the created bean will be passivation capable.

Returns:
true if the created bean will be passivation capable, otherwise false

passivationCapable

public BeanBuilder<T> passivationCapable(boolean passivationCapable)
Define that the created bean will (or will not) be passivation capable.

Parameters:
nullable - true if the created bean should be passivation capable, otherwise false

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<InjectionPoint> getInjectionPoints()
The injection points currently defined for bean creation.

Returns:
the injection points currently defined.

injectionPoints

public BeanBuilder<T> injectionPoints(Set<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 when Object.toString() is called on the bean.

Parameters:
toString - the string to use

getToString

public String getToString()
The string used when Object.toString() is called on the bean.

Returns:
the string currently defined


Copyright © 2008-2010 Seam Framework. All Rights Reserved.