public class ValidationMetadata
extends java.lang.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.
Constructor and Description |
---|
ValidationMetadata(java.lang.String property)
Constructs a ValidationMetadata object for the specified property.
|
ValidationMetadata(java.lang.String property,
Validate validate)
Essentially a copy constructor that constructs a ValidationMetadata object from
an @Validate annotation declared on a property.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<? extends TypeConverter> |
converter()
Returns the overridden TypeConverter if there is one, or null.
|
ValidationMetadata |
converter(java.lang.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.
|
java.lang.String |
expression()
Returns the overridden TypeConverter if there is one, or null.
|
ValidationMetadata |
expression(java.lang.String expression)
Sets the expression that should be used to validate values.
|
java.lang.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.
|
java.lang.String |
label()
Get the field label.
|
void |
label(java.lang.String label)
Set the field label.
|
java.util.regex.Pattern |
mask()
Returns the mask Pattern property values must match, or null if there is none.
|
ValidationMetadata |
mask(java.lang.String mask)
Sets the mask which the String form of the property must match.
|
java.lang.Integer |
maxlength()
Returns the maximum acceptable length for values, or null if there is none.
|
ValidationMetadata |
maxlength(java.lang.Integer maxlength)
Sets the maximum acceptable length for property values.
|
java.lang.Double |
maxvalue()
Returns the maximum acceptable value for numeric properties, or null if there is none.
|
ValidationMetadata |
maxvalue(java.lang.Double maxvalue)
Sets the maximum acceptable value for numeric property values.
|
java.lang.Integer |
minlength()
Returns the minimum acceptable length for values, or null if there is none.
|
ValidationMetadata |
minlength(java.lang.Integer minlength)
Sets the minimum acceptable length for property values.
|
java.lang.Double |
minvalue()
Returns the minimum acceptable value for numeric properties, or null if there is none.
|
ValidationMetadata |
minvalue(java.lang.Double minvalue)
Sets the minimum acceptable value for numeric property values.
|
java.util.Set<java.lang.String> |
on()
Returns the set of events for which the field in question is required.
|
ValidationMetadata |
on(java.lang.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(java.lang.String event)
Returns true if the field is required when processing the specified event.
|
java.lang.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.
|
public ValidationMetadata(java.lang.String property)
new ValidationMetadata("username").minlength(5).maxlength(10);
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
public ValidationMetadata(java.lang.String property, Validate validate)
validate
- public java.lang.String getProperty()
public ValidationMetadata encrypted(boolean encrypted)
public boolean encrypted()
public ValidationMetadata required(boolean required)
public boolean required()
public ValidationMetadata trim(boolean trim)
public boolean trim()
public boolean requiredOn(java.lang.String event)
public ValidationMetadata ignore(boolean ignore)
public boolean ignore()
public ValidationMetadata minlength(java.lang.Integer minlength)
public java.lang.Integer minlength()
public ValidationMetadata maxlength(java.lang.Integer maxlength)
public java.lang.Integer maxlength()
public ValidationMetadata minvalue(java.lang.Double minvalue)
public java.lang.Double minvalue()
public ValidationMetadata maxvalue(java.lang.Double maxvalue)
public java.lang.Double maxvalue()
public ValidationMetadata mask(java.lang.String mask)
public java.util.regex.Pattern mask()
public ValidationMetadata converter(java.lang.Class<? extends TypeConverter> converter)
public java.lang.Class<? extends TypeConverter> converter()
public ValidationMetadata expression(java.lang.String expression)
public java.lang.String expression()
public ValidationMetadata on(java.lang.String... on)
public java.util.Set<java.lang.String> on()
public void label(java.lang.String label)
public java.lang.String label()
public java.lang.String toString()
toString
in class java.lang.Object
? Copyright 2005-2006, Stripes Development Team.