anthill.factory
Class Factory

java.lang.Object
  |
  +--anthill.factory.Factory

public class Factory
extends java.lang.Object

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.


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(java.lang.String configURL)
          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
 java.lang.Object get(java.lang.Class cl)
          The get method is used to obtain an instantiation of a class implementing the requested interface.
 java.lang.Object get(java.lang.String iface)
          The get method is used to obtain an instantiation of a class implementing the requested interface.
 int getVersion(java.lang.Class cl)
          Check the version of the class, argument pair stored in the factory database under the key iface.
 int getVersion(java.lang.String iface)
          Check the version of the class, argument pair stored in the factory database under the key iface.
 void put(java.lang.String iface, java.lang.String clazz, java.lang.Object[] args)
          Method used to insert or update an interface mapping in the factory database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Factory

public Factory(java.lang.String configURL)
        throws ConfigFormatException,
               java.io.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 provide URL for the configuration file location.
Parameters:
configURL - A URL pointing to the configuration file to parse.

Factory

public Factory()
        throws ConfigFormatException,
               java.io.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.
Method Detail

get

public java.lang.Object get(java.lang.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 java.lang.Object get(java.lang.String iface)
                     throws ConfigFormatException,
                            ConstructorException
The get method is used to obtain an instantiation of a class implementing the requested interface.
Parameters:
iface - The interface name 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

getVersion

public int getVersion(java.lang.Class cl)
Check the version of the class, argument pair stored in the factory database under the key iface.
Parameters:
cl - The interface to check the current version of.

getVersion

public int getVersion(java.lang.String iface)
Check the version of the class, argument pair stored in the factory database under the key iface.
Parameters:
iface - The interface to check the current version of.

put

public void put(java.lang.String iface,
                java.lang.String clazz,
                java.lang.Object[] args)
Method used to insert or update an interface mapping in the factory database.
Parameters:
iface - The interface name used as mapping key.
clazz - The class name implementing the above interface.
args - Array of arguments used for instantiating the above class.