de.jstacs.parameters.validation
Class StorableValidator

java.lang.Object
  extended by de.jstacs.parameters.validation.StorableValidator
All Implemented Interfaces:
ParameterValidator, Storable, Cloneable

public class StorableValidator
extends Object
implements ParameterValidator

Class for a validator that validates instances and XML-representations for the correct class types (e.g. AbstractModel

Author:
Jan Grau

Constructor Summary
StorableValidator(Class<? extends Storable> clazz)
          Creates a new ObjectValidator for a subclass of Storable.
StorableValidator(Class<? extends Storable> clazz, boolean trained)
          Creates a new ObjectValidator for a subclass of AbstractModel or AbstractClassifier.
StorableValidator(StringBuffer buf)
          Constructs an ObjectValidator from its XML-representation
 
Method Summary
 boolean checkValue(Object value)
          Checks the value of value.
 StorableValidator clone()
          This method returns a deep copy of the current instance.
 void fromXML(StringBuffer representation)
          Parses a StorableValidator from the XML-representation as returned by toXML().
 String getErrorMessage()
          Returns the error message if checkValue() returned false.
 StringBuffer toXML()
          This method returns an XML-representation of an instance of the implementing class.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StorableValidator

public StorableValidator(Class<? extends Storable> clazz,
                         boolean trained)
                  throws Exception
Creates a new ObjectValidator for a subclass of AbstractModel or AbstractClassifier. This constructor may not be used on other subclasses of Storable

Parameters:
clazz - the class
trained - true if the model or classifier must be trained
Throws:
Exception - an exception is thrown if clazz is not of expected type

StorableValidator

public StorableValidator(Class<? extends Storable> clazz)
                  throws Exception
Creates a new ObjectValidator for a subclass of Storable.

Parameters:
clazz - the class
Throws:
Exception - an exception is thrown if clazz is not of expected type

StorableValidator

public StorableValidator(StringBuffer buf)
                  throws NonParsableException
Constructs an ObjectValidator from its XML-representation

Parameters:
buf - the XML-representation
Throws:
NonParsableException - a NonParsableException is thrown if buf could not be parsed
Method Detail

clone

public StorableValidator clone()
                        throws CloneNotSupportedException
Description copied from interface: ParameterValidator
This method returns a deep copy of the current instance.

Specified by:
clone in interface ParameterValidator
Overrides:
clone in class Object
Returns:
a deep copy
Throws:
CloneNotSupportedException - if the ParameterValidator could not be cloned
See Also:
Cloneable

checkValue

public boolean checkValue(Object value)
Checks the value of value. Allowed types of value are AbstractModel, AbstractClassifier, FileRepresentation, String, and StringBuffer. In all cases where an XML-representation is given as value, it must be surrounded by <object>-tags and these tags must contain a <className>-element that contains the name of the class of the represented instance.

Specified by:
checkValue in interface ParameterValidator
Parameters:
value - the value to be checked.
Returns:
if the value is valid

getErrorMessage

public String getErrorMessage()
Description copied from interface: ParameterValidator
Returns the error message if checkValue() returned false.

Specified by:
getErrorMessage in interface ParameterValidator
Returns:
the error message

toXML

public StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML-representation of an instance of the implementing class.

Specified by:
toXML in interface Storable
Returns:
the XML-representation

fromXML

public void fromXML(StringBuffer representation)
             throws NonParsableException
Parses a StorableValidator from the XML-representation as returned by toXML().

Parameters:
representation - the XML-representation
Throws:
NonParsableException - thrown if the XML-code could not be parsed