laser.util.argument
Class ClassParameter

java.lang.Object
  extended by laser.util.argument.Argument
      extended by laser.util.argument.Parameter
          extended by laser.util.argument.ClassParameter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ClassParameter
extends Parameter

The ClassParameter class defines a user-defined parameter of type Class.

Author:
Jamieson M. Cobleigh (laser-software@cs.umass.edu)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class laser.util.argument.Parameter
NOT_REPEATABLE_CHAR, REPEATABLE_CHAR
 
Fields inherited from class laser.util.argument.Argument
FIRST, HELP_DEFAULT, HELP_PREFIX, REPEATABLE_DEFAULT, TYPE_PREFIX, TYPE_SUFFIX
 
Constructor Summary
ClassParameter(java.lang.String name)
          Creates a new ClassParameter with a given name.
ClassParameter(java.lang.String name, java.lang.String helpMessage)
          Creates a new ClassParameter with a given name and helpMessage.
ClassParameter(java.lang.String name, java.lang.String helpMessage, java.lang.Class supertype)
          Creates a new ClassParameter with a given name, helpMessage, and supertype.
 
Method Summary
protected  void checkValue(java.lang.Object value)
          Checks to make sure the the given value is well-formed.
 java.lang.Object clone()
          Clones this Object.
protected  java.lang.Object fromStringValue(java.lang.String value)
          Parses a String value into an Object appropriate for the type
 java.lang.Object getClassInstance()
          Creates an instance of the class named in this parameter
 java.lang.Class getClassValue()
          Gets the value of this ClassOption
 java.lang.Class getClassValue(int i)
          Gets the i-th value of this ClassOption
 java.lang.Class getType()
          Gets the type of this Argument.
 void setValue(java.lang.Class value)
          Sets the value of this ClassOption to the specified value.
protected  java.lang.String toStringValue(java.lang.Object value)
          Returns the String value of the given Object value.
 
Methods inherited from class laser.util.argument.Parameter
check, getHelp, getRepeatableChar
 
Methods inherited from class laser.util.argument.Argument
clear, equals, getHelpMessage, getName, getValue, getValue, getValues, initialize, isRepeatable, numberOfActualValues, numberOfValues, parseValue, save, setValue, toString, toStringValue
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassParameter

public ClassParameter(java.lang.String name,
                      java.lang.String helpMessage,
                      java.lang.Class supertype)
Creates a new ClassParameter with a given name, helpMessage, and supertype.

Parameters:
name - the name of the parameter
helpMessage - the help message to be displayed
supertype - the class that must be a supertype of the class stored in the parameter
Throws:
ArgumentException - if the class for the supertype cannot be found

ClassParameter

public ClassParameter(java.lang.String name,
                      java.lang.String helpMessage)
Creates a new ClassParameter with a given name and helpMessage.

Parameters:
name - the name of the parameter
helpMessage - the help message to be displayed

ClassParameter

public ClassParameter(java.lang.String name)
Creates a new ClassParameter with a given name.

Parameters:
name - the name of the parameter
Method Detail

getType

public java.lang.Class getType()
Gets the type of this Argument.

Specified by:
getType in class Argument
Returns:
The type description

fromStringValue

protected java.lang.Object fromStringValue(java.lang.String value)
                                    throws ArgumentFormatException
Parses a String value into an Object appropriate for the type

Specified by:
fromStringValue in class Argument
Parameters:
value - the value
Returns:
the parsed Object
Throws:
ArgumentFormatException - if the value is malformed
See Also:
laser.util.argument.Argument.toStringValue(Object)

toStringValue

protected java.lang.String toStringValue(java.lang.Object value)
Returns the String value of the given Object value.

Overrides:
toStringValue in class Argument
Parameters:
value - The Object value
Returns:
The String value
See Also:
laser.util.argument.Argument.fromStringValue(String)

checkValue

protected void checkValue(java.lang.Object value)
                   throws ArgumentFormatException
Checks to make sure the the given value is well-formed.

Overrides:
checkValue in class Argument
Parameters:
value - The new value
Throws:
ArgumentFormatException - if the argument is not well-formed

setValue

public void setValue(java.lang.Class value)
              throws ArgumentFormatException,
                     ArgumentNotRepeatableException
Sets the value of this ClassOption to the specified value.

Parameters:
value - The value for this ClassOption
Throws:
ArgumentFormatException - if the value is incorrectly formatted
ArgumentNotRepeatableException - if the user attempted to set the value of a single-valued argument multiple times

getClassValue

public java.lang.Class getClassValue()
Gets the value of this ClassOption

Returns:
the value of this ClassOption

getClassValue

public java.lang.Class getClassValue(int i)
Gets the i-th value of this ClassOption

Parameters:
i - the value to get
Returns:
the i-th value of this ClassOption

getClassInstance

public java.lang.Object getClassInstance()
                                  throws ArgumentException
Creates an instance of the class named in this parameter

Returns:
an instance of the class named in this parameter
Throws:
ArgumentException - if an error occurs

clone

public java.lang.Object clone()
Clones this Object.

Specified by:
clone in class Argument
Returns:
The clone