|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcmdline.AbstractParameter
Base class for command line parameters.
To implement a concrete Parameter class by subclassing this class, the following should be done:
validateValue()
method.
This method is called any time an attempt is made to add or set
values.
setOptionLabel()
from the
constructors to set a
reasonable option label for the new type of parameter.
FileParam
provides the
getFiles()
method to retrieve its values as File
objects.
A simple Parameter class that accepts only strings of a specified length might look as follows:
public class FixedLenParam extends AbstractParameter { private int length; public FixedLenParam(String tag, String desc, int length) { setTag(tag); setDesc(desc); this.length = length; setOptionLabel("<s>"); } public void validateValue(String val) throws CmdLineException { super.validateValue(val); // check acceptable values, etc.. if (val.length() != length) { throw new CmdLineException(getTag() + " must be a string of " + length + " characters in length"); } } }
Field Summary | |
protected java.lang.String[] |
acceptableValues
a set of restricted values the Parameter may take |
protected java.lang.String |
desc
a description of the parameter to be displayed in the usage |
protected boolean |
hidden
indicates that the parameter is hidden and will not be displayed in the normal usage - default is false |
protected boolean |
ignoreRequired
During parse, ignore missing required Parameters if this Parameter is set. |
protected boolean |
multiValued
Indicates whether the parameter can have multiple values. |
protected boolean |
optional
Indicates whether or not the parameter is optional. |
protected java.lang.String |
optionLabel
The label that should be used for a Parameter option's value in the usage |
protected boolean |
set
indicates that the value of the parameter has been set |
protected java.lang.String |
tag
the tag which uniquely identifies the parameter, and will be used to identify the parameter on the command line if the parameter is used as an option |
protected java.util.ArrayList |
values
the value(s) of the entity |
Fields inherited from interface jcmdline.Parameter |
HIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED |
Constructor Summary | |
AbstractParameter()
|
Method Summary | |
void |
addValue(java.lang.String value)
Adds the specified string as a value for this entity after calling validateValue() to validate. |
java.lang.String[] |
getAcceptableValues()
Gets the values that are acceptable for this parameter, if a restricted set exists. |
java.lang.String |
getDesc()
gets the value of the parameter's description |
boolean |
getIgnoreRequired()
Gets the flag indicating that during parse, missing required Parameters are ignored if this Parameter is set. |
java.lang.String |
getOptionLabel()
gets the value of optionLabel |
java.lang.String |
getTag()
gets the value of tag |
java.lang.String |
getValue()
The value of the parameter, in the case where the parameter is not multi-valued. |
java.util.Collection |
getValues()
gets the values associated with this Parameter |
boolean |
isHidden()
gets the value of the hidden indicator |
boolean |
isMultiValued()
gets the value of multiValued indicator |
boolean |
isOptional()
returns the value of the optional indicator |
boolean |
isSet()
gets an indicator that the parameter's value has been set |
void |
setAcceptableValues(java.util.Collection vals)
Sets the values that are acceptable for this parameter, if a restricted set exists. |
void |
setAcceptableValues(java.lang.String[] vals)
Sets the values that are acceptable for this parameter, if a restricted set exists. |
void |
setDesc(java.lang.String desc)
sets the value of this parameter's description |
void |
setHidden(boolean hidden)
sets the value of the hidden indicator |
void |
setIgnoreRequired(boolean ignoreRequired)
Sets a flag such that during parse, missing required Parameters are ignored if this Parameter is set. |
void |
setMultiValued(boolean multiValued)
sets the value of the multiValued indicator |
void |
setOptional(boolean optional)
indicates whether or not the parameter is optional |
void |
setOptionLabel(java.lang.String optionLabel)
Sets the value of optionLabel. |
void |
setTag(java.lang.String tag)
sets the value of tag |
void |
setValue(java.lang.String value)
Sets the value of the parameter to the specified string after calling validateValue() to validate. |
void |
setValues(java.util.Collection values)
Sets the values of the parameter to those specified after calling validateValue() to validate. |
void |
setValues(java.lang.String[] values)
Sets the values of the parameter to those specified after calling validateValue() to validate. |
void |
validateValue(java.lang.String value)
Verifies that value is valid for this entity. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String tag
protected boolean optional
true
, indicating that the parameter is optional.
protected boolean multiValued
protected java.lang.String desc
protected boolean hidden
false
protected boolean set
protected java.util.ArrayList values
protected java.lang.String optionLabel
setOptionLabel()
,
getOptionLabel()
protected java.lang.String[] acceptableValues
setAcceptableValues()
,
getAcceptableValues()
protected boolean ignoreRequired
setIgnoreRequired()
,
getIgnoreRequired()
Constructor Detail |
public AbstractParameter()
Method Detail |
public boolean isSet()
isSet
in interface Parameter
public void setHidden(boolean hidden)
setHidden
in interface Parameter
hidden
- true (Parameter.HIDDEN
) if the parameter is a
hidden parameterpublic boolean isHidden()
isHidden
in interface Parameter
Parameter.HIDDEN
) if the parameter is a
hidden parameterpublic void setDesc(java.lang.String desc) throws java.lang.IllegalArgumentException
setDesc
in interface Parameter
desc
- a description of the parameter, suitable for display in
the command's usage
java.lang.IllegalArgumentException
- if desc
is
fewer than 5 charaters.public java.lang.String getDesc()
getDesc
in interface Parameter
public void setTag(java.lang.String tag) throws java.lang.IllegalArgumentException
setTag
in interface Parameter
tag
- a unique identifier for this parameter. If the
parameter is used as an option, it will be used to
identify the option on the command line. In the case
where the parameter is used as an argument, it will
only be used to identify the argument in the usage
statement. Tags must be made up of any character but
'='.
java.lang.IllegalArgumentException
- if the length of tag
is less than 1, or tag
contains an
invalid character.public java.lang.String getTag()
getTag
in interface Parameter
setTag()
public void setMultiValued(boolean multiValued)
setMultiValued
in interface Parameter
multiValued
- true if the parameter can have multiple valuespublic boolean isMultiValued()
isMultiValued
in interface Parameter
public void setOptional(boolean optional)
setOptional
in interface Parameter
optional
- true if the parameter is optionalpublic boolean isOptional()
isOptional
in interface Parameter
public java.lang.String[] getAcceptableValues()
getAcceptableValues
in interface Parameter
setAcceptableValues()
public void setAcceptableValues(java.lang.String[] vals)
vals
value, or an empty vals
array, will result in any previously set acceptable values being cleared.
setAcceptableValues
in interface Parameter
vals
- the new acceptable valuesgetAcceptableValues()
public void setAcceptableValues(java.util.Collection vals)
vals
value, or an empty vals
Collection, will result in any previously set acceptable values being
cleared.
The toString()
values of the Objects in vals
will be used for the acceptable values.
setAcceptableValues
in interface Parameter
vals
- the new acceptable valuespublic void addValue(java.lang.String value) throws CmdLineException
addValue
in interface Parameter
value
- the value to be added
CmdLineException
- if the value of the entity
has already been set and multiValued
is
not true
, or if
validateValue()
detects a problem.public void setValue(java.lang.String value) throws CmdLineException
setValue
in interface Parameter
value
- the new value of the parameter
if
- validateValue()
detects a problem.
CmdLineException
public void setValues(java.util.Collection values) throws CmdLineException
setValues
in interface Parameter
values
- A collection of String objects to be used as the
parameter's values.
java.lang.ClassCastException
- if the Collection contains object that
are not Strings.
CmdLineException
- if more than one value is specified
and multiValued
is not true
, or
if validateValue()
detects a problem.public void setValues(java.lang.String[] values) throws CmdLineException
setValues
in interface Parameter
values
- The String objects to be used as the
parameter's values.
CmdLineException
- if more than one value is specified
and multiValued
is not true
, or
if validateValue()
detects a problem.public void validateValue(java.lang.String value) throws CmdLineException
value
is valid for this entity.
The implementation in AbstractParameter is to verify that, if there are specific acceptableValues associated with the Parameter, the value is one of those specified. Any additional validation must be done by a subclass. Because the validation performed by this method is applicable to most, if not all Parameters, it is recommended that subclasses call it from within their override methods:
public void validateValue(String value) throws CmdLineException { super.validateValue(value); // do some subclass-specific validation . . }
validateValue
in interface Parameter
value
- the value to be validated
CmdLineException
- if value
is not valid.public java.lang.String getValue()
getValue
in interface Parameter
getValues()
public java.util.Collection getValues()
getValues
in interface Parameter
isSet()
public void setOptionLabel(java.lang.String optionLabel)
st_date <mm/dd/yy> the start date of the reportThe default is the empty string.
setOptionLabel
in interface Parameter
optionLabel
- The string used as a label for the parameter's
value. If null, an empty string is used.getOptionLabel()
public java.lang.String getOptionLabel()
getOptionLabel
in interface Parameter
setOptionLabel()
public void setIgnoreRequired(boolean ignoreRequired)
setIgnoreRequired
in interface Parameter
ignoreRequired
- set to true
to ignore missing
required Parameters if this Parameter is setgetIgnoreRequired()
public boolean getIgnoreRequired()
getIgnoreRequired
in interface Parameter
true
if missing required Parameters
will be ignored when this Parameter is set.setIgnoreRequired()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |