org.jboss.webbeans
Class ManagerImpl

java.lang.Object
  extended by org.jboss.webbeans.ManagerImpl
All Implemented Interfaces:
java.io.Serializable, Manager, WebBeansManager

public class ManagerImpl
extends java.lang.Object
implements WebBeansManager, java.io.Serializable

Implementation of the Web Beans Manager. Essentially a singleton for registering Beans, Contexts, Observers, Interceptors etc. as well as providing resolution

Author:
Pete Muir
See Also:
Serialized Form

Field Summary
static java.lang.String JNDI_KEY
           
 
Method Summary
 Manager addBean(Bean<?> bean)
          Registers a bean with the manager
 Manager addContext(Context context)
          Registers a context with the manager
 Manager addDecorator(Decorator decorator)
          Registers a decorator with the manager
 Manager addInterceptor(Interceptor interceptor)
          Registers an interceptor with the manager
<T> Manager
addObserver(Observer<T> observer, java.lang.Class<T> eventType, java.lang.annotation.Annotation... bindings)
          Register an observer with the container
<T> Manager
addObserver(Observer<T> observer, TypeLiteral<T> eventType, java.lang.annotation.Annotation... bindings)
          Register an observer with the container
<T> Manager
addObserver(ObserverImpl<T> observer)
          Shortcut to register an ObserverImpl
<T> Manager
addObserverByType(Observer<T> observer, java.lang.reflect.Type eventType, java.lang.annotation.Annotation... bindings)
          Does the actual observer registration
protected  void addWebBeansDeploymentTypes()
           
protected  void checkEnabledDeploymentTypes()
          Set up the enabled deployment types, if none are specified by the user, the default @Production and @Standard are used.
 ManagerImpl createActivity()
          Create a new child activity.
 void fireEvent(java.lang.Object event, java.lang.annotation.Annotation... bindings)
          Fires an event object with given event object for given bindings
<T> Bean<T>
getBeanByType(AnnotatedItem<T,?> element, java.lang.annotation.Annotation... bindings)
           
 java.util.List<Bean<?>> getBeans()
          The beans registered with the Web Bean manager.
protected  ClientProxyProvider getClientProxyProvider()
           
 Context getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
          Gets an active context of the given scope.
protected  ConcurrentListMultiMap<java.lang.Class<? extends java.lang.annotation.Annotation>,Context> getContexts()
           
 ManagerImpl getCurrent()
           
protected  java.util.Set<org.jboss.webbeans.ManagerImpl.CurrentActivity> getCurrentActivities()
           
 java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> getEnabledDeploymentTypes()
          A strongly ordered, unmodifiable list of enabled deployment types
 java.lang.Integer getId()
           
protected  java.util.concurrent.atomic.AtomicInteger getIds()
           
 InjectionPoint getInjectionPoint()
          Accesses the factory used to create each instance of InjectionPoint that is injected into web beans.
<T> T
getInstance(Bean<T> bean)
          Returns an instance of a bean
<T> T
getInstance(Bean<T> bean, boolean create)
           
 java.lang.Object getInstanceByName(java.lang.String name)
          Gets an instance by name, returning null if none is found and throwing an exception if too many beans match
<T> T
getInstanceByType(AnnotatedItem<T,?> element, java.lang.annotation.Annotation... bindings)
          Resolve an instance, verify that the resolved bean can be instantiated, and return
<T> T
getInstanceByType(java.lang.Class<T> type, java.lang.annotation.Annotation... bindings)
          Returns an instance by API type and binding types
<T> T
getInstanceByType(TypeLiteral<T> type, java.lang.annotation.Annotation... bindings)
          Returns an instance by type literal and binding types
<T> T
getInstanceToInject(InjectionPoint injectionPoint)
          Obtains an instance of bean for a given injection point.
