Class CatalogBase<C extends Context>

java.lang.Object
org.apache.commons.chain.impl.CatalogBase<C>
Type Parameters:
C - Type of the context associated with this catalog
All Implemented Interfaces:
Catalog<C>

public class CatalogBase<C extends Context> extends Object implements Catalog<C>
Simple in-memory implementation of Catalog. This class can also be used as the basis for more advanced implementations.

This implementation is thread-safe.

Version:
$Revision$ $Date$
Author:
Craig R. McClanahan, Matthew J. Sgarlata
  • Constructor Details

    • CatalogBase

      public CatalogBase()
      Create an empty catalog.
    • CatalogBase

      public CatalogBase(Map<String,Command<C>> commands)
      Create a catalog whose commands are those specified in the given Map. All Map keys should be String and all values should be Command.
      Parameters:
      commands - Map of Commands.
      Since:
      Chain 1.1
  • Method Details

    • addCommand

      public <CMD extends Command<C>> void addCommand(String name, CMD command)
      Add a new name and associated Command to the set of named commands known to this Catalog, replacing any previous command for that name.
      Specified by:
      addCommand in interface Catalog<C extends Context>
      Type Parameters:
      CMD - the Command type to be added in the Catalog
      Parameters:
      name - Name of the new command
      command - Command to be returned for later lookups on this name
    • getCommand

      public <CMD extends Command<C>> CMD getCommand(String name)
      Return the Command associated with the specified name, if any; otherwise, return null.
      Specified by:
      getCommand in interface Catalog<C extends Context>
      Type Parameters:
      CMD - the expected Command type to be returned
      Parameters:
      name - Name for which a Command should be retrieved
      Returns:
      The Command associated with the specified name.
    • getNames

      Return an Iterator over the set of named commands known to this Catalog. If there are no known commands, an empty Iterator is returned.
      Specified by:
      getNames in interface Catalog<C extends Context>
      Returns:
      An iterator of the names in this Catalog.
    • toString

      public String toString()
      Converts this Catalog to a String. Useful for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a representation of this catalog as a String