de.tototec.cmdoption.handler
Class BooleanFieldHandler

java.lang.Object
  extended by de.tototec.cmdoption.handler.BooleanFieldHandler
All Implemented Interfaces:
CmdOptionHandler

public class BooleanFieldHandler
extends java.lang.Object
implements CmdOptionHandler

Apply an one-arg option to a Boolean (or boolean) field. Evaluated the argument to true if it is "true", "on" or "1".


Constructor Summary
BooleanFieldHandler()
           
BooleanFieldHandler(java.lang.String[] trueWords, java.lang.String[] falseWords, boolean caseSensitive)
          If the list of falseWords is empty or null, any words not in trueWords is considered as false.
 
Method Summary
 void applyParams(java.lang.Object config, java.lang.reflect.AccessibleObject element, java.lang.String[] args, java.lang.String optionName)
          Apply the option and it arguments (if any) to the field or method representing the option.
 boolean canHandle(java.lang.reflect.AccessibleObject element, int argCount)
          Return true if the field or method (element) with the given number of arguments (argCount) can be handled by this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanFieldHandler

public BooleanFieldHandler()

BooleanFieldHandler

public BooleanFieldHandler(java.lang.String[] trueWords,
                           java.lang.String[] falseWords,
                           boolean caseSensitive)
If the list of falseWords is empty or null, any words not in trueWords is considered as false.

Parameters:
trueWords -
falseWords -
caseSensitive -
Method Detail

canHandle

public boolean canHandle(java.lang.reflect.AccessibleObject element,
                         int argCount)
Description copied from interface: CmdOptionHandler
Return true if the field or method (element) with the given number of arguments (argCount) can be handled by this handler.

Specified by:
canHandle in interface CmdOptionHandler
Parameters:
element - The field or method that represents an command line option.
argCount - The number or arguments the command line option supports.
Returns:
true if the option can be parsed and applied by this handler.

applyParams

public void applyParams(java.lang.Object config,
                        java.lang.reflect.AccessibleObject element,
                        java.lang.String[] args,
                        java.lang.String optionName)
                 throws CmdOptionHandlerException
Description copied from interface: CmdOptionHandler
Apply the option and it arguments (if any) to the field or method representing the option.

Specified by:
applyParams in interface CmdOptionHandler
Parameters:
config - The object containing the field or element to which the parsed values should be applied.
element - The element itself (field or method) to apply to.
args - The parsed arguments of the option.
optionName - The actual name of the currently handled option. This is only required to create good error messages.
Throws:
CmdOptionHandlerException - When the argument can not be applied to the config object.