org.apache.commons.cli

Class PatternOptionBuilder

public class PatternOptionBuilder extends Object

Allows Options to be created from a single String. The pattern contains various single character flags and via an optional punctuation character, their expected type.

a-a flag
b@-b [classname]
c>-c [filename]
d+-d [classname] (creates object via empty contructor)
e%-e [number] (creates Double/Long instance depeding on existing of a '.')
f/-f [url]
g:-g [string]

For example, the following allows command line flags of '-v -p string-value -f /dir/file'.

Options options = PatternOptionBuilder.parsePattern("vp:f/");

TODO These need to break out to OptionType and also to be pluggable.

Version: $Revision: 542144 $

Author: Henri Yandell (bayard @ generationjava.com)

Field Summary
static ClassCLASS_VALUE
Class class
static ClassDATE_VALUE
Date class
static ClassEXISTING_FILE_VALUE
FileInputStream class
static ClassFILES_VALUE
File array class
static ClassFILE_VALUE
File class
static ClassNUMBER_VALUE
Number class
static ClassOBJECT_VALUE
Object class
static ClassSTRING_VALUE
String class
static ClassURL_VALUE
URL class
Method Summary
static ObjectgetValueClass(char ch)

Retrieve the class that ch represents.

static booleanisValueCode(char ch)

Returns whether ch is a value code, i.e. whether it represents a class in a pattern.

static OptionsparsePattern(String pattern)

Returns the Options instance represented by pattern.

Field Detail

CLASS_VALUE

public static final Class CLASS_VALUE
Class class

DATE_VALUE

public static final Class DATE_VALUE
Date class

EXISTING_FILE_VALUE

public static final Class EXISTING_FILE_VALUE
FileInputStream class

FILES_VALUE

public static final Class FILES_VALUE
File array class

FILE_VALUE

public static final Class FILE_VALUE
File class

NUMBER_VALUE

public static final Class NUMBER_VALUE
Number class

OBJECT_VALUE

public static final Class OBJECT_VALUE
Object class

STRING_VALUE

public static final Class STRING_VALUE
String class

URL_VALUE

public static final Class URL_VALUE
URL class

Method Detail

getValueClass

public static Object getValueClass(char ch)

Retrieve the class that ch represents.

Parameters: ch the specified character

Returns: The class that ch represents

isValueCode

public static boolean isValueCode(char ch)

Returns whether ch is a value code, i.e. whether it represents a class in a pattern.

Parameters: ch the specified character

Returns: true if ch is a value code, otherwise false.

parsePattern

public static Options parsePattern(String pattern)

Returns the Options instance represented by pattern.

Parameters: pattern the pattern string

Returns: The Options instance