org.opends.server.util.args
Class Argument

java.lang.Object
  extended by org.opends.server.util.args.Argument
Direct Known Subclasses:
BooleanArgument, FileBasedArgument, IntegerArgument, MultiChoiceArgument, StringArgument

public abstract class Argument
extends java.lang.Object

This class defines a generic argument that may be used in the argument list for an application. This is an abstract class that must be subclassed in order to provide specific functionality.


Constructor Summary
protected Argument(java.lang.String name, java.lang.Character shortIdentifier, java.lang.String longIdentifier, boolean isRequired, boolean isMultiValued, boolean needsValue, Message valuePlaceholder, java.lang.String defaultValue, java.lang.String propertyName, Message description)
          Creates a new argument with the provided information.
 
Method Summary
 void addValue(java.lang.String valueString)
          Adds a value to the set of values for this argument.
 void clearValues()
          Clears the set of values assigned to this argument.
 boolean getBooleanValue()
          Retrieves the value of this argument as a Boolean.
 java.lang.String getDefaultValue()
          Retrieves the default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file.
 Message getDescription()
          Retrieves the human-readable description for this argument.
 int getIntValue()
          Retrieves the value of this argument as an integer.
 java.util.LinkedList<java.lang.Integer> getIntValues()
          Retrieves the set of values for this argument as a list of integers.
 java.lang.String getLongIdentifier()
          Retrieves the long (multi-character) identifier that may be used to specify the value of this argument.
 java.lang.String getName()
          Retrieves the generic name that will be used to refer to this argument.
 java.lang.String getPropertyName()
          Retrieves the name of a property in a properties file that may be used to set the default value for this argument if it is present.
 java.lang.Character getShortIdentifier()
          Retrieves the single-character identifier that may be used to specify the value of this argument.
 java.lang.String getValue()
          Retrieves the string vale for this argument.
 Message getValuePlaceholder()
          Retrieves the value placeholder that will be displayed for this argument in the generated usage information.
 java.util.LinkedList<java.lang.String> getValues()
          Retrieves the set of string values for this argument.
 boolean hasValue()
          Indicates whether this argument has at least one value.
 boolean isHidden()
          Indicates whether this argument should be hidden from the usage information.
 boolean isMultiValued()
          Indicates whether this argument may be provided more than once on the command line to specify multiple values.
 boolean isPresent()
          Indicates whether this argument is present in the parsed set of command-line arguments.
 boolean isRequired()
          Indicates whether this argument is required to have at least one value.
 boolean isValueSetByProperty()
          Indicates whether this argument was provided in the set of properties found is a properties file.
 boolean needsValue()
          Indicates whether a value must be provided with this argument if it is present.
 void setDefaultValue(java.lang.String defaultValue)
          Specifies the default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file.
 void setHidden(boolean isHidden)
          Specifies whether this argument should be hidden from the usage information.
 void setMultiValued(boolean isMultiValued)
          Specifies whether this argument may be provided more than once on the command line to specify multiple values.
 void setNeedsValue(boolean needsValue)
          Specifies whether a value must be provided with this argument if it is present.
 void setPresent(boolean isPresent)
          Specifies whether this argument is present in the parsed set of command-line arguments.
 void setPropertyName(java.lang.String propertyName)
          Specifies the name of a property in a properties file that may be used to set the default value for this argument if it is present.
 void setRequired(boolean isRequired)
          Specifies whether this argument is required to have at least one value.
 void setValuePlaceholder(Message valuePlaceholder)
          Specifies the value placeholder that will be displayed for this argument in the generated usage information.
 void setValueSetByProperty(boolean isValueSetByProperty)
          Specifies whether this argument was provided in the set of properties found is a properties file.
abstract  boolean valueIsAcceptable(java.lang.String valueString, MessageBuilder invalidReason)
          Indicates whether the provided value is acceptable for use in this argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Argument

