org.apache.turbine.services
Class BaseInitableBroker

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitableBroker
All Implemented Interfaces:
InitableBroker

public abstract class BaseInitableBroker
extends java.lang.Object
implements InitableBroker

A generic implementation of InitableBroker. Functionality provided by the broker includes:

Version:
$Id: BaseInitableBroker.java 534527 2007-05-02 16:10:59Z tv $
Author:
Kevin Burton, Rafal Krzewski, Henning P. Schmiedehausen

Field Summary
protected  java.util.Hashtable initables
          A repository of Initable instances.
protected  java.util.Stack stack
          Names of classes being early-initialized are pushed onto this stack.
 
Constructor Summary
protected BaseInitableBroker()
          Default constructor of InitableBroker.
 
Method Summary
 Initable getInitable(java.lang.String className)
          Provides an instance of Initable class ready to work.
protected  Initable getInitableInstance(java.lang.String className)
          Retrieves an instance of an Initable from the repository.
 void initClass(java.lang.String className, java.lang.Object data)
          Performs early initialization of an Initable class.
 void shutdownClass(java.lang.String className)
          Shuts down an Initable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initables

protected java.util.Hashtable initables
A repository of Initable instances.


stack

protected java.util.Stack stack
Names of classes being early-initialized are pushed onto this stack. A name appearing twice indicates a circular dependency chain.

Constructor Detail

BaseInitableBroker

protected BaseInitableBroker()
Default constructor of InitableBroker. This constructor does nothing. Your brokers should be singletons, therefore their constructors should be private. They should also have public YourBroker getInstance() methods.

Method Detail

initClass

public void initClass(java.lang.String className,
                      java.lang.Object data)
               throws InitializationException
Performs early initialization of an Initable class.

Specified by:
initClass in interface InitableBroker
Parameters:
className - The name of the class to be initialized.
data - An Object to be used for initialization activities.
Throws:
InitializationException - Initialization was not successful.

shutdownClass

public void shutdownClass(java.lang.String className)
Shuts down an Initable. This method is used to release resources allocated by an Initable, and return it to its initial (uninitailized) state.

Specified by:
shutdownClass in interface InitableBroker
Parameters:
className - The name of the class to be uninitialized.

getInitable

public Initable getInitable(java.lang.String className)
                     throws InstantiationException
Provides an instance of Initable class ready to work. If the requested class couldn't be instatiated or initialized, an InstantiationException will be thrown. You needn't handle this exception in your code, since it indicates fatal misconfigurtion of the system.

Specified by:
getInitable in interface InitableBroker
Parameters:
className - The name of the Initable requested.
Returns:
An instance of the requested Initable.
Throws:
InstantiationException - if there was a problem during instantiation or initialization of the Initable.

getInitableInstance

protected Initable getInitableInstance(java.lang.String className)
                                throws InstantiationException
Retrieves an instance of an Initable from the repository. If the requested class is not present in the repository, it is instantiated and passed a reference to the broker, saved and then returned.

Parameters:
className - The name of the class to be instantiated.
Throws:
InstantiationException - if the requested class can't be instantiated.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.