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. |
|
Returns a list type application option if one exists in the list provided.
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 }
|
|
Returns an option with the given name.
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 }
|
|
Creates a new flag type option. These types of options are used to indicate some application switch is either on or off.
Definition at line 118 of file AppOption.java. References AppOption.FLAG_TYPE. 00118 { 00119 return new AppOption(FLAG_TYPE, name, 0); 00120 }
|
|
Returns the number of data values associated with this option.
Definition at line 224 of file AppOption.java. 00224 {return this.len;}
|
|
Creates a new list type option. These types of options are used to supply lists of data such as filenames as command line arguments
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 }
|
|
Returns the name of this option.
Definition at line 231 of file AppOption.java. Referenced by AppOption.findOption(). 00231 {return this.name;}
|
|
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>
Definition at line 164 of file AppOption.java. References AppOption.OPTION_TYPE. 00164 { 00165 return new AppOption(OPTION_TYPE, name, numvalues); 00166 }
|
|
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>.
Definition at line 145 of file AppOption.java. References AppOption.OPTION_TYPE. 00145 { 00146 return new AppOption(OPTION_TYPE, name, 1); 00147 }
|
|
Returns the type of this option.
Definition at line 238 of file AppOption.java. Referenced by AppOption.findListOption(). 00238 {return this.type;}
|
|
Returns the value of this option in a string representation.
Definition at line 245 of file AppOption.java. 00245 {return this.value;}
|
|
Parses the command line arguments of an application and compares those options against a list of expected options.
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
|
|
Sets the value of this option.
Definition at line 252 of file AppOption.java. 00252 {this.value = value;}
|
|
Returns a string representation of 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 }
|
|
Indicates the option is a simple flag.
Definition at line 30 of file AppOption.java. Referenced by AppOption.getFlag(). |
|
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(). |
|
Indicates the option contains an argument.
Definition at line 33 of file AppOption.java. Referenced by AppOption.getOption(). |
|
Indicates the option type is not known.
Definition at line 39 of file AppOption.java. |
|
Indicates that a list option has an unconstrained argument list length.
Definition at line 42 of file AppOption.java. Referenced by AppOption.getList(). |