protected Argument(java.lang.String name,
                   java.lang.Character shortIdentifier,
                   java.lang.String longIdentifier,
                   boolean isRequired,
                   boolean isMultiValued,
                   boolean needsValue,
                   Message valuePlaceholder,
                   java.lang.String defaultValue,
                   java.lang.String propertyName,
                   Message description)
            throws ArgumentException
Creates a new argument with the provided information.

Parameters:
name - The generic name that should be used to refer to this argument.
shortIdentifier - The single-character identifier for this argument, or null if there is none.
longIdentifier - The long identifier for this argument, or null if there is none.
isRequired - Indicates whether this argument must be specified on the command line.
isMultiValued - Indicates whether this argument may be specified more than once to provide multiple values.
needsValue - Indicates whether this argument requires a value.
valuePlaceholder - The placeholder for the argument value that will be displayed in usage information, or null if this argument does not require a value.
defaultValue - The default value that should be used for this argument if none is provided in a properties file or on the command line. This may be null if there is no generic default.
propertyName - The name of the property in a property file that may be used to override the default value but will be overridden by a command-line argument.
description - Message for the description of this argument.
Throws:
ArgumentException - If there is a problem with any of the parameters used to create this argument.
Method Detail

getName

public java.lang.String getName()
Retrieves the generic name that will be used to refer to this argument.

Returns:
The generic name that will be used to refer to this argument.

getShortIdentifier

public java.lang.Character getShortIdentifier()
Retrieves the single-character identifier that may be used to specify the value of this argument.

Returns:
The single-character identifier that may be used to specify the value of this argument, or null if there is none.

getLongIdentifier

public java.lang.String getLongIdentifier()
Retrieves the long (multi-character) identifier that may be used to specify the value of this argument.

Returns:
The long (multi-character) identifier that may be used to specify the value of this argument.

isRequired

public boolean isRequired()
Indicates whether this argument is required to have at least one value.

Returns:
true if this argument is required to have at least one value, or false if it does not need to have a value.

setRequired

public void setRequired(boolean isRequired)
Specifies whether this argument is required to have at least one value.

Parameters:
isRequired - Indicates whether this argument is required to have at least one value.

isPresent

public boolean isPresent()
Indicates whether this argument is present in the parsed set of command-line arguments.

Returns:
true if this argument is present in the parsed set of command-line arguments, or false if not.

setPresent

public void setPresent(boolean isPresent)
Specifies whether this argument is present in the parsed set of command-line arguments.

Parameters:
isPresent - Indicates whether this argument is present in the set of command-line arguments.

isHidden

public boolean isHidden()
Indicates whether this argument should be hidden from the usage information.

Returns:
true if this argument should be hidden from the usage information, or false if not.

setHidden

public void setHidden(boolean isHidden)
Specifies whether this argument should be hidden from the usage information.

Parameters:
isHidden - Indicates whether this argument should be hidden from the usage information.

isMultiValued

public boolean isMultiValued()
Indicates whether this argument may be provided more than once on the command line to specify multiple values.

Returns:
true if this argument may be provided more than once on the command line to specify multiple values, or false if it may have at most one value.

setMultiValued

public void setMultiValued(boolean isMultiValued)
Specifies whether this argument may be provided more than once on the command line to specify multiple values.

Parameters:
isMultiValued - Indicates whether this argument may be provided more than once on the command line to specify multiple values.

needsValue

public boolean needsValue()
Indicates whether a value must be provided with this argument if it is present.

Returns:
true if a value must be provided with the argument if it is present, or false if the argument does not take a value and the presence of the argument identifier itself is sufficient to convey the necessary information.

setNeedsValue

public void setNeedsValue(boolean needsValue)
Specifies whether a value must be provided with this argument if it is present. If this is changed from false to true, then a value placeholder must also be provided.

Parameters:
needsValue - Indicates whether a value must be provided with this argument if it is present.

getValuePlaceholder

public Message getValuePlaceholder()
Retrieves the value placeholder that will be displayed for this argument in the generated usage information.

