org.apache.myfaces.extensions.cdi.core.api.provider
Class BeanManagerProvider

java.lang.Object
  extended by org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider
All Implemented Interfaces:
javax.enterprise.inject.spi.Extension

public class BeanManagerProvider
extends Object
implements javax.enterprise.inject.spi.Extension

This class provides access to the BeanManager by registring the current BeanManager in an extension and making it available via a singleton factory

This is really handy if you like to access CDI functionality from places where no injection is available.

Usage:

 BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
 


Constructor Summary
BeanManagerProvider()
           
 
Method Summary
 javax.enterprise.inject.spi.BeanManager getBeanManager()
          The active BeanManager for the current ClassLoader
<T> T
getContextualReference(Class<T> type, Annotation... qualifiers)
          Get a Contextual Reference by it's type and annotation.
<T> T
getContextualReference(Class<T> type, String name)
          Get a Contextual Reference by it's EL Name.
static BeanManagerProvider getInstance()
          Singleton accessor
static boolean isActive()
          Returns if the BeanManagerProvider has been initialized
 void setBeanManager(javax.enterprise.inject.spi.AfterBeanDiscovery afterBeanDiscovery, javax.enterprise.inject.spi.BeanManager beanManager)
          It basiscally doesn't matter which of the system events we use, but basically we
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanManagerProvider

public BeanManagerProvider()
Method Detail

isActive

public static boolean isActive()
Returns if the BeanManagerProvider has been initialized

Returns:
true if the bean-manager-provider is ready to be used

getInstance

public static BeanManagerProvider getInstance()
Singleton accessor

Returns:
the singleton BeanManagerProvider

getBeanManager

public javax.enterprise.inject.spi.BeanManager getBeanManager()
The active BeanManager for the current ClassLoader

Returns:
the current bean-manager

getContextualReference

public <T> T getContextualReference(Class<T> type,
                                    Annotation... qualifiers)
Get a Contextual Reference by it's type and annotation. You can use this method

Type Parameters:
T - target type
Parameters:
type - the type of the bean in question
qualifiers - additional qualifiers which further distinct the resolved bean
Returns:
the resolved Contextual Reference

getContextualReference

public <T> T getContextualReference(Class<T> type,
                                    String name)
Get a Contextual Reference by it's EL Name. This only works for beans with the @Named annotation.

Type Parameters:
T - target type
Parameters:
type - the type of the bean in question - only use Object.class if the type is unknown in dyn. use-cases
name - the EL name of the bean
Returns:
the resolved Contextual Reference

setBeanManager

public void setBeanManager(@Observes
                           javax.enterprise.inject.spi.AfterBeanDiscovery afterBeanDiscovery,
                           javax.enterprise.inject.spi.BeanManager beanManager)
It basiscally doesn't matter which of the system events we use, but basically we

Parameters:
afterBeanDiscovery - event which we don't actually use ;)
beanManager - the BeanManager we store and make available.


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.