org.apache.catalina.core
Class ContainerBase

java.lang.Object
  |
  +--org.apache.catalina.core.ContainerBase
All Implemented Interfaces:
Container, Lifecycle, Pipeline
Direct Known Subclasses:
StandardContext, StandardEngine, StandardHost, StandardWrapper

public abstract class ContainerBase
extends java.lang.Object
implements Container, Lifecycle, Pipeline

Abstract implementation of the Container interface, providing common functionality required by nearly every implementation. Classes extending this base class must implement getInfo(), and may implement a replacement for invoke().

If a subclass prefers to use the default version of invoke() with pipeline support, it should instantiate a Valve instance containing the default behavior desired, and assign it with setBasic() in a constructor. In that way, any and all configured Valves added to the pipeline will preceed the basic Valve.

This implementation fires property change events, per the JavaBeans design pattern, for changes in singleton properties. In addition, it fires the following ContainerEvent events to listeners who register themselves with addContainerListener():
Type Data Description
addChild Container Child container added to this Container.
addValve Valve Valve added to this Container.
removeChild Container Child container removed from this Container.
removeValve Valve Valve removed from this Container.
start null Container was started.
stop null Container was stopped.
Subclasses that fire additional events should document them in the class comments of the implementation class.

Version:
$Revision: 1.4 $ $Date: 2000/09/30 19:15:45 $
Author:
Craig R. McClanahan

Field Summary
protected  Valve basic
          The Valve that implements the basic behavior of this Container, if any.
protected  java.util.HashMap children
          The child Containers belonging to this Container, keyed by name.
protected  int debug
          The debugging detail level for this component.
protected  Valve first
          The first Valve in the pipeline associated with this Container.
protected  LifecycleSupport lifecycle
          The lifecycle event support for this component.
protected  java.util.ArrayList listeners
          The container event listeners for this Container.
protected  Loader loader
          The Loader implementation with which this Container is associated.
protected  Logger logger
          The Logger implementation with which this Container is associated.
protected  Manager manager
          The Manager implementation with which this Container is associated.
protected  Mapper mapper
          The one and only Mapper associated with this Container, if any.
protected  java.lang.String mapperClass
          The Java class name of the default Mapper class for this Container.
protected  java.util.HashMap mappers
          The set of Mappers associated with this Container, keyed by protocol.
protected  java.lang.String name
          The human-readable name of this Container.
protected  Container parent
          The parent Container to which this Container is a child.
protected  Realm realm
          The Realm with which this Container is associated.
protected  Resources resources
          The Resources object with which this Container is associated.
protected static StringManager sm
          The string manager for this package.
protected  boolean started
          Has this component been started?
protected  java.beans.PropertyChangeSupport support
          The property change support for this component.
 
Fields inherited from interface org.apache.catalina.Container
ADD_CHILD_EVENT, ADD_MAPPER_EVENT, ADD_VALVE_EVENT, REMOVE_CHILD_EVENT, REMOVE_MAPPER_EVENT, REMOVE_VALVE_EVENT
 
Fields inherited from interface org.apache.catalina.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
ContainerBase()
           
 
Method Summary
 void addChild(Container child)
          Add a new child Container to those associated with this Container, if supported.
 void addContainerListener(ContainerListener listener)
          Add a container event listener to this component.
protected  void addDefaultMapper(java.lang.String mapperClass)
          Add a default Mapper implementation if none have been configured explicitly.
 void addLifecycleListener(LifecycleListener listener)
          Add a lifecycle event listener to this component.
 void addMapper(Mapper mapper)
          Add the specified Mapper associated with this Container.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a property change listener to this component.
 void addValve(Valve valve)
          Add a new Valve to the end of the pipeline associated with this Container.
 Container findChild(java.lang.String name)
          Return the child Container, associated with this Container, with the specified name (if any); otherwise, return null
 Container[] findChildren()
          Return the set of children Containers associated with this Container.
 Mapper findMapper(java.lang.String protocol)
          Return the Mapper associated with the specified protocol, if there is one.
 Mapper[] findMappers()
          Return the set of Mappers associated with this Container.
 Valve findValves()
          Return the first Valve in the pipeline associated with this Container.
protected  void fireContainerEvent(java.lang.String type, java.lang.Object data)
          Notify all container event listeners that a particular event has occurred for this Container.
 Valve getBasic()
          Return the Valve that provides the basic functionality for this Container, if any.
 int getDebug()
          Return the debugging detail level for this component.