Returns:
The value placeholder that will be displayed for this argument in the generated usage information, or null if there is none.

setValuePlaceholder

public void setValuePlaceholder(Message valuePlaceholder)
Specifies the value placeholder that will be displayed for this argument in the generated usage information. It may be null only if needsValue() returns false.

Parameters:
valuePlaceholder - The value placeholder that will be displayed for this argument in the generated usage information.

getDefaultValue

public java.lang.String getDefaultValue()
Retrieves the default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file.

Returns:
The default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file, or null if there is no default value.

setDefaultValue

public void setDefaultValue(java.lang.String defaultValue)
Specifies the default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file.

Parameters:
defaultValue - The default value that will be used for this argument if it is not specified on the command line and it is not set from a properties file.

getPropertyName

public java.lang.String getPropertyName()
Retrieves the name of a property in a properties file that may be used to set the default value for this argument if it is present. A value read from a properties file will override the default value returned from the getDefaultValue, but the properties file value will be overridden by a value supplied on the command line.

Returns:
The name of a property in a properties file that may be used to set the default value for this argument if it is present.

setPropertyName

public void setPropertyName(java.lang.String propertyName)
Specifies the name of a property in a properties file that may be used to set the default value for this argument if it is present.

Parameters:
propertyName - The name of a property in a properties file that may be used to set the default value for this argument if it is present.

isValueSetByProperty

public boolean isValueSetByProperty()
Indicates whether this argument was provided in the set of properties found is a properties file.

Returns:
true if this argument was provided in the set of properties found is a properties file, or false if not.

setValueSetByProperty

public void setValueSetByProperty(boolean isValueSetByProperty)
Specifies whether this argument was provided in the set of properties found is a properties file.

Parameters:
isValueSetByProperty - Specify whether this argument was provided in the set of properties found is a properties file.

getDescription

public Message getDescription()
Retrieves the human-readable description for this argument.

Returns:
The human-readable description for this argument.

hasValue

public boolean hasValue()
Indicates whether this argument has at least one value.

Returns:
true if this argument has at least one value, or false if it does not have any values.

getValue

public java.lang.String getValue()
Retrieves the string vale for this argument. If it has multiple values, then the first will be returned. If it does not have any values, then the default value will be returned.

Returns:
The string value for this argument, or null if there are no values and no default value has been given.

getValues

public java.util.LinkedList<java.lang.String> getValues()
Retrieves the set of string values for this argument.

Returns:
The set of string values for this argument.

getIntValue

public int getIntValue()
                throws ArgumentException
Retrieves the value of this argument as an integer.

Returns:
The value of this argument as an integer.
Throws:
ArgumentException - If there are multiple values, or the value cannot be parsed as an integer.

getIntValues

public java.util.LinkedList<java.lang.Integer> getIntValues()
                                                     throws ArgumentException
Retrieves the set of values for this argument as a list of integers.

Returns:
A list of the integer representations of the values for this argument.
Throws:
ArgumentException - If any of the values cannot be parsed as an integer.

getBooleanValue

public boolean getBooleanValue()
                        throws ArgumentException
Retrieves the value of this argument as a Boolean.

Returns:
The value of this argument as a Boolean.
Throws:
ArgumentException - If this argument cannot be interpreted as a Boolean value.

valueIsAcceptable

public abstract boolean valueIsAcceptable(java.lang.String valueString,
                                          MessageBuilder invalidReason)
Indicates whether the provided value is acceptable for use in this argument.

Parameters:
valueString - The value for which to make the determination.
invalidReason - A buffer into which the invalid reason may be written if the value is not acceptable.
Returns:
true if the value is acceptable, or false if it is not.

addValue

public void addValue(java.lang.String valueString)
Adds a value to the set of values for this argument. This should only be called if the value is allowed by the valueIsAcceptable method.

Parameters:
valueString - The string representation of the value to add to this argument.

clearValues

public void clearValues()
Clears the set of values assigned to this argument.