Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

AppOption Class Reference

Collaboration diagram for AppOption:

Collaboration graph
[legend]
List of all members.

Detailed Description

An object representing a command line option.

Author:
Author
tvaline
Version:
Revision
1.3
,
Date
2005/03/05 04:06:16

Definition at line 28 of file AppOption.java.

Public Member Functions

int getLen ()
 Returns the number of data values associated with this option.
String getName ()
 Returns the name of this option.
int getType ()
 Returns the type of this option.
String getValue ()
 Returns the value of this option in a string representation.
void setValue (String value)
 Sets the value of this option.
String toString ()
 Returns a string representation of the values associated with this option.

Static Public Member Functions

static AppOption findListOption (AppOption options[])
 Returns a list type application option if one exists in the list provided.
static AppOption findOption (String name, AppOption options[])
 Returns an option with the given name.
static AppOption getFlag (String name)
 Creates a new flag type option.
static AppOption getList ()
 Creates a new list type option.
static AppOption getOption (String name, int numvalues)
 Returns a named option having a finite number of values.
static AppOption getOption (String name)
 Returns a named option having one value.
static AppOption[] parseCLArgs (String args[], AppOption templates[]) throws AppException
 Parses the command line arguments of an application and compares those options against a list of expected options.

Static Public Attributes

static final int FLAG_TYPE = 0
 Indicates the option is a simple flag.
static final int LIST_TYPE = 2
 Indicates the option contains a list of arguments.
static final int OPTION_TYPE = 1
 Indicates the option contains an argument.
static final int UNKNOWN = -1
 Indicates the option type is not known.
static final int UNLIMITED_LENGTH = -1
 Indicates that a list option has an unconstrained argument list length.


Member Function Documentation

static AppOption findListOption AppOption  options[]  )  [static]
 

Returns a list type application option if one exists in the list provided.

Parameters:
options The options to search through.
Returns:
The first list type application option or null if none are found.

Definition at line 86 of file AppOption.java.

References AppOption.getType(), and AppOption.LIST_TYPE.

00086                                                               {
00087     for(int i = 0;i < options.length;i++) {
00088       if(options[i].getType() == LIST_TYPE){return options[i];}
00089     }
00090 
00091     return null;
00092   }

static AppOption findOption String  name,
AppOption  options[]
[static]
 

Returns an option with the given name.

Parameters:
name The option name to search for
options The list of options to search through
Returns:
The named option from the list or null if it doesn't exist

Definition at line 102 of file AppOption.java.

References AppOption.getName().

00102                                                                        {
00103     for(int i = 0;i < options.length;i++) {
00104       if(options[i].getName() == name){return options[i];}
00105     }
00106 
00107     return null;
00108   }

static AppOption getFlag String  name  )  [static]
 

Creates a new flag type option.

These types of options are used to indicate some application switch is either on or off.

Parameters:
name The name of the option
Returns:
The option

Definition at line 118 of file AppOption.java.

References AppOption.FLAG_TYPE.

00118                                                {
00119     return new AppOption(FLAG_TYPE, name, 0);
00120   }

int getLen  ) 
 

Returns the number of data values associated with this option.

Returns:
The number of data values associated with this option.

Definition at line 224 of file AppOption.java.

00224 {return this.len;}

static AppOption getList  )  [static]
 

Creates a new list type option.

These types of options are used to supply lists of data such as filenames as command line arguments

Returns:
The option

Definition at line 128 of file AppOption.java.

References AppOption.LIST_TYPE, and AppOption.UNLIMITED_LENGTH.

00128                                     {
00129     return new AppOption(LIST_TYPE, new String(), UNLIMITED_LENGTH);
00130   }

String getName  ) 
 

Returns the name of this option.

Returns:
The name of this option.

Definition at line 231 of file AppOption.java.

Referenced by AppOption.findOption().

00231 {return this.name;}

static AppOption getOption String  name,
int  numvalues
[static]
 

Returns a named option having a finite number of values.

This is used to supply a finite list of arguments associated with a named option. An example may be a 'files' option for a diff program.

diff -files <file1> <file2>

In this case the -files option has a length of two values of <file1> and <file2>

Parameters:
name The name of the option
numvalues The number of values associated with the option.
Returns:
The option

Definition at line 164 of file AppOption.java.

References AppOption.OPTION_TYPE.

00164                                                                 {
00165     return new AppOption(OPTION_TYPE, name, numvalues);
00166   }

