public class ConstrainedProperty
extends java.lang.Object
implements grails.validation.Constrained
applyConstraint(String constraintName, Object constrainingValue)in combination with a constraint constant. Example:
...
ConstrainedProperty cp = new ConstrainedProperty(owningClass, propertyName, propertyType);
if (cp.supportsConstraint(ConstrainedProperty.EMAIL_CONSTRAINT)) {
cp.applyConstraint(ConstrainedProperty.EMAIL_CONSTRAINT, new Boolean(true));
}
Alternatively constraints can be applied directly using the java bean getters/setters if a static (as oposed to dynamic)
approach to constraint creation is possible:
cp.setEmail(true)
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,Constraint> |
appliedConstraints |
static java.lang.String |
BLANK_CONSTRAINT |
protected static java.util.ResourceBundle |
bundle |
protected static java.util.Map<java.lang.String,java.util.List<java.lang.Object>> |
constraints |
static java.lang.String |
CREDIT_CARD_CONSTRAINT |
protected static java.util.Map<java.lang.String,java.lang.String> |
DEFAULT_MESSAGES |
static java.lang.String |
EMAIL_CONSTRAINT |
protected static java.lang.String |
EXCEEDED_SUFFIX |
static java.lang.String |
IN_LIST_CONSTRAINT |
protected static java.lang.String |
INVALID_SUFFIX |
protected static org.apache.commons.logging.Log |
LOG |
static java.lang.String |
MATCHES_CONSTRAINT |
static java.lang.String |
MAX_CONSTRAINT |
static java.lang.String |
MAX_SIZE_CONSTRAINT |
protected org.springframework.context.MessageSource |
messageSource |
static java.lang.String |
MIN_CONSTRAINT |
static java.lang.String |
MIN_SIZE_CONSTRAINT |
static java.lang.String |
NOT_EQUAL_CONSTRAINT |
protected static java.lang.String |
NOT_PREFIX |
protected static java.lang.String |
NOTMET_SUFFIX |
static java.lang.String |
NULLABLE_CONSTRAINT |
protected java.lang.Class<?> |
owningClass |
protected java.lang.String |
propertyName |
protected java.lang.Class<?> |
propertyType |
static java.lang.String |
RANGE_CONSTRAINT |
static java.lang.String |
SCALE_CONSTRAINT |
static java.lang.String |
SIZE_CONSTRAINT |
protected static java.lang.String |
TOOBIG_SUFFIX |
protected static java.lang.String |
TOOLONG_SUFFIX |
protected static java.lang.String |
TOOSHORT_SUFFIX |
protected static java.lang.String |
TOOSMALL_SUFFIX |
static java.lang.String |
URL_CONSTRAINT |
static java.lang.String |
VALIDATOR_CONSTRAINT |
| Constructor and Description |
|---|
ConstrainedProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<?> propertyType)
Constructs a new ConstrainedProperty for the given arguments.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addMetaConstraint(java.lang.String name,
java.lang.Object value)
Adds a meta constraints which is a non-validating informational constraint.
|
void |
applyConstraint(java.lang.String constraintName,
java.lang.Object constrainingValue)
Applies a constraint for the specified name and consraint value.
|
Constraint |
getAppliedConstraint(java.lang.String name)
Obtains an applied constraint by name.
|
java.util.Collection<Constraint> |
getAppliedConstraints() |
java.util.Map |
getAttributes() |
java.lang.String |
getFormat() |
java.util.List |
getInList() |
java.lang.String |
getMatches() |
java.lang.Comparable |
getMax() |
java.lang.Integer |
getMaxSize() |
java.lang.Object |
getMetaConstraintValue(java.lang.String name)
Obtains the value of the named meta constraint.
|
java.lang.Comparable |
getMin() |
java.lang.Integer |
getMinSize() |
java.lang.Object |
getNotEqual() |
int |
getOrder() |
java.lang.Class |
getOwner() |
java.lang.String |
getPropertyName() |
java.lang.Class<?> |
getPropertyType() |
groovy.lang.Range |
getRange() |
java.lang.Integer |
getScale() |
groovy.lang.Range |
getSize() |
java.lang.String |
getWidget() |
boolean |
hasAppliedConstraint(java.lang.String constraintName) |
static boolean |
hasRegisteredConstraint(java.lang.String constraintName) |
boolean |
isBlank() |
boolean |
isCreditCard() |
boolean |
isDisplay() |
boolean |
isEditable() |
boolean |
isEmail() |
boolean |
isNullable() |
boolean |
isPassword() |
boolean |
isUrl() |
static void |
registerNewConstraint(java.lang.String name,
java.lang.Class<?> constraintClass) |
static void |
registerNewConstraint(java.lang.String name,
ConstraintFactory factory) |
static void |
removeConstraint(java.lang.String name) |
static void |
removeConstraint(java.lang.String name,
java.lang.Class<?> constraintClass) |
void |
setAttributes(java.util.Map attributes) |
void |
setBlank(boolean blank) |
void |
setCreditCard(boolean creditCard) |
void |
setDisplay(boolean display) |
void |
setEditable(boolean editable) |
void |
setEmail(boolean email) |
void |
setFormat(java.lang.String format) |
void |
setInList(java.util.List inList) |
void |
setMatches(java.lang.String regex) |
void |
setMax(java.lang.Comparable max) |
void |
setMaxSize(java.lang.Integer maxSize) |
void |
setMessageSource(org.springframework.context.MessageSource source)
The message source used to evaluate error messages
|
void |
setMin(java.lang.Comparable min) |
void |
setMinSize(java.lang.Integer minSize) |
void |
setNotEqual(java.lang.Object notEqual) |
void |
setNullable(boolean nullable) |
void |
setOrder(int order) |
void |
setPassword(boolean password) |
void |
setPropertyName(java.lang.String propertyName) |
void |
setRange(groovy.lang.Range range) |
void |
setSize(groovy.lang.Range size) |
void |
setUrl(boolean url) |
void |
setWidget(java.lang.String widget) |
boolean |
supportsContraint(java.lang.String constraintName)
Checks with this ConstraintedProperty instance supports applying the specified constraint.
|
java.lang.String |
toString() |
void |
validate(java.lang.Object target,
java.lang.Object propertyValue,
org.springframework.validation.Errors errors)
Validate this constrainted property against specified property value
|
protected static final java.util.ResourceBundle bundle
public static final java.lang.String CREDIT_CARD_CONSTRAINT
public static final java.lang.String EMAIL_CONSTRAINT
public static final java.lang.String BLANK_CONSTRAINT
public static final java.lang.String RANGE_CONSTRAINT
public static final java.lang.String IN_LIST_CONSTRAINT
public static final java.lang.String URL_CONSTRAINT
public static final java.lang.String MATCHES_CONSTRAINT
public static final java.lang.String SIZE_CONSTRAINT
public static final java.lang.String MIN_CONSTRAINT
public static final java.lang.String MAX_CONSTRAINT
public static final java.lang.String MAX_SIZE_CONSTRAINT
public static final java.lang.String MIN_SIZE_CONSTRAINT
public static final java.lang.String SCALE_CONSTRAINT
public static final java.lang.String NOT_EQUAL_CONSTRAINT
public static final java.lang.String NULLABLE_CONSTRAINT
public static final java.lang.String VALIDATOR_CONSTRAINT
protected static final java.lang.String INVALID_SUFFIX
protected static final java.lang.String EXCEEDED_SUFFIX
protected static final java.lang.String NOTMET_SUFFIX
protected static final java.lang.String NOT_PREFIX
protected static final java.lang.String TOOBIG_SUFFIX
protected static final java.lang.String TOOLONG_SUFFIX
protected static final java.lang.String TOOSMALL_SUFFIX
protected static final java.lang.String TOOSHORT_SUFFIX
protected static java.util.Map<java.lang.String,java.util.List<java.lang.Object>> constraints
protected static final java.util.Map<java.lang.String,java.lang.String> DEFAULT_MESSAGES
protected static final org.apache.commons.logging.Log LOG
protected java.lang.String propertyName
protected java.lang.Class<?> propertyType
protected java.util.Map<java.lang.String,Constraint> appliedConstraints
protected java.lang.Class<?> owningClass
protected org.springframework.context.MessageSource messageSource
public ConstrainedProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<?> propertyType)
clazz - The owning classpropertyName - The name of the propertypropertyType - The property typepublic static void removeConstraint(java.lang.String name,
java.lang.Class<?> constraintClass)
public static void removeConstraint(java.lang.String name)
public static void registerNewConstraint(java.lang.String name,
java.lang.Class<?> constraintClass)
public static void registerNewConstraint(java.lang.String name,
ConstraintFactory factory)
public static boolean hasRegisteredConstraint(java.lang.String constraintName)
public java.util.Collection<Constraint> getAppliedConstraints()
public Constraint getAppliedConstraint(java.lang.String name)
name - The name of the constraintpublic boolean hasAppliedConstraint(java.lang.String constraintName)
hasAppliedConstraint in interface grails.validation.ConstrainedconstraintName - The name of the constraint to checkpublic java.lang.Class<?> getPropertyType()
getPropertyType in interface grails.validation.Constrainedpublic java.lang.Comparable getMax()
getMax in interface grails.validation.Constrainedpublic void setMax(java.lang.Comparable max)
max - The max to set.public java.lang.Comparable getMin()
getMin in interface grails.validation.Constrainedpublic void setMin(java.lang.Comparable min)
min - The min to set.public java.util.List getInList()
getInList in interface grails.validation.Constrainedpublic void setInList(java.util.List inList)
inList - The inList to set.public groovy.lang.Range getRange()
getRange in interface grails.validation.Constrainedpublic void setRange(groovy.lang.Range range)
range - The range to set.public java.lang.Integer getScale()
getScale in interface grails.validation.Constrainedpublic groovy.lang.Range getSize()
getSize in interface grails.validation.Constrainedpublic void setSize(groovy.lang.Range size)
size - The size to set.public boolean isBlank()
isBlank in interface grails.validation.Constrainedpublic void setBlank(boolean blank)
blank - The blank to set.public boolean isEmail()
isEmail in interface grails.validation.Constrainedpublic void setEmail(boolean email)
email - The email to set.public boolean isCreditCard()
isCreditCard in interface grails.validation.Constrainedpublic void setCreditCard(boolean creditCard)
creditCard - The creditCard to set.public java.lang.String getMatches()
getMatches in interface grails.validation.Constrainedpublic void setMatches(java.lang.String regex)
regex - The matches to set.public java.lang.Object getNotEqual()
getNotEqual in interface grails.validation.Constrainedpublic java.lang.Integer getMaxSize()
getMaxSize in interface grails.validation.Constrainedpublic void setMaxSize(java.lang.Integer maxSize)
maxSize - The maxSize to set.public java.lang.Integer getMinSize()
getMinSize in interface grails.validation.Constrainedpublic void setMinSize(java.lang.Integer minSize)
minSize - The minLength to set.public void setNotEqual(java.lang.Object notEqual)
notEqual - The notEqual to set.public boolean isNullable()
isNullable in interface grails.validation.Constrainedpublic void setNullable(boolean nullable)
nullable - The nullable to set.public java.lang.String getPropertyName()
public void setPropertyName(java.lang.String propertyName)
propertyName - The propertyName to set.public boolean isUrl()
isUrl in interface grails.validation.Constrainedpublic void setUrl(boolean url)
url - The url to set.public boolean isDisplay()
isDisplay in interface grails.validation.Constrainedpublic void setDisplay(boolean display)
display - The display to set.public boolean isEditable()
isEditable in interface grails.validation.Constrainedpublic void setEditable(boolean editable)
editable - The editable to set.public int getOrder()
getOrder in interface grails.validation.Constrainedpublic void setOrder(int order)
order - The order to set.public java.lang.String getFormat()
getFormat in interface grails.validation.Constrainedpublic void setFormat(java.lang.String format)
public boolean isPassword()
isPassword in interface grails.validation.Constrainedpublic void setPassword(boolean password)
public java.util.Map getAttributes()
public void setAttributes(java.util.Map attributes)
public java.lang.String getWidget()
public void setWidget(java.lang.String widget)
public void setMessageSource(org.springframework.context.MessageSource source)
source - The MessageSource instance to use to resolve messagespublic void validate(java.lang.Object target,
java.lang.Object propertyValue,
org.springframework.validation.Errors errors)
target - The target object to validatepropertyValue - The value of the property to validateerrors - The Errors instances to report errors topublic boolean supportsContraint(java.lang.String constraintName)
supportsContraint in interface grails.validation.ConstrainedconstraintName - The name of the constraintpublic void applyConstraint(java.lang.String constraintName,
java.lang.Object constrainingValue)
applyConstraint in interface grails.validation.ConstrainedconstraintName - The name of the constraintconstrainingValue - The constraining valueConstraintException - Thrown when the specified constraint is not supported by this ConstrainedProperty. Use supportsContraint(String constraintName) to check before callingpublic java.lang.Class getOwner()
getOwner in interface grails.validation.Constrainedpublic java.lang.String toString()
toString in class java.lang.Objectpublic void addMetaConstraint(java.lang.String name,
java.lang.Object value)
name - The name of the constraintvalue - The valuepublic java.lang.Object getMetaConstraintValue(java.lang.String name)
name - The name of the constraint