Errai 3.0.1-SNAPSHOT

org.jboss.errai.ioc.client.container
Class SyncBeanManagerImpl

java.lang.Object
  extended by org.jboss.errai.ioc.client.container.SyncBeanManagerImpl
All Implemented Interfaces:
ClientBeanManager, SyncBeanManager, SyncBeanManagerSetup

public class SyncBeanManagerImpl
extends Object
implements SyncBeanManager, SyncBeanManagerSetup

A simple bean manager provided by the Errai IOC framework. The manager provides access to all of the wired beans and their instances. Since the actual wiring code is generated, the bean manager is populated by the generated code at bootstrap time.

Author:
Mike Brock

Constructor Summary
SyncBeanManagerImpl()
           
 
Method Summary
 void addBean(Class<Object> type, Class<?> beanType, BeanProvider<Object> callback, Object instance, Annotation[] qualifiers)
          Register a bean with the manager.
 void addBean(Class<Object> type, Class<?> beanType, BeanProvider<Object> callback, Object instance, Annotation[] qualifiers, String name)
          Register a bean with the manager with a name.
 void addBean(Class<Object> type, Class<?> beanType, BeanProvider<Object> callback, Object instance, Annotation[] qualifiers, String name, boolean concreteType, Class<Object> beanActivatorType)
          Register a bean with the manager with a name as well as specifying whether the bean should be treated a concrete type.
 void addBeanToContext(Object ref, CreationalContext creationalContext)
          Associates a bean instance with a creational context.
 boolean addDestructionCallback(Object beanInstance, DestructionCallback<?> destructionCallback)
          Associates a DestructionCallback with a bean instance.
 void addProxyReference(Object proxyRef, Object realRef)
          Associates the reference to a proxied bean to the underlying bean instance which it is proxying.
 void destroyAllBeans()
          Destroy all beans currently managed by the bean manager.
 void destroyBean(Object ref)
          Destroy a bean and all other beans associated with its creational context in the bean manager.
 Object getActualBeanReference(Object ref)
          Obtains an instance to the actual bean.
 boolean isManaged(Object ref)
          Indicates whether the referenced object is currently a managed bean.
 boolean isProxyReference(Object ref)
          Determines whether the referenced object is itself a proxy to a managed bean.
<T> IOCBeanDef<T>
lookupBean(Class<T> type, Annotation... qualifiers)
          Looks up a bean reference based on type and qualifiers.
<T> Collection<IOCBeanDef<T>>
lookupBeans(Class<T> type)
          Looks up all beans of the specified type.
<T> Collection<IOCBeanDef<T>>
lookupBeans(Class<T> type, Annotation... qualifierInstances)
          Looks up a bean reference based on type and qualifiers.
 Collection<IOCBeanDef> lookupBeans(String name)
          Looks up all beans with the specified bean name as specified by Named.
<T> IOCBeanDef<T>
registerBean(IOCBeanDef<T> bean)
          Register a bean with the manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncBeanManagerImpl

public SyncBeanManagerImpl()
Method Detail

addBean

public void addBean(Class<Object> type,
                    Class<?> beanType,
                    BeanProvider<Object> callback,
                    Object instance,
                    Annotation[] qualifiers)
Description copied from interface: SyncBeanManagerSetup
Register a bean with the manager. This is usually called by the generated code to advertise the bean. Adding beans at runtime will make beans available for lookup through the BeanManager, but will not in any way alter the wiring scenario of auto-discovered beans at runtime.

Specified by:
addBean in interface SyncBeanManagerSetup
Parameters:
type - the bean type
beanType - the actual type of the bean
callback - the creational callback used to construct the bean
instance - the instance reference
qualifiers - any qualifiers

addBean

public void addBean(Class<Object> type,
                    Class<?> beanType,
                    BeanProvider<Object> callback,
                    Object instance,
                    Annotation[] qualifiers,
                    String name)
Description copied from interface: SyncBeanManagerSetup
Register a bean with the manager with a name. This is usually called by the generated code to advertise the bean. Adding beans at runtime will make beans available for lookup through the BeanManager, but will not in any way alter the wiring scenario of auto-discovered beans at runtime.

Specified by:
addBean in interface SyncBeanManagerSetup
Parameters:
type - the bean type
beanType - the actual type of the bean
callback - the creational callback used to construct the bean
instance - the instance reference
qualifiers - any qualifiers
name - the name of the bean

addBean

public void addBean(Class<Object> type,
                    Class<?> beanType,
                    BeanProvider<Object> callback,
                    Object instance,
                    Annotation[] qualifiers,
                    String name,
                    boolean concreteType,
                    Class<Object> beanActivatorType)
Description copied from interface: SyncBeanManagerSetup
Register a bean with the manager with a name as well as specifying whether the bean should be treated a concrete type. This is usually called by the generated code to advertise the bean. Adding beans at runtime will make beans available for lookup through the BeanManager, but will not in any way alter the wiring scenario of auto-discovered beans at runtime.

Specified by:
addBean in interface SyncBeanManagerSetup
Parameters:
type - the bean type
beanType - the actual type of the bean
callback - the creational callback used to construct the bean
instance - the instance reference
qualifiers - any qualifiers
name - the name of the bean
concreteType - true if bean should be treated as concrete (ie. not an interface or abstract type).

