com.g11ntoolkit.util
Class Arguments

java.lang.Object
  |
  +--com.g11ntoolkit.util.Arguments

public class Arguments
extends java.lang.Object

A helper utility to manage the command line arguments presented to a program.

Utility like Unix getopt. This class has been adapted from the Arguments class provided by the Apache Software Foundation.

Usage:

 int c
 parseArgumentTokens(argv);
 while((c = getArguments()) != -1 )
 {
   switch (c)
   {
     case 'v':
       System.out.println( "v" );
       break;
     case 'V':
       System.out.println( "V" );
       break;
   }
 }
 

Version:
2005/06/20
Author:
Jeffrey Rodriguez, The Apache Software Foundation..
, Bill Rich, Wilandra Consulting LLC
Copyright © 2001-2005, Wilandra Consulting LLC. All rights reserved.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See License Agreement.


Nested Class Summary
private  class Arguments.Queue
          Private class to handle the queue of arguments.
 
Field Summary
private  int lastPopArgument
          Contains the index of the last argument popped.
private static java.util.logging.Logger log
          The log used for all messages from this class.
private static int maxIncrement
          Contains the number of items by which to extend the Queue if it runs out of room.
private  java.lang.String[] messageArray
          Contains the elements of a message to display.
private  Arguments.Queue queueOfOtherStringParameters
          Contains all the arguments that don't go in the other 2 queues.
private  Arguments.Queue queueOfSwitches
          Contains all the switch arguments.
private  Arguments.Queue queueStringParameters
          Contains all the string arguments needed by the switch arguments.
 
Constructor Summary
Arguments()
          Default constructor.
 
Method Summary
 int getArguments()
          Returns the number of switches in the arguments.
 java.lang.String getlistFiles()
          Returns a list of the arguments that are strings and do not apply to a switch argument.
 java.lang.String getStringParameter()
          Returns a String type parameter from the arguments.
 void parseArgumentTokens(java.lang.String[] arguments, char[] argsWithOptions)
          Takes the array of standard Args passed from main() and parses the switches and other arguments from the list.
 void printUsage()
          Prints the usage variable to the console.
 void setUsage(java.lang.String[] message)
          Sets the usage variable so we can show the user how to use the program.
 int stringParameterLeft()
          Returns the count of how many parameters are left in the argument list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log
The log used for all messages from this class.


queueOfSwitches

private Arguments.Queue queueOfSwitches
Contains all the switch arguments.


queueStringParameters

private Arguments.Queue queueStringParameters
Contains all the string arguments needed by the switch arguments.


queueOfOtherStringParameters

private Arguments.Queue queueOfOtherStringParameters
Contains all the arguments that don't go in the other 2 queues.


messageArray

private java.lang.String[] messageArray
Contains the elements of a message to display.


lastPopArgument

private int lastPopArgument
Contains the index of the last argument popped.


maxIncrement

private static final int maxIncrement
Contains the number of items by which to extend the Queue if it runs out of room.

See Also:
Arguments.Queue.push(java.lang.Object), Constant Field Values
Constructor Detail

Arguments

public Arguments()
Default constructor.

Method Detail

parseArgumentTokens

public void parseArgumentTokens(java.lang.String[] arguments,
                                char[] argsWithOptions)
Takes the array of standard Args passed from main() and parses the switches and other arguments from the list.

The value -1 is a special flag that is used to indicate the beginning of the queue of flags and is also to tell the end of a group of switches.

This method will generate three internal queues.

  1. A queue that has the switch flag arguments.

    For example: -dvV will hold d, v, V, -1.

  2. A queue holding the string arguments needed by the switch flag arguments. If character -p requires a string argument. The string argument is saved in the string argument queue.
  3. A queue holding a list of string parameters not associated with a switch flag. For example: -a -v -p myvalue test.xml test1.xml will contain test.xml test1.xml.

Parameters:
arguments - a String array specifying the arguments
argsWithOptions - a char array specifying the switches that have string options associated with them. One character per switch in each element of this array. May be null if no switches have options.

getArguments

public int getArguments()
Returns the number of switches in the arguments.

Returns:
an int representing the number of switches in the arguments

getStringParameter

public java.lang.String getStringParameter()
Returns a String type parameter from the arguments.

Returns:
a String representing the next String type parameter

getlistFiles

public java.lang.String getlistFiles()
Returns a list of the arguments that are strings and do not apply to a switch argument.

Returns:
a String representing the list of arguments

stringParameterLeft

public int stringParameterLeft()
Returns the count of how many parameters are left in the argument list.

Returns:
an int representing the number of parameters left in the argument list

setUsage

public void setUsage(java.lang.String[] message)
Sets the usage variable so we can show the user how to use the program.

Parameters:
message - a String array specifying the usage text to display

printUsage

public void printUsage()
Prints the usage variable to the console.

Each element of the usage array is printed on a separate line.