org.opends.server.util.args
Class FileBasedArgument

java.lang.Object
  extended by org.opends.server.util.args.Argument
      extended by org.opends.server.util.args.FileBasedArgument

public class FileBasedArgument
extends Argument

This class defines an argument whose value will be read from a file rather than actually specified on the command-line. When a value is specified on the command line, it will be treated as the path to the file containing the actual value rather than the value itself.

Note that if if no filename is provided on the command line but a default value is specified programatically or if the default value is read from a specified property, then that default value will be taken as the actual value rather than a filename.

Also note that this argument type assumes that the entire value for the argument is on a single line in the specified file. If the file contains multiple lines, then only the first line will be read.


Constructor Summary
FileBasedArgument(java.lang.String name, java.lang.Character shortIdentifier, java.lang.String longIdentifier, boolean isRequired, boolean isMultiValued, Message valuePlaceholder, java.lang.String defaultValue, java.lang.String propertyName, Message description)
          Creates a new file-based argument with the provided information.
FileBasedArgument(java.lang.String name, java.lang.Character shortIdentifier, java.lang.String longIdentifier, boolean isRequired, Message valuePlaceholder, Message description)
          Creates a new file-based argument with the provided information.
 
Method Summary
 void addValue(java.lang.String valueString)
          Adds a value to the set of values for this argument.
 java.util.LinkedHashMap<java.lang.String,java.lang.String> getNameToValueMap()
          Retrieves a map between the filenames specified on the command line and the first lines read from those files.
 boolean valueIsAcceptable(java.lang.String valueString, MessageBuilder invalidReason)
          Indicates whether the provided value is acceptable for use in this argument.
 
Methods inherited from class org.opends.server.util.args.Argument
clearValues, getBooleanValue, getDefaultValue, getDescription, getIntValue, getIntValues, getLongIdentifier, getName, getPropertyName, getShortIdentifier, getValue, getValuePlaceholder, getValues, hasValue, isHidden, isMultiValued, isPresent, isRequired, isValueSetByProperty, needsValue, setDefaultValue, setHidden, setMultiValued, setNeedsValue, setPresent, setPropertyName, setRequired, setValuePlaceholder, setValueSetByProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileBasedArgument

public FileBasedArgument(java.lang.String name,
                         java.lang.Character shortIdentifier,
                         java.lang.String longIdentifier,
                         boolean isRequired,
                         Message valuePlaceholder,
                         Message description)
                  throws ArgumentException
Creates a new file-based 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.
valuePlaceholder - The placeholder for the argument value that will be displayed in usage information, or null if this argument does not require a value.
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.

FileBasedArgument

public FileBasedArgument(java.lang.String name,
                         java.lang.Character shortIdentifier,
                         java.lang.String longIdentifier,
                         boolean isRequired,
                         boolean isMultiValued,
                         Message valuePlaceholder,
                         java.lang.String defaultValue,
                         java.lang.String propertyName,
                         Message description)
                  throws ArgumentException
Creates a new file-based 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.
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

getNameToValueMap

public java.util.LinkedHashMap<java.lang.String,java.lang.String> getNameToValueMap()
Retrieves a map between the filenames specified on the command line and the first lines read from those files.

Returns:
A map between the filenames specified on the command line and the first lines read from those files.

valueIsAcceptable

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

Specified by:
valueIsAcceptable in class 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. Note that in this case, correct behavior depends on a previous successful call to valueIsAcceptable so that the value read from the file may be stored in the name-to-value hash and used in place of the filename here.

Overrides:
addValue in class Argument
Parameters:
valueString - The string representation of the value to add to this argument.