<T> T
getInstanceToInject(InjectionPoint injectionPoint, CreationalContext<?> creationalContext)
          Obtains an instance of bean for a given injection point.
 java.util.Map<java.lang.Class<?>,EnterpriseBean<?>> getNewEnterpriseBeanMap()
          Gets the class-mapped beans.
 ConcurrentSetMultiMap<java.lang.reflect.Type,EventObserver<?>> getRegisteredObservers()
           
 Resolver getResolver()
          Get the web bean resolver.
 java.util.Map<java.lang.String,RIBean<?>> getRiBeans()
           
 Namespace getRootNamespace()
           
 ServiceRegistry getServices()
           
 java.util.Map<Bean<?>,Bean<?>> getSpecializedBeans()
           
 java.util.concurrent.ExecutorService getTaskExecutor()
          Provides access to the executor service used for asynchronous tasks.
 void injectNonContextualInstance(java.lang.Object instance)
          Perform JSR-299 dependency injection into a non-contextual instance
static ManagerImpl newChildManager(ManagerImpl parentManager)
          Create a new child manager
static ManagerImpl newRootManager(ServiceRegistry serviceRegistry)
          Create a new, root, manager
 Manager parse(java.io.InputStream xmlStream)
          Allows additional XML based to be provided.
protected  java.lang.Object readResolve()
           
protected  void registerBeanNamespace(Bean<?> bean)
           
<T> Manager
removeObserver(Observer<T> observer, java.lang.Class<T> eventType, java.lang.annotation.Annotation... bindings)
          Removes an observer
<T> Manager
removeObserver(Observer<T> observer, TypeLiteral<T> eventType, java.lang.annotation.Annotation... bindings)
          Removes an observer
 java.util.Set<Bean<?>> resolveByName(java.lang.String name)
          Resolves a set of beans based on their name
<T> java.util.Set<Bean<T>>
resolveByType(AnnotatedItem<T,?> element, java.lang.annotation.Annotation... bindings)
          Check the resolution request is valid, and then ask the resolver to perform the resolution.
<T> java.util.Set<Bean<T>>
resolveByType(AnnotatedItem<T,?> element, InjectionPoint injectionPoint, java.lang.annotation.Annotation... bindings)
           
<T> java.util.Set<Bean<T>>
resolveByType(java.lang.Class<T> type, java.lang.annotation.Annotation... bindings)
          Resolves beans by API type and binding types
<T> java.util.Set<Bean<T>>
resolveByType(TypeLiteral<T> type, java.lang.annotation.Annotation... bindings)
          Resolves beans by API type literal and binding types
 java.util.List<Decorator> resolveDecorators(java.util.Set<java.lang.reflect.Type> types, java.lang.annotation.Annotation... bindings)
          Resolves a list of decorators based on API types and binding types Os
<T> java.util.Set<DisposalMethodBean<T>>
resolveDisposalBeans(java.lang.Class<T> apiType, java.lang.annotation.Annotation... bindings)
          Resolve the disposal method for the given producer method.
 java.util.List<Interceptor> resolveInterceptors(InterceptionType type, java.lang.annotation.Annotation... interceptorBindings)
          Resolves a list of interceptors based on interception type and interceptor bindings
