org.apache.commons.cli2.validation
Class ClassValidator

java.lang.Object
  extended by org.apache.commons.cli2.validation.ClassValidator
All Implemented Interfaces:
Validator

public class ClassValidator
extends java.lang.Object
implements Validator

The ClassValidator validates the string argument values are class names. The following example shows how to validate the 'logger' argument value is a class name, that can be instantiated.

 ...
 ClassValidator validator = new ClassValidator();
 validator.setInstance(true);

 ArgumentBuilder builder = new ArgumentBuilder();
 Argument logger =
     builder.withName("logger");
            .withValidator(validator);
 

Author:
John Keyes

Field Summary
private  boolean instance
          whether to create an instance of the class
private  boolean loadable
          whether the class argument is loadable
private  java.lang.ClassLoader loader
          the classloader to load classes from
private static ResourceHelper resources
          i18n
 
Constructor Summary
ClassValidator()
           
 
Method Summary
 java.lang.ClassLoader getClassLoader()
          Returns the ClassLoader used to resolve and load the classes specified by the argument values.
 boolean isInstance()
          Returns whether the argument value must represent a class that can be instantiated.
 boolean isLoadable()
          Returns whether the argument value must represent a class that is loadable.
protected  boolean isPotentialClassName(java.lang.String name)
          Returns whether the specified name is allowed as a Java class name.
 void setClassLoader(java.lang.ClassLoader loader)
          Specifies the ClassLoader used to resolve and load the classes specified by the argument values.
 void setInstance(boolean instance)
          Specifies whether the argument value must represent a class that can be instantiated.
 void setLoadable(boolean loadable)
          Specifies whether the argument value must represent a class that is loadable.
 void validate(java.util.List values)
          Validate each argument value in the specified List against this instances permitted attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resources

private static final ResourceHelper resources
i18n


loadable

private boolean loadable
whether the class argument is loadable


instance

private boolean instance
whether to create an instance of the class


loader

private java.lang.ClassLoader loader
the classloader to load classes from

Constructor Detail

ClassValidator

public ClassValidator()
Method Detail

validate

public void validate(java.util.List values)
              throws InvalidArgumentException
Validate each argument value in the specified List against this instances permitted attributes. If a value is valid then it's String value in the list is replaced with it's Class value or instance.

Specified by:
validate in interface Validator
Parameters:
values - The values to validate.
Throws:
InvalidArgumentException - If any of the specified values are not valid.
See Also:
Validator.validate(java.util.List)

isLoadable

public boolean isLoadable()
Returns whether the argument value must represent a class that is loadable.

Returns:
whether the argument value must represent a class that is loadable.

setLoadable

public void setLoadable(boolean loadable)
Specifies whether the argument value must represent a class that is loadable.

Parameters:
loadable - whether the argument value must represent a class that is loadable.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the ClassLoader used to resolve and load the classes specified by the argument values.

Returns:
the ClassLoader used to resolve and load the classes specified by the argument values.

setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Specifies the ClassLoader used to resolve and load the classes specified by the argument values.

Parameters:
loader - the ClassLoader used to resolve and load the classes specified by the argument values.

isInstance

public boolean isInstance()
Returns whether the argument value must represent a class that can be instantiated.

Returns:
whether the argument value must represent a class that can be instantiated.

setInstance

public void setInstance(boolean instance)
Specifies whether the argument value must represent a class that can be instantiated.

Parameters:
instance - whether the argument value must represent a class that can be instantiated.

isPotentialClassName

protected boolean isPotentialClassName(java.lang.String name)
Returns whether the specified name is allowed as a Java class name.