net.dpml.cli.validation

Class ClassValidator

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);
 
Version:
@PROJECT-VERSION@
Author:
@PUBLISHER-NAME@

Method Summary

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(String name)
Returns whether the specified name is allowed as a Java class name.
void
setClassLoader(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(List values)
Validate each argument value in the specified List against this instances permitted attributes.

Method Details

getClassLoader

public 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.

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.

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.

isPotentialClassName

protected boolean isPotentialClassName(String name)
Returns whether the specified name is allowed as a Java class name.
Parameters:
name - the potential classname
Returns:
true if the name is a potential classname

setClassLoader

public void setClassLoader(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.

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.

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.

validate

public void validate(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 list of values to validate
Throws:
InvalidArgumentException - if a value is invalid
See Also:
net.dpml.cli.validation.Validator.validate(java.util.List)