net.sourceforge.stripes.validation
Class ValidationMetadata

java.lang.Object
  extended by net.sourceforge.stripes.validation.ValidationMetadata

public class ValidationMetadata
extends Object

Encapsulates the validation metadata for a single property of a single class. Structure is purposely very similar to the @Validate annotation. This class is used internally to store and manipulate validation metadata, the source of which is often validation annotations.

However, since this class is not an annotation it has the added benefits of being able to contain behaviour, being subclassable, and of being able to be instantiated at runtime - i.e. it can contain non-static validation information.

Since:
Stripes 1.5
Author:
Tim Fennell

Constructor Summary
ValidationMetadata(String property)
          Constructs a ValidationMetadata object for the specified property.
ValidationMetadata(String property, Validate validate)
          Essentially a copy constructor that constructs a ValidationMetadata object from an @Validate annotation declared on a property.
 
Method Summary
 Class<? extends TypeConverter> converter()
          Returns the overridden TypeConverter if there is one, or null.
 ValidationMetadata converter(Class<? extends TypeConverter> converter)
          Sets the overridden TypeConveter to use to convert values.
 boolean encrypted()
          Returns true if the field in question is encrypted.
 ValidationMetadata encrypted(boolean encrypted)
          Sets the encrypted flag for this field.
 String expression()
          Returns the overridden TypeConverter if there is one, or null.
 ValidationMetadata expression(String expression)
          Sets the expression that should be used to validate values.
 String getProperty()
          Returns the name of the property this validation metadata represents.
 boolean ignore()
          Returns true if this field should be ignored in binding and validation.
 ValidationMetadata ignore(boolean ignore)
          Sets whether or not this field should be ignored during binding and validation.
 String label()
          Get the field label.
 void label(String label)
          Set the field label.
 Pattern mask()
          Returns the mask Pattern property values must match, or null if there is none.
 ValidationMetadata mask(String mask)
          Sets the mask which the String form of the property must match.
 Integer maxlength()
          Returns the maximum acceptable length for values, or null if there is none.
 ValidationMetadata maxlength(Integer maxlength)
          Sets the maximum acceptable length for property values.
 Double maxvalue()
          Returns the maximum acceptable value for numeric properties, or null if there is none.
 ValidationMetadata maxvalue(Double maxvalue)
          Sets the maximum acceptable value for numeric property values.
 Integer minlength()
          Returns the minimum acceptable length for values, or null if there is none.
 ValidationMetadata minlength(Integer minlength)
          Sets the minimum acceptable length for property values.
 Double minvalue()
          Returns the minimum acceptable value for numeric properties, or null if there is none.
 ValidationMetadata minvalue(Double minvalue)
          Sets the minimum acceptable value for numeric property values.
 Set<String> on()
          Returns the set of events for which the field in question is required.
 ValidationMetadata on(String... on)
          Sets the set of events for which the field in question is required, if it is at all.
 boolean required()
          Returns true if the field in question is required.
 ValidationMetadata required(boolean required)
          Sets the required-ness of this field.
 boolean requiredOn(String event)
          Returns true if the field is required when processing the specified event.
 String toString()
          Overidden toString() that only outputs the constraints that are specified by the instance of validation metadata (i.e.
 boolean trim()
          Returns true if the field should be trimmed before validation or type conversion.
 ValidationMetadata trim(boolean trim)
          Sets the trim flag of this field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValidationMetadata

public ValidationMetadata(String property)
Constructs a ValidationMetadata object for the specified property. Further constraints can be specified by calling individual methods, e.g. new ValidationMetadata("username").minlength(5).maxlength(10);

Parameters:
property - the name of the property to be validated. If the property is a nested property then the fully path should be included, e.g. user.address.city

ValidationMetadata

public ValidationMetadata(String property,
                          Validate validate)
Essentially a copy constructor that constructs a ValidationMetadata object from an @Validate annotation declared on a property.

Parameters:
validate -
Method Detail

getProperty

public String getProperty()
Returns the name of the property this validation metadata represents.


encrypted

public ValidationMetadata encrypted(boolean encrypted)
Sets the encrypted flag for this field. True = encrypted, false = plain text.


encrypted

public boolean encrypted()
Returns true if the field in question is encrypted.


required

public ValidationMetadata required(boolean required)
Sets the required-ness of this field. True = required, false = not required.


required

public boolean required()
Returns true if the field in question is required.


trim

public ValidationMetadata trim(boolean trim)
Sets the trim flag of this field. True = trim, false = don't trim.


trim

public boolean trim()
Returns true if the field should be trimmed before validation or type conversion.


requiredOn

public boolean requiredOn(String event)
Returns true if the field is required when processing the specified event.


ignore

public ValidationMetadata ignore(boolean ignore)
Sets whether or not this field should be ignored during binding and validation.


ignore

public boolean ignore()
Returns true if this field should be ignored in binding and validation.


minlength

public ValidationMetadata minlength(Integer minlength)
Sets the minimum acceptable length for property values.


minlength

public Integer minlength()
Returns the minimum acceptable length for values, or null if there is none.


maxlength

public ValidationMetadata maxlength(Integer maxlength)
Sets the maximum acceptable length for property values.


maxlength

public Integer maxlength()
Returns the maximum acceptable length for values, or null if there is none.


minvalue

public ValidationMetadata minvalue(Double minvalue)
Sets the minimum acceptable value for numeric property values.


minvalue

public Double minvalue()
Returns the minimum acceptable value for numeric properties, or null if there is none.


maxvalue

public ValidationMetadata maxvalue(Double maxvalue)
Sets the maximum acceptable value for numeric property values.


maxvalue

public Double maxvalue()
Returns the maximum acceptable value for numeric properties, or null if there is none.


mask

public ValidationMetadata mask(String mask)
Sets the mask which the String form of the property must match.


mask

public Pattern mask()
Returns the mask Pattern property values must match, or null if there is none.


converter

public ValidationMetadata converter(Class<? extends TypeConverter> converter)
Sets the overridden TypeConveter to use to convert values.


converter

public Class<? extends TypeConverter> converter()
Returns the overridden TypeConverter if there is one, or null.


expression

public ValidationMetadata expression(String expression)
Sets the expression that should be used to validate values.


expression

public String expression()
Returns the overridden TypeConverter if there is one, or null.


on

public ValidationMetadata on(String... on)
Sets the set of events for which the field in question is required, if it is at all.


on

public Set<String> on()
Returns the set of events for which the field in question is required. May return null.


label

public void label(String label)
Set the field label.


label

public String label()
Get the field label.


toString

public String toString()
Overidden toString() that only outputs the constraints that are specified by the instance of validation metadata (i.e. omits nulls, defaults etc.)

Overrides:
toString in class Object
Returns:
a human readable string form of the metadata


? Copyright 2005-2006, Stripes Development Team.