org.jargp
Class ArgumentProcessor

java.lang.Object
  |
  +--org.jargp.ArgumentProcessor

public class ArgumentProcessor
extends java.lang.Object

Command line parameter processing handler. Organizes all the parameter information, including the data object to which parameter values defined by the command line are stored. Provides specialized processing for the argument strings, including recognizing the '-' character at the start of an argument as indicating that the argument provides control information (flags and possibly embedded values) as opposed to data.

Version:
1.0
Author:
Dennis M. Sosnoski

Constructor Summary
ArgumentProcessor(ParameterDef[] defs)
          Constructor from array of parameter definitions.
ArgumentProcessor(ParameterSet set)
          Constructor from parameter set definition.
 
Method Summary
 StringTracker getArgs()
          Get argument list information.
 void listParameters(int width, java.io.PrintStream print)
          List known parameter definitions.
 java.lang.Object processArgs(java.lang.String[] args, java.lang.Object target)
          Process argument list control information.
static int processArgs(java.lang.String[] args, ParameterDef[] parms, java.lang.Object target)
          Process argument list directly.
 void reportArgumentError(char flag, java.lang.String text)
          Report argument error.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentProcessor

public ArgumentProcessor(ParameterSet set)
Constructor from parameter set definition.

Parameters:
set - head parameter set in possible chain of sets defined

ArgumentProcessor

public ArgumentProcessor(ParameterDef[] defs)
Constructor from array of parameter definitions.

Method Detail

processArgs

public java.lang.Object processArgs(java.lang.String[] args,
                                    java.lang.Object target)
Process argument list control information. Processes control flags present in the supplied argument list, setting the associated parameter values. Arguments not consumed in the control flag processing are available for access using other methods after the return from this call.

Parameters:
args - command line argument string array
target - application object defining parameter fields
Throws:
ArgumentErrorException - on error in data
java.lang.IllegalArgumentException - on error in processing

getArgs

public StringTracker getArgs()
Get argument list information. The caller can comsume arguments from the list as needed.

Returns:
argument list information

reportArgumentError

public void reportArgumentError(char flag,
                                java.lang.String text)
Report argument error. Generates an exception with information about the argument causing the problem.

Parameters:
flag - argument flag character
text - error message text
Throws:
ArgumentErrorException - reporting the error

listParameters

public void listParameters(int width,
                           java.io.PrintStream print)
List known parameter definitions. This lists all known parameter definitions in fixed maximum width format.

Parameters:
width - maximum number of columns in listing
print - print stream destination for listing definitions

processArgs

public static int processArgs(java.lang.String[] args,
                              ParameterDef[] parms,
                              java.lang.Object target)
Process argument list directly. Creates and initializes an instance of this class, then processes control flags present in the supplied argument list, setting the associated parameter values in the target object. Arguments not consumed in the control flag processing are available for access using other methods after the return from this call.

Parameters:
args - command line argument string array
target - application object defining parameter fields
Returns:
index of first command line argument not consumed by processing
Throws:
ArgumentErrorException - on error in data
java.lang.IllegalArgumentException - on error in processing


Project Web Site