org.sadun.util
Class CmdLineOptions.Handler

java.lang.Object
  extended byorg.sadun.util.CmdLineOptions.Handler
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
CmdLineOptions.ChainedHandler
Enclosing class:
CmdLineOptions

public abstract static class CmdLineOptions.Handler
extends java.lang.Object
implements java.lang.Comparable

This class handles an option and can be subclassed to define the reaction to the discovery of an option.


Nested Class Summary
static class CmdLineOptions.Handler.ParamSet
          A set of parmeters for an option
 
Field Summary
protected  java.lang.String[] aliases
          The aliases for the option
protected  java.lang.String description
          The description for the option
protected  java.lang.String option
          The option literal
protected  int priority
          The priority of the option
 
Constructor Summary
CmdLineOptions.Handler(java.lang.String option)
          Build an handler which recognizes the given option literal (at zero priority).
CmdLineOptions.Handler(java.lang.String option, java.lang.String description)
          Build an handler which recognizes the given option literal (at zero priority).
CmdLineOptions.Handler(java.lang.String option, java.lang.String description, java.lang.String aliases)
          Build an handler which recognizes the given option literal, the given aliases and the given description (at zero priority).
CmdLineOptions.Handler(java.lang.String option, java.lang.String description, java.lang.String aliases, int priority)
          Build an handler which recognizes the given option literal, the given aliases, the given description and the given priority.
 
Method Summary
 void addAliases(java.lang.String aliases)
          Adds aliases for the option handled by this handler, in comma-separated format.
 void addAliases(java.lang.String[] aliases)
          Adds aliases for the option handled by this handler.
 int compareTo(java.lang.Object obj)
           
protected  java.lang.String[] getAliases()
          Return the array of aliases for this handler.
 java.lang.String getDescription()
          Return a description for the handled option - which is included in the usage() string.
 int getPriority()
          Return the priority of the handler.
protected abstract  void option(java.lang.String option, CmdLineOptions.Handler.ParamSet ps, boolean value)
          This method must be overridden by an implementation to define the behaviour of the handler when an option is found.
 void setAliases(java.lang.String aliases)
          Sets the aliases for the option handled by this handler, in comma-separated format.
 void setAliases(java.lang.String[] aliases)
          Sets the aliases for the option handled by this handler.
 void setDescription(java.lang.String description)
          Set a description for the handled option - which is included in the usage() string.
 void setPriority(int priority)
          Set the priority of the handler.
 java.lang.String toString()
          Return a description of the handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

option

protected java.lang.String option
The option literal


description

protected java.lang.String description
The description for the option


aliases

protected java.lang.String[] aliases
The aliases for the option


priority

protected int priority
The priority of the option

Constructor Detail

CmdLineOptions.Handler

public CmdLineOptions.Handler(java.lang.String option,
                              java.lang.String description,
                              java.lang.String aliases,
                              int priority)
Build an handler which recognizes the given option literal, the given aliases, the given description and the given priority.

Parameters:
priority - the priority of the option.
option - the option literal.
description - a description for the option.
aliases - the option aliases, in comma-separated format.

CmdLineOptions.Handler

public CmdLineOptions.Handler(java.lang.String option,
                              java.lang.String description,
                              java.lang.String aliases)
Build an handler which recognizes the given option literal, the given aliases and the given description (at zero priority).

Parameters:
option - the option literal.

CmdLineOptions.Handler

public CmdLineOptions.Handler(java.lang.String option,
                              java.lang.String description)
Build an handler which recognizes the given option literal (at zero priority).

Parameters:
option - the option literal.

CmdLineOptions.Handler

public CmdLineOptions.Handler(java.lang.String option)
Build an handler which recognizes the given option literal (at zero priority).

Parameters:
option - the option literal.
Method Detail

setDescription

public void setDescription(java.lang.String description)
Set a description for the handled option - which is included in the usage() string.

Parameters:
description - a short description of the tool.

getDescription

public java.lang.String getDescription()
Return a description for the handled option - which is included in the usage() string.

Returns:
a description for the handled option - which is included in the usage() string.

toString

public java.lang.String toString()
Return a description of the handler.

See Also:
Object.toString()

getAliases

protected java.lang.String[] getAliases()
Return the array of aliases for this handler. When registering the handler, it will be registered for the aliases too.

Returns:
the array of aliases for this handler.

setPriority

public void setPriority(int priority)
Set the priority of the handler. See CmdLineOptions.parse(String[]).

Parameters:
priority - the priority of the handler

getPriority

public int getPriority()
Return the priority of the handler. See CmdLineOptions.parse(String[])

Returns:
the priority of the handler.

addAliases

public void addAliases(java.lang.String[] aliases)
Adds aliases for the option handled by this handler.

Parameters:
aliases - the option aliases.

addAliases

public void addAliases(java.lang.String aliases)
Adds aliases for the option handled by this handler, in comma-separated format.

Parameters:
aliases - the option aliases, in comma-separated format.

setAliases

public void setAliases(java.lang.String aliases)
Sets the aliases for the option handled by this handler, in comma-separated format.

Parameters:
aliases - the option aliases, in comma-separated format.

setAliases

public void setAliases(java.lang.String[] aliases)
Sets the aliases for the option handled by this handler.

Parameters:
aliases - the option aliases.

option

protected abstract void option(java.lang.String option,
                               CmdLineOptions.Handler.ParamSet ps,
                               boolean value)
This method must be overridden by an implementation to define the behaviour of the handler when an option is found. For example, an handler may set a member variable, load a file, etc.

It receives the option literal (stripped of the option prefix and postfix), a ParamSet object with additional non-optional parameters and the "set/unset" value of the option.

Parameters:
option - the option literal.
ps - a ParamSet object, to browse option parameters.
value - specifies if the option has been set or unset.

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
See Also:
Comparable.compareTo(Object)


Copyright © 1999-2004 Cristiano Sadun. This software is released under GPL.