net.dpml.cli.validation
Class FileValidator

java.lang.Object
  extended by net.dpml.cli.validation.FileValidator
All Implemented Interfaces:
Validator

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 List of values is replaced with the 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:
1.0.0
Author:
Digital Product Meta Library

Constructor Summary
FileValidator()
           
 
Method Summary
static FileValidator getExistingDirectoryInstance()
          Returns a FileValidator for existing directories.
static FileValidator getExistingFileInstance()
          Returns a FileValidator for existing files.
static FileValidator getExistingInstance()
          Returns a FileValidator for existing files/directories.
 boolean isDirectory()
          Returns whether the argument values must represent directories.
 boolean isExisting()
          Returns whether the argument values must represent existing files/directories.
 boolean isFile()
          Returns whether the argument values must represent directories.
 void setDirectory(boolean directory)
          Specifies whether the argument values must represent directories.
 void setExisting(boolean existing)
          Specifies whether the argument values must represent existing files/directories.
 void setFile(boolean file)
          Specifies whether the argument values must represent files.
 void validate(List values)
          Validate the list of values against the list of permitted values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileValidator

public FileValidator()
Method Detail

getExistingInstance

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

Returns:
a FileValidator for existing files/directories.

getExistingFileInstance

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

Returns:
a FileValidator for existing files.

getExistingDirectoryInstance

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

Returns:
a FileValidator for existing directories.

validate

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

Specified by:
validate in interface Validator
Parameters:
values - the list of values to validate
Throws:
InvalidArgumentException - if a value is invalid
See Also:
Validator.validate(java.util.List)

isDirectory

public boolean isDirectory()
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.

isExisting

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

Returns:
whether the argument values must represent existing files/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.

isFile

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

Returns:
whether the argument values must represent 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.