org.apache.cocoon.core.container.handler
Class AbstractComponentHandler

java.lang.Object
  extended byorg.apache.cocoon.core.container.handler.AbstractComponentHandler
All Implemented Interfaces:
ComponentHandler
Direct Known Subclasses:
AbstractFactoryHandler, AliasComponentHandler, InstanceComponentHandler

public abstract class AbstractComponentHandler
extends Object
implements ComponentHandler

This class acts like a Factory to instantiate the correct version of the component handler that you need.

Since:
2.2
Version:
$Id: AbstractComponentHandler.java 312637 2005-10-10 13:00:42Z cziegeler $

Field Summary
protected  boolean disposed
          State management boolean stating whether the Handler is disposed or not
protected  Logger logger
           
 
Constructor Summary
AbstractComponentHandler(ComponentInfo info, Logger logger)
          Creates a new ComponentHandler.
 
Method Summary
 boolean canBeDisposed()
          Returns true if this component handler can safely be disposed (i.e. none of the components it is handling are still being used).
 void dispose()
          Dispose of the component handler and any associated Pools and Factories.
protected abstract  Object doGet()
          Concrete implementation of getting a component.
protected abstract  void doInitialize()
           
protected abstract  void doPut(Object component)
          Concrete implementation of putting back a component.
 Object get()
          Get an instance of the type of component handled by this handler.
static ComponentHandler getComponentHandler(Class clazz, Logger logger, Context context, ServiceManager manager, Configuration config)
          Create a component handler (version used by XSP) TODO - perhaps we can remove this later?
static ComponentHandler getComponentHandler(String role, ComponentEnvironment componentEnv, ComponentInfo info)
          Looks up and returns a component handler for a given component class.
 ComponentInfo getInfo()
          Get the service metadata for this handler
 void initialize()
          Initialize this handler
 boolean isSingleton()
          Default here is to return false
 void put(Object component)
          Put back an instance of the type of component handled by this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Logger logger

disposed

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

Constructor Detail

AbstractComponentHandler

public AbstractComponentHandler(ComponentInfo info,
                                Logger logger)
Creates a new ComponentHandler.

Method Detail

getComponentHandler

public static ComponentHandler getComponentHandler(String role,
                                                   ComponentEnvironment componentEnv,
                                                   ComponentInfo info)
                                            throws Exception
Looks up and returns a component handler for a given component class.

Parameters:
role - the component's role. Can be null if the role isn't known.
componentEnv - The component's creation environment.
info - The description of the component (configuration, lifecycle etc.)
Throws:
Exception - If there were any problems obtaining a ComponentHandler

getInfo

public ComponentInfo getInfo()
Description copied from interface: ComponentHandler
Get the service metadata for this handler

Specified by:
getInfo in interface ComponentHandler

get

public final Object get()
                 throws Exception
Get an instance of the type of component handled by this handler.

Subclasses should not extend this method but rather the doGet method below otherwise reference counts will not be supported.

Specified by:
get in interface ComponentHandler
Returns:
an instance
Throws:
Exception - if an error occurs

put

public final void put(Object component)
               throws Exception
Put back an instance of the type of component handled by this handler.

Subclasses should not extend this method but rather the doPut method below otherwise reference counts will not be supported.

Specified by:
put in interface ComponentHandler
Parameters:
component - a service
Throws:
Exception - if an error occurs

doGet

protected abstract Object doGet()
                         throws Exception
Concrete implementation of getting a component.

Returns:
a service
Throws:
Exception - if an error occurs

doPut

protected abstract void doPut(Object component)
                       throws Exception
Concrete implementation of putting back a component.

Parameters:
component - a Component value
Throws:
Exception - if an error occurs

isSingleton

public boolean isSingleton()
Default here is to return false

Specified by:
isSingleton in interface ComponentHandler
Returns:
true if managed object is a singleton

canBeDisposed

public final boolean canBeDisposed()
Returns true if this component handler can safely be disposed (i.e. none of the components it is handling are still being used).

Specified by:
canBeDisposed in interface ComponentHandler
Returns:
true if this component handler can safely be disposed; false otherwise

dispose

public void dispose()
Description copied from interface: ComponentHandler
Dispose of the component handler and any associated Pools and Factories.

Specified by:
dispose in interface ComponentHandler

initialize

public final void initialize()
                      throws Exception
Description copied from interface: ComponentHandler
Initialize this handler

Specified by:
initialize in interface ComponentHandler
Throws:
Exception

doInitialize

protected abstract void doInitialize()
                              throws Exception
Throws:
Exception

getComponentHandler

public static ComponentHandler getComponentHandler(Class clazz,
                                                   Logger logger,
                                                   Context context,
                                                   ServiceManager manager,
                                                   Configuration config)
                                            throws Exception
Create a component handler (version used by XSP) TODO - perhaps we can remove this later?

Throws:
Exception


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.