Qizx/open API

net.axyana.qizxopen.util
Class CmdLine

java.lang.Object
  extended bynet.axyana.qizxopen.util.CmdLine

public class CmdLine
extends java.lang.Object

Command line option analyzer.

Options are defined in this object with:

When an option is recognized by the parse method, either a field of a target application object can be set, or a method of this object can be invoked.


Nested Class Summary
static class CmdLine.Error
           
 
Constructor Summary
CmdLine(java.lang.String appName)
          Creation with an application name.
 
Method Summary
 void define(java.lang.String keyDef, java.lang.String argLabel, java.lang.String actionDef, java.lang.String help)
          Defines an option.
static java.util.Properties getDefaultProperties(java.lang.String name)
          Loads a property file from the user's home directory.
 void parse(java.lang.String[] args, java.lang.Object appli)
          Parses the command line.
 void printHelp(java.io.PrintStream out)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmdLine

public CmdLine(java.lang.String appName)
Creation with an application name.

Options must then be defined by define().

Parameters:
appName - name of the application
Method Detail

getDefaultProperties

public static java.util.Properties getDefaultProperties(java.lang.String name)
Loads a property file from the user's home directory.

Parameters:
name -
Returns:
a non-null set of properties (may be empty if file not found)

define

public void define(java.lang.String keyDef,
                   java.lang.String argLabel,
                   java.lang.String actionDef,
                   java.lang.String help)
Defines an option.

Parameters:
keyDef - appearance of the option switch.

A null key means a stray argument. The last character defines how an argument of this switch is processed (the argument value can be assigned to a field or passed to a method, according to parameter actionDef):

  • Dot '.' or ARG_SET: no following argument, pass a Boolean.TRUE value.
  • Dash '-' or ARG_RESET: no following arg, pass a Boolean.FALSE value.
  • Underscore '_' or ARG_NEXT: argument follows after a space, pass its value.
  • Colon ':' or ARG_STUCK: argument is stuck to this option switch.
  • Star '*' or ARG_ALL: get all following command-line arguments into a String array value.
argLabel - A description of the argument.
actionDef - name of a Java field or a method of the application object. The first character defines the action:
  • '!' calls a method,
  • '+' sets a field: error if the (String) field is already set.
  • '=' adds to a field: if the field is an array, the value is appended, otherwise it replaces the old value.
  • '?' prints the help.
help - option help description.

parse

public void parse(java.lang.String[] args,
                  java.lang.Object appli)
           throws java.lang.Exception
Parses the command line.

Option switches can either set the value of a member of object 'appli', or call a method of this object.

Throws:
java.lang.Exception

printHelp

public void printHelp(java.io.PrintStream out)

© 2005 Axyana Software