abstract  java.lang.String getInfo()
          Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.
 Valve getLast()
          Return the last configured Valve (other than the basic Valve, if any) configured in the pipeline for this Container, if any; otherwise return null.
 Loader getLoader()
          Return the Loader with which this Container is associated.
 Logger getLogger()
          Return the Logger with which this Container is associated.
 Manager getManager()
          Return the Manager with which this Container is associated.
 java.lang.String getName()
          Return a name string (suitable for use by humans) that describes this Container.
 Container getParent()
          Return the Container for which this Container is a child, if there is one.
 java.lang.ClassLoader getParentClassLoader()
          Return the parent class loader (if any) for this web application.
 Realm getRealm()
          Return the Realm with which this Container is associated.
 Resources getResources()
          Return the Resources with which this Container is associated.
 void invoke(Request request, Response response)
          Process the specified Request, to produce the corresponding Response, by invoking the first Valve in our pipeline (if any), or the basic Valve otherwise.
protected  void log(java.lang.String message)
          Log the specified message to our current Logger (if any).
protected  void log(java.lang.String message, java.lang.Throwable throwable)
          Log the specified message and exception to our current Logger (if any).
protected  java.lang.String logName()
          Return the abbreviated name of this container for logging messsages
 Container map(Request request, boolean update)
          Return the child Container that should be used to process this Request, based upon its characteristics.
 void removeChild(Container child)
          Remove an existing child Container from association with this parent Container.
 void removeContainerListener(ContainerListener listener)
          Remove a container event listener from this component.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a lifecycle event listener from this component.
 void removeMapper(Mapper mapper)
          Remove a Mapper associated with this Container, if any.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a property change listener from this component.
 void removeValve(Valve valve)
          Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing.
 void setBasic(Valve valve)
          Set the Valve that provides the basic functionality for this Container, if any.
 void setDebug(int debug)
          Set the debugging detail level for this component.
 void setLoader(Loader loader)
          Set the Loader with which this Container is associated.
 void setLogger(Logger logger)
          Set the Logger with which this Container is associated.
 void setManager(Manager manager)
          Set the Manager with which this Container is associated.
 void setName(java.lang.String name)
          Set a name string (suitable for use by humans) that describes this Container.
 void setParent(Container container)
          Set the parent Container to which this Container is being added as a child.
 void setParentClassLoader(java.lang.ClassLoader parent)
          Set the parent class loader (if any) for this web application.
 void setRealm(Realm realm)
          Set the Realm with which this Container is associated.
 void setResources(Resources resources)
          Set the Resources object with which this Container is associated.
 void start()
          Prepare for active use of the public methods of this Component.
 void stop()
          Gracefully shut down active use of the public methods of this Component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

basic

protected Valve basic
The Valve that implements the basic behavior of this Container, if any.

children

protected java.util.HashMap children
The child Containers belonging to this Container, keyed by name.

debug

protected int debug
The debugging detail level for this component.

first

protected Valve first
The first Valve in the pipeline associated with this Container.

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.

listeners

protected java.util.ArrayList listeners
The container event listeners for this Container.

loader

protected Loader loader
The Loader implementation with which this Container is associated.

logger

protected Logger logger
The Logger implementation with which this Container is associated.

manager

protected Manager manager
The Manager implementation with which this Container is associated.

mapper

protected Mapper mapper
The one and only Mapper associated with this Container, if any.

mappers

protected java.util.HashMap mappers
The set of Mappers associated with this Container, keyed by protocol.

mapperClass

protected java.lang.String mapperClass
The Java class name of the default Mapper class for this Container.

name

protected java.lang.String name
The human-readable name of this Container.

parent

protected Container parent
The parent Container to which this Container is a child.

realm

protected Realm realm
The Realm with which this Container is associated.

resources

protected Resources resources
The Resources object with which this Container is associated.

sm

protected static StringManager sm
The string manager for this package.

started

protected boolean started
Has this component been started?

support

protected java.beans.PropertyChangeSupport support
The property change support for this component.
Constructor Detail

ContainerBase

public ContainerBase()
Method Detail

getBasic

public Valve getBasic()
Return the Valve that provides the basic functionality for this Container, if any.

setBasic

public void setBasic(Valve valve)
Set the Valve that provides the basic functionality for this Container, if any.
Parameters:
valve - The new basic Valve

getDebug

public int getDebug()
Return the debugging detail level for this component.

setDebug

public void setDebug(int debug)
Set the debugging detail level for this component.
Parameters:
debug - The new debugging detail level

getInfo

public abstract java.lang.String getInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.
Specified by:
getInfo in interface Container

getLast

public Valve getLast()
Return the last configured Valve (other than the basic Valve, if any) configured in the pipeline for this Container, if any; otherwise return null.

getLoader

public Loader getLoader()
Return the Loader with which this Container is associated. If there is no associated Loader, return the Loader associated with our parent Container (if any); otherwise, return null.
Specified by:
getLoader in interface Container

