org.eclipse.actf.util.command
Class CLSwitch

java.lang.Object
  extended by org.eclipse.actf.util.command.CLSwitch

public class CLSwitch
extends Object

The CLSwitch class is used in conjuction with the CLArgumentProcessor to embody a single command line switch. An implementation of IArgumentResolver should be associated with any CLSwitch.

Author:
Mike Squillace
See Also:
CLArgumentProcessor

Constructor Summary
CLSwitch(String name, String desc, Class type)
          create a command line switch with the given name and type.
CLSwitch(String name, String desc, Class type, boolean required)
          create a command line switch with the given name and type.
CLSwitch(String name, String desc, Class type, boolean required, IArgumentResolver resolver)
          create a command line switch with the given name and type.
CLSwitch(String name, String desc, IArgumentResolver resolver)
          create a command line switch with the given name and type.
 
Method Summary
 IArgumentResolver getArgumentResolver()
           
 String getDefaultValue()
           
 String getDescription()
           
 int getExpectedNumberOfArgs()
           
 String getFullSwitchName()
          returns the full switch name which is composed of its prefix followed by its name.
 String getName()
           
 String getPrefix()
           
 Object getResolvedValue()
          returns the resolved value of the argument passed to the switch.
 String getValue()
          returns the unresolved value or argument passed to the switch on the command line.
 Class getValueType()
          returns the desired type of the value or agument corresponding to the swithh.
 boolean isRequired()
           
 Object resolveValue(String arg)
          resolve the value passed from the command line.
 void setArgumentResolver(IArgumentResolver resolver)
           
 void setDefaultValue(String value)
           
 void setDescription(String description)
           
 void setExpectedNumberOfArgs(int args)
          set the number of arguments expected by this switch.
 void setName(String name)
          set the name of the switch.
 void setPrefix(String prefix)
          set the command line switch's prefix.
 void setRequired(boolean required)
          set to true if the switch and its corresponding value are required for the application.
 void setToDefaultValue()
          set the switch to its default value
 void setValue(String value)
           
 void setValueType(Class type)
          set the type of the value or argument to this switch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLSwitch

public CLSwitch(String name,
                String desc,
                Class type)
create a command line switch with the given name and type. By default, the switch is not required.

Parameters:
name - -switch name (denoted with a hypthen (-) on the command line)
desc - - switch description or usage
type - - type of resolved value

CLSwitch

public CLSwitch(String name,
                String desc,
                IArgumentResolver resolver)
create a command line switch with the given name and type. By default, the switch is not required. Type resoltuion is left to the specified resolver.

Parameters:
name - -switch name
desc - - switch description or usage
resolver - - argument resolver

CLSwitch

public CLSwitch(String name,
                String desc,
                Class type,
                boolean required)
create a command line switch with the given name and type. By default, the org.eclipse.actf.util.command.DefaultArgumentResolver is used to resolve switch values.

Parameters:
name - -switch name
desc - - switch description or usage
type - - type of resolved value
required - - whether or not this switch is required on the command line
See Also:
DefaultArgumentResolver

CLSwitch

public CLSwitch(String name,
                String desc,
                Class type,
                boolean required,
                IArgumentResolver resolver)
create a command line switch with the given name and type. The argument or value passed to this switch is resolved via the specified implementation of the ArgumentResolver interface.

Parameters:
name - -switch name
desc - - switch description or usage
type - - type of resolved value
required - - whether or not this switch is required on the command line
resolver - - argument resolver
Method Detail

getName

public String getName()
Returns:
Returns the switch name.

setName

public void setName(String name)
set the name of the switch. This name will also be used to refer to the switch on the command line when preceded by a hyphen (-).

Parameters:
name - - The switch name

getPrefix

public String getPrefix()
Returns:
returns the switch prefix as it should be used on the command line

setPrefix

public void setPrefix(String prefix)
set the command line switch's prefix. The switch must ocur on the command line preceded with this prefix. The default prefix is '0'.

Parameters:
prefix - - prefix for switch

getFullSwitchName

public String getFullSwitchName()
returns the full switch name which is composed of its prefix followed by its name.

Returns:
full switch name including prefix

getDescription

public String getDescription()
Returns:
Returns the description or help for the switch.

setDescription

public void setDescription(String description)
Parameters:
description - the help or description of the switch (appears in the usage message)

getExpectedNumberOfArgs

public int getExpectedNumberOfArgs()
Returns:
expected number of arguments for this switch
See Also:
setExpectedNumberOfArgs(int)

setExpectedNumberOfArgs

public void setExpectedNumberOfArgs(int args)
set the number of arguments expected by this switch. This value determines the number of arguments from the original command line argument array as received by the main(String[]) method will be used for this switch. Supplying fewer than the number of expected number of arguments on the command line is acceptable and additional arguments beyond the number of expected arguments will be flagged.

Parameters:
args - - expected number of arguments (default is 1)

isRequired

public boolean isRequired()
Returns:
Returns whether or not this switch is required

setRequired

public void setRequired(boolean required)
set to true if the switch and its corresponding value are required for the application.

Parameters:
required - true if the switch is required, false otherwise

getValueType

public Class getValueType()
returns the desired type of the value or agument corresponding to the swithh. An implementation of IArgumentResolver is responsible for resolving the value or argument to this type.

Returns:
Returns the type of the value/argument of the switch

setValueType

public void setValueType(Class type)
set the type of the value or argument to this switch.

Parameters:
type - the type to which the argument to this switch is to be resolved
See Also:
getValueType()

getValue

public String getValue()
returns the unresolved value or argument passed to the switch on the command line.

Returns:
Returns the unresolved argument or value passed to this switch

setValue

public void setValue(String value)
Parameters:
value - The argument or value given to the switch on the command line

resolveValue

public Object resolveValue(String arg)
                    throws Exception
resolve the value passed from the command line. The value will be resolved via this switch's IArgumentResolver and be of the type with which this switch was defined.

Parameters:
arg - - command line argument for this switch
Returns:
returns the resolved value for the argument
Throws:
Exception

getDefaultValue

public String getDefaultValue()
Returns:
Returns the default value (if any) for this switch.

setDefaultValue

public void setDefaultValue(String value)
Parameters:
value - The default value for this switch if no value is given

setToDefaultValue

public void setToDefaultValue()
set the switch to its default value


getResolvedValue

public Object getResolvedValue()
returns the resolved value of the argument passed to the switch. The resolved value is of the type specified during the creation of the switch or via the setType(Class) method.

Returns:
the resolved value of the switch

getArgumentResolver

public IArgumentResolver getArgumentResolver()
Returns:
Returns the argument resolver.

setArgumentResolver

public void setArgumentResolver(IArgumentResolver resolver)
Parameters:
resolver - the argument resolved to be used