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

java.lang.Object
  extended by org.jboss.seam.solder.bean.AbstractImmutableBean<T>
      extended by org.jboss.seam.solder.bean.ImmutableNarrowingBean<T>
All Implemented Interfaces:
Contextual<T>, Bean<T>
Direct Known Subclasses:
ImmutablePassivationCapableNarrowingBean

public class ImmutableNarrowingBean<T>
extends AbstractImmutableBean<T>

A narrowing bean allows you to build a general purpose bean (likely a producer method), and register it for a narrowed type (or qualifiers). For example, you could create a producer method which uses an a String ID to located an object (the object can have any class):

 @Produces
 // Use some synthetic scope to prevent this from interfering with other
 // resolutions
 @MyProducer
 Object produce(InjectionPoint ip)
 {
    String id = ip.getAnnotated().getAnnotation(Id.class).value();
    // Lookup and return the object for the id
 }
 

The delegate bean must return an object which can be cast to the type T, otherwise a ClassCastException will be thrown at runtime when the bean is created.

You can then register a narrowing bean for each type you need:

 event.addBean(new NarrowingBeanBuilder<T>(delegateBean).readFromType(type).create());
 

ImmutableNarrowingBean will use the annotations on defininingType to discover the qualifiers, types, scope, stereotypes of the bean, as well as determine it's name (if any) and whether it is an alternative.

The attributes are immutable, and collections are defensively copied on instantiation. It uses the defaults from the specification for properties if not specified.

Author:
Pete Muir
See Also:
NarrowingBeanBuilder, ImmutablePassivationCapableNarrowingBean

Constructor Summary
ImmutableNarrowingBean(Bean<Object> delegate, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, String toString)
          Instantiate a new ImmutableNarrowingBean.
 
Method Summary
 T create(CreationalContext<T> creationalContext)
           
 void destroy(T instance, CreationalContext<T> creationalContext)
           
 
Methods inherited from class org.jboss.seam.solder.bean.AbstractImmutableBean
getBeanClass, getInjectionPoints, getName, getQualifiers, getScope, getStereotypes, getTypes, isAlternative, isNullable, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImmutableNarrowingBean

public ImmutableNarrowingBean(Bean<Object> delegate,
                              String name,
                              Set<Annotation> qualifiers,
                              Class<? extends Annotation> scope,
                              Set<Class<? extends Annotation>> stereotypes,
                              Set<Type> types,
                              boolean alternative,
                              boolean nullable,
                              String toString)
Instantiate a new ImmutableNarrowingBean.

Parameters:
delegate - the bean to delegate the lifecycle to
name - the name of the bean
qualifiers - the qualifiers of the bean
scope - the scope of the bean
stereotypes - the bean's stereotypes
types - the types of the bean
alternative - whether the bean is an alternative
Method Detail

create

public T create(CreationalContext<T> creationalContext)

destroy

public void destroy(T instance,
                    CreationalContext<T> creationalContext)


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