net.dpml.cli.validation

Class FileValidator

public class FileValidator extends Object implements Validator

The FileValidator validates the string argument values are files. If the value is a file, the string value in the java.util.List of values is replaced with the java.io.File instance. The following attributes can also be specified using the appropriate settors: The following example shows how to limit the valid values for the config attribute to files that exist.
 ...
 ArgumentBuilder builder = new ArgumentBuilder();
 FileValidator validator = FileValidator.getExistingFileInstance();
 Argument age = 
     builder.withName("config");
            .withValidator(validator);
 

Version: @PROJECT-VERSION@

Author: @PUBLISHER-NAME@

Method Summary
static FileValidatorgetExistingDirectoryInstance()
Returns a FileValidator for existing directories.
static FileValidatorgetExistingFileInstance()
Returns a FileValidator for existing files.
static FileValidatorgetExistingInstance()
Returns a FileValidator for existing files/directories.
booleanisDirectory()
Returns whether the argument values must represent directories.
booleanisExisting()
Returns whether the argument values must represent existing files/directories.
booleanisFile()
Returns whether the argument values must represent directories.
voidsetDirectory(boolean directory)
Specifies whether the argument values must represent directories.
voidsetExisting(boolean existing)
Specifies whether the argument values must represent existing files/directories.
voidsetFile(boolean file)
Specifies whether the argument values must represent files.
voidvalidate(List values)
Validate the list of values against the list of permitted values.

Method Detail

getExistingDirectoryInstance

public static FileValidator getExistingDirectoryInstance()
Returns a FileValidator for existing directories.

Returns: a FileValidator for existing directories.

getExistingFileInstance

public static FileValidator getExistingFileInstance()
Returns a FileValidator for existing files.

Returns: a FileValidator for existing files.

getExistingInstance

public static FileValidator getExistingInstance()
Returns a FileValidator for existing files/directories.

Returns: a FileValidator for existing files/directories.

isDirectory

public boolean isDirectory()
Returns whether the argument values must represent directories.

Returns: whether the argument values must represent directories.

isExisting

public boolean isExisting()
Returns whether the argument values must represent existing files/directories.

Returns: whether the argument values must represent existing files/directories.

isFile

public boolean isFile()
Returns whether the argument values must represent directories.

Returns: whether the argument values must represent directories.

setDirectory

public void setDirectory(boolean directory)
Specifies whether the argument values must represent directories.

Parameters: directory specifies whether the argument values must represent directories.

setExisting

public void setExisting(boolean existing)
Specifies whether the argument values must represent existing files/directories.

Parameters: existing specifies whether the argument values must represent existing files/directories.

setFile

public void setFile(boolean file)
Specifies whether the argument values must represent files.

Parameters: file specifies whether the argument values must represent files.

validate

public void validate(List values)
Validate the list of values against the list of permitted values. If a value is valid, replace the string in the values java.util.List with the java.io.File instance.

Parameters: values the list of values to validate

Throws: InvalidArgumentException if a value is invalid

See Also: validate