com.ibm.as400.access
Class CommandLineArguments

java.lang.Object
  extended by com.ibm.as400.access.CommandLineArguments

public class CommandLineArguments
extends Object

The CommandLineArguments class will parse command line arguments into options specified in the format "-optionName optionValue".

Here is an example of calling a program from the command line with arguments:

  A sample program:  java myProgram systemName -userid myID -password myPWD
  

The Java code to parse the command:
// Create a vector to hold all the possible command line arguments. Vector v = new Vector(); v.addElement("-userID"); v.addElement("-password");

// Create a Hashtable to map shortcuts to the command line arguments. Hashtable shortcuts = new Hashtable(); shortcuts.put("-u", "-userID"); shortcuts.put("-p", "-password");

// Create a CommandLineArguments object with the args array passed into main(String args[]) // along with the vector and hashtable just created. CommandLineArguments arguments = new CommandLineArguments(args, v, shortcuts);

// Get the AS400 system that the user wants to run to. String system = arguments.getOptionValue("");

// Get the user ID that the user wants to log in with. String uid = arguments.getOptionValue("-userID");

// Get the password that the user wants to log in with. String pwd = arguments.getOptionValue("-password");


Constructor Summary
Constructor and Description
CommandLineArguments(String[] args)
          Creates a CommandLineArguments object.
CommandLineArguments(String[] args, Vector expectedOptions, Hashtable shortcuts)
          Creates a CommandLineArguments object.
 
Method Summary
Modifier and Type Method and Description
 Enumeration getExtraOptions()
          Returns the list of any extra options that were specified.
 Enumeration getOptionNames()
          Returns the list of option names that were specified.
 String getOptionValue(String optionName)
          Returns the value of an option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineArguments

public CommandLineArguments(String[] args)
Creates a CommandLineArguments object.

Parameters:
args - The command line arguments.

CommandLineArguments

public CommandLineArguments(String[] args,
                            Vector expectedOptions,
                            Hashtable shortcuts)
Creates a CommandLineArguments object.

Parameters:
args - The command line arguments.
expectedOptions - The expected options. This is a Vector of Strings, each starting with a hyphen ("-"). These are not case sensitive. Specify null if any options are expected.
shortcuts - The shortcuts. This is a Hashtable where the keys are Strings for the shortcuts (e.g. "-?") and the elements are Strings for the option (e.g. "-help"). All strings start with a hyphen ("-"). Specify null if no shortcuts are used.
Method Detail

getExtraOptions

public Enumeration getExtraOptions()
Returns the list of any extra options that were specified. These are options that the application was not expecting.

Returns:
The list of extra options. This is an Enumeration which contains a String for each extra option.

getOptionNames

public Enumeration getOptionNames()
Returns the list of option names that were specified.

Returns:
The list of option names. This is an Enumeration which contains a String for each option name.

getOptionValue

public String getOptionValue(String optionName)
Returns the value of an option.

Parameters:
optionName - The option name.
Returns:
The option value, or null if the option was not specified.