static AppOption getOption String  name  )  [static]
 

Returns a named option having one value.

An example may be a logfile option for a program.

program -log <logfile>

In this case the -log option has a length of one value of <logfile>.

Parameters:
name The name of the option.
Returns:
The option.

Definition at line 145 of file AppOption.java.

References AppOption.OPTION_TYPE.

00145                                                  {
00146     return new AppOption(OPTION_TYPE, name, 1);
00147   }

int getType  ) 
 

Returns the type of this option.

Returns:
The type of this option.

Definition at line 238 of file AppOption.java.

Referenced by AppOption.findListOption().

00238 {return this.type;}

String getValue  ) 
 

Returns the value of this option in a string representation.

Returns:
The value of this option.

Definition at line 245 of file AppOption.java.

00245 {return this.value;}

static AppOption [] parseCLArgs String  args[],
AppOption  templates[]
throws AppException [static]
 

Parses the command line arguments of an application and compares those options against a list of expected options.

Parameters:
args The command line arguments to parse
templates The template list of application options.
Returns:
A list of options that are present on the command line, are valid for the application and have data populated in them.
Exceptions:
AppException If an error in processing occurs.

Definition at line 180 of file AppOption.java.

00181                         {
00182     int             i       = 0;
00183     List<AppOption> options = new ArrayList<AppOption>(args.length);
00184     try {
00185       while(i < args.length) {
00186         String    name     = args[i++];
00187         AppOption template = findTemplate(name, templates);
00188         if(template == null){throw new AppException();}
00189         if(template.getType() == AppOption.LIST_TYPE) {
00190           if(hasMoreFlags(args, --i, templates)){throw new AppException();}
00191           else {
00192             String values = new String();
00193             while(i < args.length) {
00194               values += (args[i++] + " " /*NOI18N*/);
00195             }
00196             template.setValue(values.trim());
00197             AppOption result[] = new AppOption[options.size() + 1];
00198             result                    = ((AppOption[])options.toArray(result));
00199             result[result.length - 1] = template;
00200 
00201             return result;
00202           }
00203         } else {
00204           String values = new String();
00205           for(int j = 0;j < template.getLen();j++) {
00206             values += (args[i++] + " " /*NOI18N*/);
00207           }
00208           template.setValue(values.trim());
00209           options.add(template);
00210         }
00211       } // end while
00212     } catch(Exception e) {
00213       throw new AppException();
00214     }
00215 
00216     return ((AppOption[])options.toArray(new AppOption[options.size()]));
00217   } // end method parseCLArgs

void setValue String  value  ) 
 

Sets the value of this option.

Parameters:
value The new value of the option.

Definition at line 252 of file AppOption.java.

00252 {this.value = value;}

String toString  ) 
 

Returns a string representation of the values associated with this option.

Returns:
The values associated with this option.

Definition at line 259 of file AppOption.java.

References AppOption.LIST_TYPE.

00259                            {
00260     if(this.type == LIST_TYPE) {
00261       return ("INT_LIST" /*NOI18N*/ +
00262           ((value.length() != 0) ? (":" /*NOI18N*/ + value) : ("" /*NOI18N*/)));
00263     } else {
00264       return (name +
00265           ((value.length() != 0) ? (":" /*NOI18N*/ + value) : ("" /*NOI18N*/)));
00266     }
00267   }


Member Data Documentation

final int FLAG_TYPE = 0 [static]
 

Indicates the option is a simple flag.

Definition at line 30 of file AppOption.java.

Referenced by AppOption.getFlag().

final int LIST_TYPE = 2 [static]
 

Indicates the option contains a list of arguments.

Definition at line 36 of file AppOption.java.

Referenced by AppOption.findListOption(), AppOption.getList(), and AppOption.toString().

final int OPTION_TYPE = 1 [static]
 

Indicates the option contains an argument.

Definition at line 33 of file AppOption.java.

Referenced by AppOption.getOption().

final int UNKNOWN = -1 [static]
 

Indicates the option type is not known.

Definition at line 39 of file AppOption.java.

final int UNLIMITED_LENGTH = -1 [static]
 

Indicates that a list option has an unconstrained argument list length.

Definition at line 42 of file AppOption.java.

Referenced by AppOption.getList().


The documentation for this class was generated from the following file:
Generated on Tue Nov 1 23:43:41 2005 for JavaBasicApplicationFrameworkAPI(JBAF) by  doxygen 1.4.2