<T> java.util.Set<Observer<T>>
resolveObservers(T event, java.lang.annotation.Annotation... bindings)
          Resolves observers for given event and bindings
 void setBeans(java.util.Set<RIBean<?>> beans)
          Wraps a collection of beans into a thread safe list.
 ManagerImpl setCurrent(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
          Associate an activity with the current context for a normal scope
 void setEnabledDeploymentTypes(java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> enabledDeploymentTypes)
          Set the enabled deployment types
 void shutdown()
           
protected  void shutdownExecutors()
          Shuts down any executor services in the manager.
 java.lang.String toString()
          Gets a string representation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JNDI_KEY

public static final java.lang.String JNDI_KEY
See Also:
Constant Field Values
Method Detail

newRootManager

public static ManagerImpl newRootManager(ServiceRegistry serviceRegistry)
Create a new, root, manager

Parameters:
serviceRegistry -
Returns:

newChildManager

public static ManagerImpl newChildManager(ManagerImpl parentManager)
Create a new child manager

Parameters:
parentManager -
Returns:

checkEnabledDeploymentTypes

protected void checkEnabledDeploymentTypes()
Set up the enabled deployment types, if none are specified by the user, the default @Production and @Standard are used. For internal use.

Parameters:
enabledDeploymentTypes - The enabled deployment types from web-beans.xml

addWebBeansDeploymentTypes

protected void addWebBeansDeploymentTypes()

addBean

public Manager addBean(Bean<?> bean)
Registers a bean with the manager

Specified by:
addBean in interface Manager
Parameters:
bean - The bean to register
Returns:
A reference to manager
See Also:
Manager.addBean(javax.inject.manager.Bean)

resolveDisposalBeans

public <T> java.util.Set<DisposalMethodBean<T>> resolveDisposalBeans(java.lang.Class<T> apiType,
                                                                     java.lang.annotation.Annotation... bindings)
Resolve the disposal method for the given producer method. For internal use.

Parameters:
apiType - The API type to match
bindings - The binding types to match
Returns:
The set of matching disposal methods

resolveObservers

public <T> java.util.Set<Observer<T>> resolveObservers(T event,
                                                       java.lang.annotation.Annotation... bindings)
Resolves observers for given event and bindings

Specified by:
resolveObservers in interface Manager
Type Parameters:
T - the type of the event to obtain
Parameters:
event - The event to match
bindings - The binding types to match
Returns:
The set of matching observers
See Also:
Manager.resolveObservers(java.lang.Object, java.lang.annotation.Annotation[])

getEnabledDeploymentTypes

public java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> getEnabledDeploymentTypes()
A strongly ordered, unmodifiable list of enabled deployment types

Returns:
The ordered enabled deployment types known to the manager

setEnabledDeploymentTypes

public void setEnabledDeploymentTypes(java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> enabledDeploymentTypes)
Set the enabled deployment types

Parameters:
enabledDeploymentTypes -

resolveByType

public <T> java.util.Set<Bean<T>> resolveByType(java.lang.Class<T> type,
                                                java.lang.annotation.Annotation... bindings)
Resolves beans by API type and binding types

Specified by:
resolveByType in interface Manager
Type Parameters:
T - the type of the beans to be resolved
Parameters:
type - The API type to match
bindings - The binding types to match
Returns:
The set of matching beans
See Also:
Manager.resolveByType(java.lang.Class, java.lang.annotation.Annotation[])

resolveByType

public <T> java.util.Set<Bean<T>> resolveByType(TypeLiteral<T> type,
                                                java.lang.annotation.Annotation... bindings)
Resolves beans by API type literal and binding types

Specified by:
resolveByType in interface Manager
Type Parameters:
T - the type of the beans to be resolved
Parameters:
type - The API type literal to match
bindings - The binding types to match
Returns:
The set of matching beans
See Also:
Manager.resolveByType(javax.inject.TypeLiteral, java.lang.annotation.Annotation[])

resolveByType

public <T> java.util.Set<Bean<T>> resolveByType(AnnotatedItem<T,?> element,
                                                InjectionPoint injectionPoint,
                                                java.lang.annotation.Annotation... bindings)

resolveByType

public <T> java.util.Set<Bean<T>> resolveByType(AnnotatedItem<T,?> element,
                                                java.lang.annotation.Annotation... bindings)
Check the resolution request is valid, and then ask the resolver to perform the resolution. For internal use.

Parameters:
element - The item to resolve
bindings - The binding types to match
Returns:
The set of matching beans

setBeans

public void setBeans(java.util.Set<RIBean<?>> beans)
Wraps a collection of beans into a thread safe list. Since this overwrites any existing list of beans in the manager, this should only be done on startup and other controlled situations. Also maps the beans by implementation class. For internal use.

Parameters:
beans - The set of beans to add

registerBeanNamespace

protected void registerBeanNamespace(Bean<?> bean)

getNewEnterpriseBeanMap

public java.util.Map<java.lang.Class<?>,EnterpriseBean<?>> getNewEnterpriseBeanMap()
Gets the class-mapped beans. For internal use.

Returns:
The bean map

getBeans

public java.util.List<Bean<?>> getBeans()
The beans registered with the Web Bean manager. For internal use

Returns:
The list of known beans

getRiBeans

public java.util.Map<java.lang.String,RIBean<?>> getRiBeans()

addContext

public Manager addContext(Context context)
Registers a context with the manager

Specified by:
addContext in interface Manager
Parameters:
context - The context to add
Returns:
A reference to the manager
See Also:
Manager.addContext(javax.context.Context)

addDecorator

public Manager addDecorator(Decorator decorator)
Registers a decorator with the manager

Specified by:
addDecorator in interface Manager
Parameters:
decorator - The decorator to register
Returns:
A reference to the manager
See Also:
Manager.addDecorator(javax.inject.manager.Decorator)

addInterceptor

public Manager addInterceptor(Interceptor interceptor)
Registers an interceptor with the manager

Specified by:
addInterceptor in interface Manager
Parameters:
interceptor - The interceptor to register
Returns:
A reference to the manager
See Also:
Manager.addInterceptor(javax.inject.manager.Interceptor)

addObserver

public <T> Manager addObserver(Observer<T> observer,
                               java.lang.Class<T> eventType,
                               java.lang.annotation.Annotation... bindings)
Description copied from interface: Manager
Register an observer with the container

Specified by:
addObserver in interface Manager
Type Parameters:
T - the type of the observer
Parameters:
observer - the observer to register
eventType - the event type the observer observes
bindings - event bindings to further restrict the events observed
Returns:
the manager the observer was registered with

addObserver

public <T> Manager addObserver(ObserverImpl<T> observer)
Shortcut to register an ObserverImpl

Type Parameters:
T -
Parameters:
observer -
Returns:

addObserver

public <T> Manager addObserver(Observer<T> observer,
                               TypeLiteral<T> eventType,
                               java.lang.annotation.Annotation... bindings)
Description copied from interface: Manager
Register an observer with the container

Specified by:
addObserver in interface Manager
Type Parameters:
T - the type of the observer
Parameters:
observer - the observer to register
eventType - the event type the observer observes
bindings - event bindings to further restrict the events observed
Returns:
the manager the observer was registered with

addObserverByType

public <T> Manager addObserverByType(Observer<T> observer,
                                     java.lang.reflect.Type eventType,
                                     java.lang.annotation.Annotation... bindings)
Does the actual observer registration

Type Parameters:
T -
Parameters:
observer -
eventType -
bindings -
Returns:

fireEvent

public void fireEvent(java.lang.Object event,
                      java.lang.annotation.Annotation... bindings)
Fires an event object with given event object for given bindings

Specified by:
fireEvent in interface Manager
Parameters:
event - The event object to pass along
bindings - The binding types to match
See Also:
Manager.fireEvent(java.lang.Object, java.lang.annotation.Annotation[])

getContext

public Context getContext(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
Gets an active context of the given scope. Throws an exception if there are no active contexts found or if there are too many matches

Specified by:
getContext in interface Manager
Parameters:
scopeType - The scope to match
Returns:
A single active context of the given scope
See Also:
Manager.getContext(java.lang.Class)

getInstance

public <T> T getInstance(Bean<T> bean)
Returns an instance of a bean

Specified by:
getInstance in interface Manager
Type Parameters:
T - the type of the bean
Parameters:
bean - The bean to instantiate
Returns:
An instance of the bean
See Also:
Manager.getInstance(javax.inject.manager.Bean)

getInstance

public <T> T getInstance(Bean<T> bean,
                         boolean create)

getInstanceToInject

public <T> T getInstanceToInject(InjectionPoint injectionPoint)
Description copied from interface: Manager
Obtains an instance of bean for a given injection point. This method should not be called by an application.

Specified by:
getInstanceToInject in interface Manager
Type Parameters:
T - the type of the bean
Parameters:
injectionPoint - the injection point the instance is needed for
Returns:
an instance of the bean

injectNonContextualInstance

public void injectNonContextualInstance(java.lang.Object instance)
Description copied from interface: WebBeansManager
Perform JSR-299 dependency injection into a non-contextual instance

Specified by:
injectNonContextualInstance in interface WebBeansManager
Parameters:
instance - the instance to inject

getInstanceToInject

public <T> T getInstanceToInject(InjectionPoint injectionPoint,
                                 CreationalContext<?> creationalContext)
Description copied from interface: Manager
Obtains an instance of bean for a given injection point. This method should not be called by an application.

Specified by:
getInstanceToInject in interface Manager
Type Parameters:
T - the type of the bean
Parameters:
injectionPoint - the injection point the instance is needed for
creationalContext - the context in which the injection is occurring
Returns:
an instance of the bean

getInstanceByName

public java.lang.Object getInstanceByName(java.lang.String name)
Gets an instance by name, returning null if none is found and throwing an exception if too many beans match

Specified by:
getInstanceByName in interface Manager
Parameters:
name - The name to match
Returns:
An instance of the bean
See Also:
Manager.getInstanceByName(java.lang.String)

getInstanceByType

public <T> T getInstanceByType(java.lang.Class<T> type,
                               java.lang.annotation.Annotation... bindings)
Returns an instance by API type and binding types

Specified by:
getInstanceByType in interface Manager
Type Parameters:
T - the type of the bean to obtain
Parameters:
type - The API type to match
bindings - The binding types to match
Returns:
An instance of the bean
See Also:
Manager.getInstanceByType(java.lang.Class, java.lang.annotation.Annotation[])

getInstanceByType

public <T> T getInstanceByType(TypeLiteral<T> type,
                               java.lang.annotation.Annotation... bindings)
Returns an instance by type literal and binding types

Specified by:
getInstanceByType in interface Manager
Type Parameters:
T - the type of the bean to obtain
Parameters:
type - The type to match
bindings - The binding types to match
Returns:
An instance of the bean
See Also:
Manager.getInstanceByType(javax.inject.TypeLiteral, java.lang.annotation.Annotation[])

getInstanceByType

public <T> T getInstanceByType(AnnotatedItem<T,?> element,
                               java.lang.annotation.Annotation... bindings)
Resolve an instance, verify that the resolved bean can be instantiated, and return

Parameters:
element - The annotated item to match
bindings - The binding types to match
Returns:
An instance of the bean

getBeanByType

public <T> Bean<T> getBeanByType(AnnotatedItem<T,?> element,
                                 java.lang.annotation.Annotation... bindings)

removeObserver

public <T> Manager removeObserver(Observer<T> observer,
                                  java.lang.Class<T> eventType,
                                  java.lang.annotation.Annotation... bindings)
Removes an observer

Specified by:
removeObserver in interface Manager
Type Parameters:
T - the type of the observer
Parameters:
observer - The observer to remove
eventType - The event type to match
bindings - the binding types to match
Returns:
A reference to the manager
See Also:
Manager.removeObserver(javax.event.Observer, java.lang.Class, java.lang.annotation.Annotation[])

removeObserver

public <T> Manager removeObserver(Observer<T> observer,
                                  TypeLiteral<T> eventType,
                                  java.lang.annotation.Annotation... bindings)
Removes an observer

Specified by:
removeObserver in interface Manager
Type Parameters:
T - the type of the observer
Parameters:
observer - The observer to remove
eventType - The event type to match
bindings - the binding types to match
Returns:
A reference to the manager
See Also:
Manager.removeObserver(javax.event.Observer, javax.inject.TypeLiteral, java.lang.annotation.Annotation[])

resolveByName

public java.util.Set<Bean<?>> resolveByName(java.lang.String name)
Resolves a set of beans based on their name

Specified by:
resolveByName in interface Manager
Parameters:
The - name to match
Returns:
The set of matching beans
See Also:
Manager.resolveByName(java.lang.String)

resolveDecorators

public java.util.List<Decorator> resolveDecorators(java.util.Set<java.lang.reflect.Type> types,
                                                   java.lang.annotation.Annotation... bindings)
Resolves a list of decorators based on API types and binding types Os

Specified by:
resolveDecorators in interface Manager
Parameters:
types - The set of API types to match
bindings - The binding types to match
Returns:
A list of matching decorators
See Also:
Manager.resolveDecorators(java.util.Set, java.lang.annotation.Annotation[])

resolveInterceptors

public java.util.List<Interceptor> resolveInterceptors(InterceptionType type,
                                                       java.lang.annotation.Annotation... interceptorBindings)
Resolves a list of interceptors based on interception type and interceptor bindings

Specified by:
resolveInterceptors in interface Manager
Parameters:
type - The interception type to resolve
interceptorBindings - The binding types to match
Returns:
A list of matching interceptors
See Also:
Manager.resolveInterceptors(javax.inject.manager.InterceptionType, java.lang.annotation.Annotation[])

getResolver

public Resolver getResolver()
Get the web bean resolver. For internal use

Returns:
The resolver

toString

public java.lang.String toString()
Gets a string representation

Overrides:
toString in class java.lang.Object
Returns:
A string representation

parse

public Manager parse(java.io.InputStream xmlStream)
Description copied from interface: Manager
Allows additional XML based to be provided. This method may be called at any time in the applications lifecycle.

Specified by:
parse in interface Manager
Parameters:
xmlStream - the XML metadata
Returns:
the manager the XML metadata was registered with

createActivity

public ManagerImpl createActivity()
Description copied from interface: Manager
Create a new child activity. A child activity inherits all beans, interceptors, decorators, observers, and contexts defined by its direct and indirect parent activities. This method should not be called by the application.

Specified by:
createActivity in interface Manager
Returns:
the child activity

setCurrent

public ManagerImpl setCurrent(java.lang.Class<? extends java.lang.annotation.Annotation> scopeType)
Description copied from interface: Manager
Associate an activity with the current context for a normal scope

Specified by:
setCurrent in interface Manager
Parameters:
scopeType - the scope to associate the activity with
Returns:
the activity

getCurrent

public ManagerImpl getCurrent()

getServices

public ServiceRegistry getServices()

getInjectionPoint

public InjectionPoint getInjectionPoint()
Accesses the factory used to create each instance of InjectionPoint that is injected into web beans.

Returns:
the factory

getSpecializedBeans

public java.util.Map<Bean<?>,Bean<?>> getSpecializedBeans()
Returns:

readResolve

protected java.lang.Object readResolve()

getTaskExecutor

public java.util.concurrent.ExecutorService getTaskExecutor()
Provides access to the executor service used for asynchronous tasks.

Returns:
the ExecutorService for this manager

shutdown

public void shutdown()
Specified by:
shutdown in interface WebBeansManager

shutdownExecutors

protected void shutdownExecutors()
Shuts down any executor services in the manager.


getClientProxyProvider

protected ClientProxyProvider getClientProxyProvider()

getContexts

protected ConcurrentListMultiMap<java.lang.Class<? extends java.lang.annotation.Annotation>,Context> getContexts()

getIds

protected java.util.concurrent.atomic.AtomicInteger getIds()

getCurrentActivities

protected java.util.Set<org.jboss.webbeans.ManagerImpl.CurrentActivity> getCurrentActivities()

getId

public java.lang.Integer getId()

getRegisteredObservers

public ConcurrentSetMultiMap<java.lang.reflect.Type,EventObserver<?>> getRegisteredObservers()

getRootNamespace

public Namespace getRootNamespace()


Copyright © 2011. All Rights Reserved.