setLoader

public void setLoader(Loader loader)
Set the Loader with which this Container is associated.
Specified by:
setLoader in interface Container
Parameters:
loader - The newly associated loader

getLogger

public Logger getLogger()
Return the Logger with which this Container is associated. If there is no associated Logger, return the Logger associated with our parent Container (if any); otherwise return null.
Specified by:
getLogger in interface Container

setLogger

public void setLogger(Logger logger)
Set the Logger with which this Container is associated.
Specified by:
setLogger in interface Container
Parameters:
logger - The newly associated Logger

getManager

public Manager getManager()
Return the Manager with which this Container is associated. If there is no associated Manager, return the Manager associated with our parent Container (if any); otherwise return null.
Specified by:
getManager in interface Container

setManager

public void setManager(Manager manager)
Set the Manager with which this Container is associated.
Specified by:
setManager in interface Container
Parameters:
manager - The newly associated Manager

getName

public java.lang.String getName()
Return a name string (suitable for use by humans) that describes this Container. Within the set of child containers belonging to a particular parent, Container names must be unique.
Specified by:
getName in interface Container

setName

public void setName(java.lang.String name)
Set a name string (suitable for use by humans) that describes this Container. Within the set of child containers belonging to a particular parent, Container names must be unique.
Specified by:
setName in interface Container
Parameters:
name - New name of this container
Throws:
IllegalStateException - if this Container has already been added to the children of a parent Container (after which the name may not be changed)

getParent

public Container getParent()
Return the Container for which this Container is a child, if there is one. If there is no defined parent, return null.
Specified by:
getParent in interface Container

setParent

public void setParent(Container container)
Set the parent Container to which this Container is being added as a child. This Container may refuse to become attached to the specified Container by throwing an exception.
Specified by:
setParent in interface Container
Parameters:
container - Container to which this Container is being added as a child
Throws:
java.lang.IllegalArgumentException - if this Container refuses to become attached to the specified Container

getParentClassLoader

public java.lang.ClassLoader getParentClassLoader()
Return the parent class loader (if any) for this web application. This call is meaningful only after a Loader has been configured.
Specified by:
getParentClassLoader in interface Container

setParentClassLoader

public void setParentClassLoader(java.lang.ClassLoader parent)
Set the parent class loader (if any) for this web application. This call is meaningful only before a Loader has been configured, and the specified value (if non-null) should be passed as an argument to the class loader constructor.
Specified by:
setParentClassLoader in interface Container
Parameters:
parent - The new parent class loader

getRealm

public Realm getRealm()
Return the Realm with which this Container is associated. If there is no associated Realm, return the Realm associated with our parent Container (if any); otherwise return null.
Specified by:
getRealm in interface Container

setRealm

public void setRealm(Realm realm)
Set the Realm with which this Container is associated.
Specified by:
setRealm in interface Container
Parameters:
realm - The newly associated Realm

getResources

public Resources getResources()
Return the Resources with which this Container is associated. If there is no associated Resources object, return the Resources associated with our parent Container (if any); otherwise return null.
Specified by:
getResources in interface Container

setResources

public void setResources(Resources resources)
Set the Resources object with which this Container is associated.
Specified by:
setResources in interface Container
Parameters:
resources - The newly associated Resources

addChild

public void addChild(Container child)
Add a new child Container to those associated with this Container, if supported. Prior to adding this Container to the set of children, the child's setParent() method must be called, with this Container as an argument. This method may thrown an IllegalArgumentException if this Container chooses not to be attached to the specified Container, in which case it is not added
Specified by:
addChild in interface Container
Parameters:
child - New child Container to be added
Throws:
java.lang.IllegalArgumentException - if this exception is thrown by the setParent() method of the child Container
java.lang.IllegalArgumentException - if the new child does not have a name unique from that of existing children of this Container
IllegalStateException - if this Container does not support child Containers

addContainerListener

public void addContainerListener(ContainerListener listener)
Add a container event listener to this component.
Specified by:
addContainerListener in interface Container
Parameters:
listener - The listener to add

addMapper

public void addMapper(Mapper mapper)
Add the specified Mapper associated with this Container.
Specified by:
addMapper in interface Container
Parameters:
mapper - The corresponding Mapper implementation
Throws:
java.lang.IllegalArgumentException - if this exception is thrown by the setContainer() method of the Mapper

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.
Specified by:
addPropertyChangeListener in interface Container
Parameters:
listener - The listener to add

findChild

public Container findChild(java.lang.String name)
Return the child Container, associated with this Container, with the specified name (if any); otherwise, return null
Specified by:
findChild in interface Container
Parameters:
name - Name of the child Container to be retrieved

