org.beanlet
Class BeanletApplicationContext

java.lang.Object
  extended by org.beanlet.BeanletApplicationContext

public abstract class BeanletApplicationContext
extends Object

Bootstrap class for the application container. An instance of the BeanletApplicationContext can be obtained through the static instance method. If the container isn't already running, the first call to this method automatically starts and initializes the container.

During initialization, the container registers the beanlets listed in all the beanlet.xml and META-INF/beanlet.xml files that are available from the container's classpath.

The beanlet application context providess access to all registered beanlets. All methods of this class are thread-safe. They can be called at all time. That includes during initialization of the application container.


Constructor Summary
BeanletApplicationContext()
           
 
Method Summary
abstract  boolean exists(String beanletName)
          Returns true if a beanlet exists for the specified beanletName.
abstract  Object getBeanlet(String beanletName)
          Returns a beanlet instance for the specified beanletName.
abstract
<T> T
getBeanlet(String beanletName, Class<T> requiredType)
          Returns a beanlet instance for the specified beanletName.
abstract
<T> T
getBeanlet(String beanletName, Class<T> requiredType, Map<String,?> info)
          Returns a BeanletFactory for the specified beanletName.
abstract  Object getBeanlet(String beanletName, Map<String,?> info)
          Returns a beanlet for the specified beanletName.
abstract  BeanletFactory<?> getBeanletFactory(String beanletName)
          Returns a BeanletFactory for the specified beanletName, or throws a BeanletNotFoundException if beanlet does not exist.
abstract
<T> BeanletFactory<? extends T>
getBeanletFactory(String beanletName, Class<T> requiredType)
          Returns a BeanletFactory for the specified beanletName.
abstract  Set<String> getBeanletNames()
          Returns an immutable set of beanlet names of all registered beanlets.
abstract  Set<String> getBeanletNamesForType(Class<?> type)
          Returns an immutable set of beanlet names of all registered beanlets, which the beanlet instance type is the same as, or a subclass of the specified type.
abstract  Set<String> getBeanletNamesForType(Class<?> type, boolean factoryAware, boolean usePrefix)
          Returns an immutable set of beanlet names of all registered beanlets, which the beanlet instance type is the same as, or a subclass of the specified type.
abstract
<T extends Event>
T
getEvent(Class<T> eventType)
          Factory method for the specified eventType.
static BeanletApplicationContext instance()
          Returns a BeanletApplicationContext instance.
static void main(String... args)
          Bootstraps the Beanlet container by obtaining a BeanletApplicationContext instance.
protected  BeanletApplicationContext resolveInstance()
          Subclasses of this class can implement this method to control which instance is returned to the caller of the static instance method.
abstract  void shutdown()
          Undeploys all components and stops all internal container threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanletApplicationContext

public BeanletApplicationContext()
Method Detail

main

public static void main(String... args)
Bootstraps the Beanlet container by obtaining a BeanletApplicationContext instance.

Parameters:
args - no arguments required.

instance

public static BeanletApplicationContext instance()
                                          throws BeanletApplicationException

Returns a BeanletApplicationContext instance. If the container isn't already running, the first call to this method automatically starts and initializes the container.

It is not specified whether multiple calls to this method results in a single or multiple instances of the BeanletApplicationContext. However, as the container only starts once, invoking this method multiple times is valid and does not consume any additional resources.

Returns:
a BeanletApplicationContext instance.
Throws:
BeanletApplicationException - indicates an error during container initialization.

resolveInstance

protected BeanletApplicationContext resolveInstance()
                                             throws BeanletApplicationException
Subclasses of this class can implement this method to control which instance is returned to the caller of the static instance method. The default implementation of this method simply returns this.

Returns:
a beanlet application context reference.
Throws:
BeanletApplicationException - indicates an error during container initialization.

shutdown

public abstract void shutdown()
                       throws BeanletApplicationException
Undeploys all components and stops all internal container threads.

Throws:
BeanletApplicationContext - indicates an error during container shutdown.
BeanletApplicationException

getEvent

public abstract <T extends Event> T getEvent(Class<T> eventType)
Factory method for the specified eventType.

Returns:
a concrete implementation of the specified eventType.

getBeanlet

public abstract Object getBeanlet(String beanletName)
                           throws BeanletNotFoundException,
                                  BeanletCreationException

Returns a beanlet instance for the specified beanletName.

If his beanlet instance implements the FactoryBeanlet interface, the result of FactoryBeanlet.getObject() is returned. Prefix the beanletName with "&" to obtain an instance to the FactoryBeanlet itself.

Parameters:
beanletName - name of the beanlet.
Returns:
a beanlet.
Throws:
BeanletNotFoundException - if beanlet does not exist.
BeanletCreationException - if beanlet could not be created for any reason.

getBeanlet

public abstract <T> T getBeanlet(String beanletName,
                                 Class<T> requiredType)
                      throws BeanletNotFoundException,
                             BeanletCreationException,
                             BeanletNotOfRequiredTypeException

Returns a beanlet instance for the specified beanletName. If no beanlet exists for the specied beanletName a BeanletNotFoundException is thrown. A BeanletNotOfRequiredTypeException is thrown if the beanlet instance cannot be assigned to the requiredType.

