org.apache.avalon.fortress.impl.handler
Class AbstractComponentHandler

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
          extended byorg.apache.avalon.fortress.impl.handler.AbstractComponentHandler
All Implemented Interfaces:
ComponentHandler, Disposable, Initializable, Instrumentable, LogEnabled, Serviceable
Direct Known Subclasses:
FactoryComponentHandler, PerThreadComponentHandler, PoolableComponentHandler, ThreadSafeComponentHandler

public abstract class AbstractComponentHandler
extends AbstractLogEnabledInstrumentable
implements Serviceable, Initializable, Disposable, ComponentHandler

AbstractComponentHandler class, ensures components are initialized and destroyed correctly.

Since:
4.0
Version:
CVS $Revision: 1.19 $ $Date: 2004/03/13 13:56:51 $
Author:
Avalon Development Team

Field Summary
protected  boolean m_disposed
          State management boolean stating whether the Handler is disposed or not
protected  org.d_haven.mpool.ObjectFactory m_factory
          The instance of the ComponentFactory that creates and disposes of the Component
protected  Logger m_logger
          Logger for factory
protected  LoggerManager m_loggerManager
          Logger Manager
protected  boolean m_prepared
          State management boolean stating whether the Handler is initialized or not
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
AbstractComponentHandler()
           
 
Method Summary
 void dispose()
          Dispose of the ComponentHandler and any associated Pools and Factories.
protected  void disposeComponent(java.lang.Object component)
          Dispose of the specified component.
protected  void doDispose()
          Dispose handler specific resources.
protected abstract  java.lang.Object doGet()
          Subclasses should actually overide this to do the work of retrieving a service.
protected  void doPrepare()
          Initialize the ComponentHandler.
protected  void doPut(java.lang.Object component)
          Subclasses should overide this to return component to handler.
 java.lang.Object get()
          Get a reference of the desired Component
 java.lang.Class getComponentClass()
          Return the component's class that this handler is trying to create.
 void initialize()
          Initialize the component.
protected  java.lang.Object newComponent()
          Create a new component for handler.
 void prepareHandler()
          Actually prepare the handler and make it ready to handle component access.
 void put(java.lang.Object component)
          Return a reference of the desired Component
 void service(ServiceManager manager)
          Pass the ServiceManager to the Serviceable.
 java.lang.String toString()
          Represents the handler as a string.
 
Methods inherited from class org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
addChildInstrumentable, addInstrument, getChildInstrumentables, getInstrumentableName, getInstruments, setInstrumentableName
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_factory

protected org.d_haven.mpool.ObjectFactory m_factory
The instance of the ComponentFactory that creates and disposes of the Component


m_prepared

protected boolean m_prepared
State management boolean stating whether the Handler is initialized or not


m_disposed

protected boolean m_disposed
State management boolean stating whether the Handler is disposed or not


m_logger

protected Logger m_logger
Logger for factory


m_loggerManager

protected LoggerManager m_loggerManager
Logger Manager

Constructor Detail

AbstractComponentHandler

public AbstractComponentHandler()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Description copied from interface: Serviceable
Pass the ServiceManager to the Serviceable. The Serviceable implementation should use the specified ServiceManager to acquire the components it needs for execution.

Specified by:
service in interface Serviceable
Parameters:
manager - The ServiceManager which this Serviceable uses. Must not be null.
Throws:
ServiceException - if an error occurs

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: Initializable
Initialize the component. Initialization includes allocating any resources required throughout the component's lifecycle.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - if an error occurs

getComponentClass

public java.lang.Class getComponentClass()
Return the component's class that this handler is trying to create. Used for deubug information.

Specified by:
getComponentClass in interface ComponentHandler
Returns:
the Class object for the component

prepareHandler

public void prepareHandler()
                    throws java.lang.Exception
Actually prepare the handler and make it ready to handle component access.

Specified by:
prepareHandler in interface ComponentHandler
Throws:
java.lang.Exception - if unable to prepare handler

doPrepare

protected void doPrepare()
                  throws java.lang.Exception
Initialize the ComponentHandler. Subclasses should overide this to do their own initialization.

Throws:
java.lang.Exception - if there is a problem

get

public java.lang.Object get()
                     throws java.lang.Exception
Get a reference of the desired Component

Specified by:
get in interface ComponentHandler
Returns:
the component
Throws:
java.lang.Exception - if unable to ge tthe compoennt reference

doGet

protected abstract java.lang.Object doGet()
                                   throws java.lang.Exception
Subclasses should actually overide this to do the work of retrieving a service.

Returns:
the service
Throws:
java.lang.Exception - if unable to aquire service

put

public void put(java.lang.Object component)
Return a reference of the desired Component

Specified by:
put in interface ComponentHandler
Parameters:
component - the component

doPut

protected void doPut(java.lang.Object component)
Subclasses should overide this to return component to handler.

Parameters:
component - the component

newComponent

protected java.lang.Object newComponent()
                                 throws java.lang.Exception
Create a new component for handler.

Returns:
the new component
Throws:
java.lang.Exception - if unable to create new component

disposeComponent

protected void disposeComponent(java.lang.Object component)
Dispose of the specified component.

Parameters:
component - the component

dispose

public void dispose()
Dispose of the ComponentHandler and any associated Pools and Factories.

Specified by:
dispose in interface Disposable

doDispose

protected void doDispose()
Dispose handler specific resources. Subclasses should overide this to provide their own funcitonality.


toString

public java.lang.String toString()
Represents the handler as a string.

Returns:
the string representation of the handler


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.