findChildren

public Container[] findChildren()
Return the set of children Containers associated with this Container. If this Container has no children, a zero-length array is returned.
Specified by:
findChildren in interface Container

findMapper

public Mapper findMapper(java.lang.String protocol)
Return the Mapper associated with the specified protocol, if there is one. If there is only one defined Mapper, use it for all protocols. If there is no matching Mapper, return null.
Specified by:
findMapper in interface Container
Parameters:
protocol - Protocol for which to find a Mapper

findMappers

public Mapper[] findMappers()
Return the set of Mappers associated with this Container. If this Container has no Mappers, a zero-length array is returned.
Specified by:
findMappers in interface Container

invoke

public void invoke(Request request,
                   Response response)
            throws java.io.IOException,
                   javax.servlet.ServletException
Process the specified Request, to produce the corresponding Response, by invoking the first Valve in our pipeline (if any), or the basic Valve otherwise.
Specified by:
invoke in interface Container
Parameters:
request - Request to be processed
response - Response to be produced
Throws:
IllegalStateException - if neither a pipeline or a basic Valve have been configured for this Container
java.io.IOException - if an input/output error occurred while processing
javax.servlet.ServletException - if a ServletException was thrown while processing this request

map

public Container map(Request request,
                     boolean update)
Return the child Container that should be used to process this Request, based upon its characteristics. If no such child Container can be identified, return null instead.
Specified by:
map in interface Container
Parameters:
request - Request being processed
update - Update the Request to reflect the mapping selection?

removeChild

public void removeChild(Container child)
Remove an existing child Container from association with this parent Container.
Specified by:
removeChild in interface Container
Parameters:
child - Existing child Container to be removed

removeContainerListener

public void removeContainerListener(ContainerListener listener)
Remove a container event listener from this component.
Specified by:
removeContainerListener in interface Container
Parameters:
listener - The listener to remove

removeMapper

public void removeMapper(Mapper mapper)
Remove a Mapper associated with this Container, if any.
Specified by:
removeMapper in interface Container
Parameters:
mapper - The Mapper to be removed

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.
Specified by:
removePropertyChangeListener in interface Container
Parameters:
listener - The listener to remove

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
Specified by:
addLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to add

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
Specified by:
removeLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to remove

start

public void start()
           throws LifecycleException
Prepare for active use of the public methods of this Component.
Specified by:
start in interface Lifecycle
Throws:
IllegalStateException - if this component has already been started
LifecycleException - if this component detects a fatal error that prevents it from being started

stop

public void stop()
          throws LifecycleException
Gracefully shut down active use of the public methods of this Component.
Specified by:
stop in interface Lifecycle
Throws:
IllegalStateException - if this component has not been started
LifecycleException - if this component detects a fatal error that needs to be reported

addValve

public void addValve(Valve valve)
Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the Valve, the Valve's setContainer method must be called, with this Container as an argument. The method may throw an IllegalArgumentException if this Valve chooses not to be associated with this Container, or IllegalStateException if it is already associated with a different Container.
Specified by:
addValve in interface Pipeline
Parameters:
valve - Valve to be added
Throws:
java.lang.IllegalArgumentException - if this Container refused to accept the specified Valve
java.lang.IllegalArgumentException - if the specifie Valve refuses to be associated with this Container
IllegalStateException - if the specified Valve is already associated with a different Container

findValves

public Valve findValves()
Return the first Valve in the pipeline associated with this Container. If there are no such Valves, null is returned.
Specified by:
findValves in interface Pipeline

removeValve

public void removeValve(Valve valve)
Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing.
Specified by:
removeValve in interface Pipeline
Parameters:
valve - Valve to be removed

addDefaultMapper

protected void addDefaultMapper(java.lang.String mapperClass)
Add a default Mapper implementation if none have been configured explicitly.
Parameters:
mapperClass - Java class name of the default Mapper

fireContainerEvent

protected void fireContainerEvent(java.lang.String type,
                                  java.lang.Object data)
Notify all container event listeners that a particular event has occurred for this Container. The default implementation performs this notification synchronously using the calling thread.
Parameters:
type - Event type
data - Event data

log

protected void log(java.lang.String message)
Log the specified message to our current Logger (if any).
Parameters:
message - Message to be logged

log

protected void log(java.lang.String message,
                   java.lang.Throwable throwable)
Log the specified message and exception to our current Logger (if any).
Parameters:
message - Message to be logged
throwable - Related exception

logName

protected java.lang.String logName()
Return the abbreviated name of this container for logging messsages


Copyright © 2000 Apache Software Foundation. All Rights Reserved.