anthill.factory
Class Factory

java.lang.Object
  |
  +--anthill.factory.Factory
All Implemented Interfaces:
Serializable

public class Factory
extends Object
implements Serializable

A generic factory for creating object instances of a class matching a particular interface and possibly taking arguments. The mapping between an implementing class and an interface, and also the arguments to be used to instantiate the class are all read from a configuration file.

Version:
$Revision: 1.14 $
Author:
Hein Meling
See Also:
Serialized Form

Constructor Summary
Factory()
          Create a parser object and pass this factory object allowing the parser to place the parsed elements directly into the HashMap using the factory API method put.
Factory(String[] configURLs)
          Create a parser object and pass this factory object allowing the parser to place the parsed elements directly into the HashMap using the factory API method put.
 
Method Summary
 boolean booleanValue(String name)
          Method used to obtain the boolean value associated to a particular configuration parameter
 double doubleValue(String name)
          Method used to obtain the double value associated to a particular configuration parameter
 float floatValue(String name)
          Method used to obtain the double value associated to a particular configuration parameter
 Object get(Class cl)
          The get method is used to obtain an instantiation of a class implementing the requested interface.
 Object get(String name)
          The get method is used to obtain an instantiation of a class implementing the requested component.
 Object getValue(String name)
          Method used to obtain the value associated to a particular configuration parameter
 int intValue(String name)
          Method used to obtain the integer value associated to a particular configuration parameter
 void put(String name, String clazz)
          Method used to update the mapping between a component name and the class implementing it.
 void putValue(String name, double value)
          Method used to insert or update a double configuration value associated to a configuration name.
 void putValue(String name, float value)
          Method used to insert or update a double configuration value associated to a configuration name.
 void putValue(String name, int value)
          Method used to insert or update an integer configuration value associated to a configuration name.
 void putValue(String name, Object value)
          Method used to insert or update a configuration value associated to a configuration name.
 String stringValue(String name)
          Method used to obtain the String value associated to a particular configuration parameter
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Factory

public Factory(String[] configURLs)
        throws ConfigFormatException,
               IOException
Create a parser object and pass this factory object allowing the parser to place the parsed elements directly into the HashMap using the factory API method put. The parser will use the provided URLs for the configuration file location.

Parameters:
configURLs - An array of URLs pointing to the configuration files to parse.
Throws:
ConfigFormatException - Thrown when there is a problem parsing or validating the content of the system configuration file.
IOException - Thrown when one of the urls cannot be accessed due to an I/O problem.

Factory

public Factory()
        throws ConfigFormatException,
               IOException
Create a parser object and pass this factory object allowing the parser to place the parsed elements directly into the HashMap using the factory API method put. The parser will use the default configuration file location.

Throws:
ConfigFormatException - Thrown when there is a problem parsing or validating the content of the system configuration file.
IOException - Thrown when one of the urls cannot be accessed due to an I/O problem.
Method Detail

get

public Object get(Class cl)
           throws ConfigFormatException,
                  ConstructorException
The get method is used to obtain an instantiation of a class implementing the requested interface.

Parameters:
cl - The interface used as mapping key.
Returns:
An object instance implementing the specified interface.
Throws:
ConfigFormatException - Thrown if specified classes and interfaces cannot be found.
ConstructorException - Thrown if the constructor reflectively invoked by get raises an exception

get

public Object get(String name)
           throws ConfigFormatException,
                  ConstructorException
The get method is used to obtain an instantiation of a class implementing the requested component.

Parameters:
name - The name of the component used as a mapping key.
Returns:
An object instance implementing the specified component.
Throws:
ConfigFormatException - Thrown if specified classes cannot be found.
ConstructorException - Thrown if the constructor reflectively invoked raises an exception

put

public void put(String name,
                String clazz)
Method used to update the mapping between a component name and the class implementing it.

Parameters:
name - The interface name used as mapping key.
clazz - The class name implementing the above interface.

putValue

public void putValue(String name,
                     Object value)
Method used to insert or update a configuration value associated to a configuration name.

Parameters:
name - The name associated to the value.
value - The value to be inserted.

putValue

public void putValue(String name,
                     int value)
Method used to insert or update an integer configuration value associated to a configuration name.

Parameters:
name - The name associated to the value.
value - The value to be inserted.

putValue

public void putValue(String name,
                     double value)
Method used to insert or update a double configuration value associated to a configuration name.

Parameters:
name - The name associated to the value.
value - The value to be inserted.

putValue

public void putValue(String name,
                     float value)
Method used to insert or update a double configuration value associated to a configuration name.

Parameters:
name - The name associated to the value.
value - The value to be inserted.

getValue

public Object getValue(String name)
Method used to obtain the value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

stringValue

public String stringValue(String name)
Method used to obtain the String value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

booleanValue

public boolean booleanValue(String name)
Method used to obtain the boolean value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

intValue

public int intValue(String name)
Method used to obtain the integer value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

doubleValue

public double doubleValue(String name)
Method used to obtain the double value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

floatValue

public float floatValue(String name)
Method used to obtain the double value associated to a particular configuration parameter

Parameters:
name - The name identifying the configuration parameter

toString

public String toString()
Overrides:
toString in class Object