If his beanlet instance implements the FactoryBeanlet interface, the result of FactoryBeanlet.getObject() is returned. Prefix the beanletName with "&" to obtain an instance to the FactoryBeanlet itself.

The entries of the info argument can be used to wire members of the beanlet instance. This does not apply to singleton and stateless beanlets.

Parameters:
beanletName - name of the beanlet.
requiredType - type to mached the beanlet type.
Returns:
a beanlet.
Throws:
BeanletNotFoundException - if beanlet does not exist.
BeanletCreationException - if beanlet could not be created for any reason.
BeanletNotOfRequiredTypeException - if beanlet cannot be assigned to the requiredType.
See Also:
Inject, Wiring

getBeanlet

public abstract Object getBeanlet(String beanletName,
                                  Map<String,?> info)
                           throws BeanletNotFoundException,
                                  BeanletCreationException

Returns a beanlet for the specified beanletName.

If this beanlet implements the FactoryBeanlet interface, the result of FactoryBeanlet.getObject() is returned. Prefix the beanletName with "&" to obtain an instance to the FactoryBeanlet itself.

The entries of the info argument can be used to wire members of the beanlet instance. This does not apply to static beanlets.

Parameters:
beanletName - name of the beanlet.
info - map that contains parameters that can be injected into the beanlet instance.
Returns:
a beanlet.
Throws:
BeanletNotFoundException - if beanlet does not exist.
BeanletCreationException - if beanlet could not be created for any reason.
See Also:
Inject, Wiring

getBeanlet

public abstract <T> T getBeanlet(String beanletName,
                                 Class<T> requiredType,
                                 Map<String,?> info)
                      throws BeanletNotFoundException,
                             BeanletCreationException,
                             BeanletNotOfRequiredTypeException

Returns a BeanletFactory for the specified beanletName. If no beanlet exists for the specified beanletName a BeanletNotFoundException is thrown. If the beanlet definition type is either the same as, or a subclass of the specified requiredType, a generified BeanletFactory is returned with the requiredType as upper bound.

This method ignores the "&" prefix.

The entries of the info argument can be used to wire members of the beanlet instance. This does not apply to static beanlets.

Parameters:
beanletName - name of the beanlet.
requiredType - type to mached the beanlet type.
info - map that contains parameters that can be injected into the beanlet instance.
Returns:
a BeanletFactory for the specified beanletName.
Throws:
BeanletNotFoundException - if beanlet does not exist.
BeanletCreationException - if beanlet could not be created for any reason.
BeanletNotOfRequiredTypeException - if beanlet cannot be assigned to the requiredType.
See Also:
Inject, Wiring

getBeanletNames

public abstract Set<String> getBeanletNames()
Returns an immutable set of beanlet names of all registered beanlets.


getBeanletNamesForType

public abstract Set<String> getBeanletNamesForType(Class<?> type)
Returns an immutable set of beanlet names of all registered beanlets, which the beanlet instance type is the same as, or a subclass of the specified type.

Parameters:
type - type to mached the beanlet type.

getBeanletNamesForType

public abstract Set<String> getBeanletNamesForType(Class<?> type,
                                                   boolean factoryAware,
                                                   boolean usePrefix)
Returns an immutable set of beanlet names of all registered beanlets, which the beanlet instance type is the same as, or a subclass of the specified type. Additionally, beanlet factories, which return type match the specified type can be added as well, if factoryAware is set to true. Set usePrefix to true if these beanlet names must be prepended with "&".

Parameters:
type - type to mached the beanlet type, or factory beanlet return type (optional).
factoryAware - specify true to include factory beanlets, which return type match the given type.
usePrefix - specify true to prefix factory beanlet names.

getBeanletFactory

public abstract BeanletFactory<?> getBeanletFactory(String beanletName)
                                             throws BeanletNotFoundException

Returns a BeanletFactory for the specified beanletName, or throws a BeanletNotFoundException if beanlet does not exist.

This method ignores the "&" prefix.

Parameters:
beanletName - name of the beanlet.
Returns:
a BeanletFactory for the specified beanletName.
Throws:
BeanletNotFoundException - if beanlet does not exist.

getBeanletFactory

public abstract <T> BeanletFactory<? extends T> getBeanletFactory(String beanletName,
                                                                  Class<T> requiredType)
                                                       throws BeanletNotFoundException,
                                                              BeanletNotOfRequiredTypeException

Returns a BeanletFactory for the specified beanletName. If no beanlet exists for the specified beanletName a BeanletNotFoundException is thrown. If the beanlet definition type is either the same as, or a subclass of the specified requiredType, a generified BeanletFactory is returned with the requiredType as upper bound.

This method ignores the "&" prefix.

Parameters:
beanletName - name of the beanlet.
requiredType - type to mached the beanlet type.
Returns:
a BeanletFactory for the specified beanletName.
Throws:
BeanletNotFoundException - if beanlet does not exist.
BeanletNotOfRequiredTypeException - if beanlet's type is not the same as, or a subtype of requiredType.

exists

public abstract boolean exists(String beanletName)

Returns true if a beanlet exists for the specified beanletName.

This method ignores the "&" prefix.

Parameters:
beanletName - name of the beanlet.
Returns:
true if beanlet exists, or false otherwise.


Copyright © 2006-2012. All Rights Reserved.