ProgramixGenericLib v5.0.1

com.programix.command
Class CommandProcessorFactory

java.lang.Object
  extended by com.programix.command.CommandProcessorFactory

public class CommandProcessorFactory
extends Object

Used to construct and initialize instances of CommandProcessor using reflection.

Common usage is (where CustomerCommandProcessor is an interface that extends the CommandProcessor interface):

 ValueMap config = //...
 CustomerCommandProcessor ccp = (CustomerCommandProcessor)
     CommandProcessorFactory.create(config, CustomerCommandProcessor.class);
or
 String filename = //...
 CustomerCommandProcessor cda = (CustomerCommandProcessor)
     CommandProcessorFactory.create(filename, CustomerCommandProcessor.class);
The configuration ValueMap passed in must contain the class name of the class to be instantiated stored under the key COMMAND_PROCESSOR_CLASSNAME_KEY. Other key/value pairs in the map are populated with whatever the specific CommandProcessor implementation needs for initialization.

Author:
Paul Hyde

Field Summary
static String COMMAND_PROCESSOR_CLASSNAME_KEY
          The reserved key that retrieves the fully-qualified name (as a String) of the CommandProcessor implementation class that will be instantiated via reflection.
 
Method Summary
static
<T extends CommandProcessor>
T
create(File file, Class<T> targetType)
          Create a CommandProcessor instance using an File whose data is in the format described by ValueMap (nearly identical to the format for a Properties file).
static
<T extends CommandProcessor>
T
create(InputStream rawIn, Class<T> targetType)
          Create a CommandProcessor instance using an InputStream whose data is in the format described by ValueMap (nearly identical to the format for a Properties file).
static
<T extends CommandProcessor>
T
create(Reader rawIn, Class<T> targetType)
          Create a CommandProcessor instance using a Reader whose data is in the format described by ValueMap (nearly identical to the format for a Properties file).
static
<T extends CommandProcessor>
T
create(URL propertiesURL, Class<T> targetType)
          Create a CommandProcessor instance using the specified URL whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).
static
<T extends CommandProcessor>
T
create(ValueMap config, Class<T> targetType)
          Constructs an instance of the CommandProcessor implementation specified in the configuration.
static
<T extends CommandProcessor>
T
createFromFile(String filename, Class<T> targetType)
          Create a CommandProcessor instance using the specified filename whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).
static
<T extends CommandProcessor>
T
createFromResource(String resourceLocation, Class<T> targetType)
          Create a CommandProcessor instance using the specified resourceLocation whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMAND_PROCESSOR_CLASSNAME_KEY

public static final String COMMAND_PROCESSOR_CLASSNAME_KEY
The reserved key that retrieves the fully-qualified name (as a String) of the CommandProcessor implementation class that will be instantiated via reflection.

The value of this key is always:

 command.processor.classname
 

See Also:
Constant Field Values
Method Detail

create

public static <T extends CommandProcessor> T create(ValueMap config,
                                                    Class<T> targetType)
                                         throws CommandException
Constructs an instance of the CommandProcessor implementation specified in the configuration. One required key that must always be present is: COMMAND_PROCESSOR_CLASSNAME_KEY with a String value which is the full class name.

Immediately after the zero-argument constructor is invoked, the init(ValueMap conf) of CommandProcessor is invoked to initialize the configuration.

If the targetType is not null, then an additional check is done to ensure that the constructed object can be type cast into that type (failures throw a CommandException instead of a ClassCastException).

Parameters:
config - key/value mapping with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(Reader, Class), create(InputStream, Class), createFromFile(String, Class), create(File, Class), create(URL, Class)

create

public static <T extends CommandProcessor> T create(Reader rawIn,
                                                    Class<T> targetType)
                                         throws CommandException
Create a CommandProcessor instance using a Reader whose data is in the format described by ValueMap (nearly identical to the format for a Properties file). Internally, the stream will be buffered and the stream will be closed.

Parameters:
rawIn - a stream whose contents can be loaded into a ValueMap with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(InputStream, Class), createFromFile(String, Class), create(File, Class), create(URL, Class)

create

public static <T extends CommandProcessor> T create(InputStream rawIn,
                                                    Class<T> targetType)
                                         throws CommandException
Create a CommandProcessor instance using an InputStream whose data is in the format described by ValueMap (nearly identical to the format for a Properties file). Internally, the stream will be buffered and the stream will be closed.

Parameters:
rawIn - a stream whose contents can be loaded into a ValueMap with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(Reader, Class), createFromFile(String, Class), create(File, Class), create(URL, Class)

create

public static <T extends CommandProcessor> T create(File file,
                                                    Class<T> targetType)
                                         throws CommandException
Create a CommandProcessor instance using an File whose data is in the format described by ValueMap (nearly identical to the format for a Properties file).

Parameters:
file - file with key/value mapping with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(Reader, Class), create(InputStream, Class), createFromFile(String, Class), create(URL, Class)

createFromFile

public static <T extends CommandProcessor> T createFromFile(String filename,
                                                            Class<T> targetType)
                                                 throws CommandException
Create a CommandProcessor instance using the specified filename whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).

Parameters:
filename - file with key/value mapping with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(Reader, Class), create(InputStream, Class), create(File, Class), create(URL, Class)

create

public static <T extends CommandProcessor> T create(URL propertiesURL,
                                                    Class<T> targetType)
                                         throws CommandException
Create a CommandProcessor instance using the specified URL whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).

Parameters:
propertiesURL - a URL whose contents can be loaded into a ValueMap with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(Reader, Class), create(InputStream, Class), createFromFile(String, Class), create(File, Class), createFromResource(String, Class)

createFromResource

public static <T extends CommandProcessor> T createFromResource(String resourceLocation,
                                                                Class<T> targetType)
                                                     throws CommandException
Create a CommandProcessor instance using the specified resourceLocation whose data is in the format described by ValueMap(nearly identical to the format for a Properties file).

Parameters:
resourceLocation - file with key/value mapping with everything that is needed to initialize the instance of CommandProcessor.
targetType - the class type that this instance is expected to be cast into. Use null to skip this check. If not null and the type does not match what is constructed, then a CommandException is thrown.
Returns:
the constructed and initialized instance.
Throws:
CommandException - if instance can not be constructed and initialized.
See Also:
create(ValueMap, Class), create(Reader, Class), create(InputStream, Class), create(File, Class), createFromFile(String, Class), create(URL, Class)

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.