org.apache.commons.chain
Class CatalogFactory

java.lang.Object
  extended by org.apache.commons.chain.CatalogFactory
Direct Known Subclasses:
CatalogFactoryBase

public abstract class CatalogFactory
extends java.lang.Object

A CatalogFactory is a class used to store and retrieve Catalogs. The factory allows for a default Catalog as well as Catalogs stored with a name key. Follows the Factory pattern (see GoF).

Version:
$Revision: 1.5 $ $Date: 2004/11/30 05:52:22 $
Author:
Sean Schofield

Field Summary
private static java.util.Map factories
          The set of registered CatalogFactory instances, keyed by the relevant class loader.
 
Constructor Summary
CatalogFactory()
           
 
Method Summary
abstract  void addCatalog(java.lang.String name, Catalog catalog)
          Adds a named instance of Catalog to the factory (for subsequent retrieval later).
static void clear()
          Clear all references to registered catalogs, as well as to the relevant class loader.
abstract  Catalog getCatalog()
          Gets the default instance of Catalog associated with the factory (if any); otherwise, return null.
abstract  Catalog getCatalog(java.lang.String name)
          Retrieves a Catalog instance by name (if any); otherwise return null.
private static java.lang.ClassLoader getClassLoader()
          Return the relevant ClassLoader to use as a Map key for this request.
static CatalogFactory getInstance()
          Return the singleton CatalogFactory instance for the relevant ClassLoader.
abstract  java.util.Iterator getNames()
          Return an Iterator over the set of named Catalogs known to this CatalogFactory.
abstract  void setCatalog(Catalog catalog)
          Sets the default instance of Catalog associated with the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factories

private static java.util.Map factories

The set of registered CatalogFactory instances, keyed by the relevant class loader.

Constructor Detail

CatalogFactory

public CatalogFactory()
Method Detail

getCatalog

public abstract Catalog getCatalog()

Gets the default instance of Catalog associated with the factory (if any); otherwise, return null.

Returns:
the default Catalog instance

setCatalog

public abstract void setCatalog(Catalog catalog)

Sets the default instance of Catalog associated with the factory.

Parameters:
catalog - the default Catalog instance

getCatalog

public abstract Catalog getCatalog(java.lang.String name)

Retrieves a Catalog instance by name (if any); otherwise return null.

Parameters:
name - the name of the Catalog to retrieve
Returns:
the specified Catalog

addCatalog

public abstract void addCatalog(java.lang.String name,
                                Catalog catalog)

Adds a named instance of Catalog to the factory (for subsequent retrieval later).

Parameters:
name - the name of the Catalog to add
catalog - the Catalog to add

getNames

public abstract java.util.Iterator getNames()

Return an Iterator over the set of named Catalogs known to this CatalogFactory. If there are no known catalogs, an empty Iterator is returned.


getInstance

public static CatalogFactory getInstance()

Return the singleton CatalogFactory instance for the relevant ClassLoader. For applications that use a thread context class loader (such as web applications running inside a servet container), this will return a separate instance for each application, even if this class is loaded from a shared parent class loader.

Returns:
the per-application singleton instance of CatalogFactory

clear

public static void clear()

Clear all references to registered catalogs, as well as to the relevant class loader. This method should be called, for example, when a web application utilizing this class is removed from service, to allow for garbage collection.


getClassLoader

private static java.lang.ClassLoader getClassLoader()

Return the relevant ClassLoader to use as a Map key for this request. If there is a thread context class loader, return that; otherwise, return the class loader that loaded this class.