Class CatalogFactory
- java.lang.Object
-
- org.apache.commons.chain.CatalogFactory
-
- Direct Known Subclasses:
CatalogFactoryBase
public abstract class CatalogFactory extends java.lang.ObjectA
CatalogFactoryis a class used to store and retrieveCatalogs. The factory allows for a defaultCatalogas well asCatalogs stored with a name key. Follows the Factory pattern (see GoF).The base
CatalogFactoryimplementation also implements a resolution mechanism which allows lookup of a command based on a single String which encodes both the catalog and command names.- Version:
- $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
- Author:
- Sean Schofield
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDELIMITERValues passed to thegetCommand(String)method should use this as the delimiter between the "catalog" name and the "command" name.private static java.util.MapfactoriesThe set of registeredCatalogFactoryinstances, keyed by the relevant class loader.
-
Constructor Summary
Constructors Constructor Description CatalogFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddCatalog(java.lang.String name, Catalog catalog)Adds a named instance of Catalog to the factory (for subsequent retrieval later).static voidclear()Clear all references to registered catalogs, as well as to the relevant class loader.abstract CataloggetCatalog()Gets the default instance of Catalog associated with the factory (if any); otherwise, returnnull.abstract CataloggetCatalog(java.lang.String name)Retrieves a Catalog instance by name (if any); otherwise returnnull.private static java.lang.ClassLoadergetClassLoader()Return the relevantClassLoaderto use as a Map key for this request.CommandgetCommand(java.lang.String commandID)Return aCommandbased on the given commandID.static CatalogFactorygetInstance()Return the singletonCatalogFactoryinstance for the relevantClassLoader.abstract java.util.IteratorgetNames()abstract voidsetCatalog(Catalog catalog)Sets the default instance of Catalog associated with the factory.
-
-
-
Field Detail
-
DELIMITER
public static final java.lang.String DELIMITER
Values passed to the
getCommand(String)method should use this as the delimiter between the "catalog" name and the "command" name.- See Also:
- Constant Field Values
-
factories
private static java.util.Map factories
The set of registered
CatalogFactoryinstances, keyed by the relevant class loader.
-
-
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 addcatalog- the Catalog to add
-
getNames
public abstract java.util.Iterator getNames()
Return an
Iteratorover the set of namedCatalogs known to thisCatalogFactory. If there are no known catalogs, an empty Iterator is returned.- Returns:
- An Iterator of the names of the Catalogs known by this factory.
-
getCommand
public Command getCommand(java.lang.String commandID)
Return a
Commandbased on the given commandID.At this time, the structure of commandID is relatively simple: if the commandID contains a DELIMITER, treat the segment of the commandID up to (but not including) the DELIMITER as the name of a catalog, and the segment following the DELIMITER as a command name within that catalog. If the commandID contains no DELIMITER, treat the commandID as the name of a command in the default catalog.
To preserve the possibility of future extensions to this lookup mechanism, the DELIMITER string should be considered reserved, and should not be used in command names. commandID values which contain more than one DELIMITER will cause an
IllegalArgumentExceptionto be thrown.- Parameters:
commandID- the identifier of the command to return- Returns:
- the command located with commandID, or
nullif either the command name or the catalog name cannot be resolved - Throws:
java.lang.IllegalArgumentException- if the commandID contains more than one DELIMITER- Since:
- Chain 1.1
-
getInstance
public static CatalogFactory getInstance()
Return the singleton
CatalogFactoryinstance for the relevantClassLoader. 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
ClassLoaderto 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.
-
-