destroyBean

public void destroyBean(Object ref)
Description copied from interface: ClientBeanManager
Destroy a bean and all other beans associated with its creational context in the bean manager.

Specified by:
destroyBean in interface ClientBeanManager
Parameters:
ref - the instance reference of the bean

isManaged

public boolean isManaged(Object ref)
Description copied from interface: ClientBeanManager
Indicates whether the referenced object is currently a managed bean.

Specified by:
isManaged in interface ClientBeanManager
Parameters:
ref - the reference to the bean
Returns:
returns true if under management

getActualBeanReference

public Object getActualBeanReference(Object ref)
Description copied from interface: ClientBeanManager
Obtains an instance to the actual bean. If the specified reference is a proxy, this method will return an un-proxied reference to the object.

Specified by:
getActualBeanReference in interface ClientBeanManager
Parameters:
ref - the proxied or unproxied reference
Returns:
returns the absolute reference to bean if the specified reference is a proxy. If the specified reference is not a proxy, the same instance passed to the method is returned.
See Also:
ClientBeanManager.isProxyReference(Object)

isProxyReference

public boolean isProxyReference(Object ref)
Description copied from interface: ClientBeanManager
Determines whether the referenced object is itself a proxy to a managed bean.

Specified by:
isProxyReference in interface ClientBeanManager
Parameters:
ref - the reference to check
Returns:
returns true if the specified reference is itself a proxy.
See Also:
ClientBeanManager.getActualBeanReference(Object)

addProxyReference

public void addProxyReference(Object proxyRef,
                              Object realRef)
Description copied from interface: ClientBeanManager
Associates the reference to a proxied bean to the underlying bean instance which it is proxying.

Specified by:
addProxyReference in interface ClientBeanManager
Parameters:
proxyRef - the reference to the proxy
realRef - the reference to the bean being proxied.

addBeanToContext

public void addBeanToContext(Object ref,
                             CreationalContext creationalContext)
Description copied from interface: ClientBeanManager
Associates a bean instance with a creational context.

Specified by:
addBeanToContext in interface ClientBeanManager
Parameters:
ref - the reference to the bean
creationalContext - the CreationalContext instance to associate the bean instance with.

registerBean

public <T> IOCBeanDef<T> registerBean(IOCBeanDef<T> bean)
Description copied from interface: SyncBeanManager
Register a bean with the manager.

Specified by:
registerBean in interface SyncBeanManager
Parameters:
bean - an IOCSingletonBean reference

lookupBeans

public Collection<IOCBeanDef> lookupBeans(String name)
Description copied from interface: SyncBeanManager
Looks up all beans with the specified bean name as specified by Named.

Specified by:
lookupBeans in interface SyncBeanManager
Parameters:
name - the name of bean to lookup
Returns:
and unmodifiable list of all beans with the specified name.

lookupBeans

public <T> Collection<IOCBeanDef<T>> lookupBeans(Class<T> type)
Description copied from interface: SyncBeanManager
Looks up all beans of the specified type.

Specified by:
lookupBeans in interface SyncBeanManager
Parameters:
type - The type of the bean
Returns:
An unmodifiable list of all the beans that match the specified type. Returns an empty list if there is no matching type.

lookupBeans

public <T> Collection<IOCBeanDef<T>> lookupBeans(Class<T> type,
                                                 Annotation... qualifierInstances)
Description copied from interface: SyncBeanManager
Looks up a bean reference based on type and qualifiers. Returns null if there is no type associated with the specified

Specified by:
lookupBeans in interface SyncBeanManager
Parameters:
type - The type of the bean
qualifierInstances - qualifiers to match
Returns:
An unmodifiable list of all beans which match the specified type and qualifiers. Returns an empty list if no beans match.

lookupBean

public <T> IOCBeanDef<T> lookupBean(Class<T> type,
                                    Annotation... qualifiers)
Description copied from interface: SyncBeanManager
Looks up a bean reference based on type and qualifiers. Returns null if there is no type associated with the specified

Specified by:
lookupBean in interface SyncBeanManager
Type Parameters:
T - The type of the bean
Parameters:
type - The type of the bean
qualifiers - qualifiers to match
Returns:
An instance of the IOCSingletonBean for the matching type and qualifiers. Throws an IOCResolutionException if there is a matching type but none of the qualifiers match or if more than one bean matches.

addDestructionCallback

public boolean addDestructionCallback(Object beanInstance,
                                      DestructionCallback<?> destructionCallback)
Description copied from interface: ClientBeanManager
Associates a DestructionCallback with a bean instance. If the bean manager cannot find a valid CreationalContext to associate with the bean, or the bean is no longer considered active, the method returns false. Otherwise, the method returns true, indicating the callback is now registered and will be called when the bean is destroyed.

Specified by:
addDestructionCallback in interface ClientBeanManager
Parameters:
beanInstance - the bean instance to associate the callback to.
destructionCallback - the instance of the DestructionCallback.
Returns:
true if the DestructionCallback is successfully registered against a valid CreationalContext and false if not.

destroyAllBeans

public void destroyAllBeans()
Description copied from interface: ClientBeanManager
Destroy all beans currently managed by the bean manager. Don't do this.

Specified by:
destroyAllBeans in interface ClientBeanManager

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.