public class ConstrainedProperty
extends java.lang.Object
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 |
---|---|
static java.lang.String |
BLANK_CONSTRAINT |
static java.lang.String |
CREDIT_CARD_CONSTRAINT |
static java.lang.String |
EMAIL_CONSTRAINT |
static java.lang.String |
IN_LIST_CONSTRAINT |
static java.lang.String |
MATCHES_CONSTRAINT |
static java.lang.String |
MAX_CONSTRAINT |
static java.lang.String |
MAX_SIZE_CONSTRAINT |
static java.lang.String |
MIN_CONSTRAINT |
static java.lang.String |
MIN_SIZE_CONSTRAINT |
static java.lang.String |
NOT_EQUAL_CONSTRAINT |
static java.lang.String |
NULLABLE_CONSTRAINT |
static java.lang.String |
RANGE_CONSTRAINT |
static java.lang.String |
SCALE_CONSTRAINT |
static java.lang.String |
SIZE_CONSTRAINT |
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.String |
getPropertyName() |
java.lang.Class<?> |
getPropertyType() |
Range |
getRange() |
java.lang.Integer |
getScale() |
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(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(Range range) |
void |
setSize(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,
Errors errors)
Validate this constrainted property against specified property value
|
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
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)
constraintName
- The name of the constraint to checkpublic java.lang.Class<?> getPropertyType()
public java.lang.Comparable getMax()
public void setMax(java.lang.Comparable max)
max
- The max to set.public java.lang.Comparable getMin()
public void setMin(java.lang.Comparable min)
min
- The min to set.public java.util.List getInList()
public void setInList(java.util.List inList)
inList
- The inList to set.public Range getRange()
public void setRange(Range range)
range
- The range to set.public java.lang.Integer getScale()
public Range getSize()
public void setSize(Range size)
size
- The size to set.public boolean isBlank()
public void setBlank(boolean blank)
blank
- The blank to set.public boolean isEmail()
public void setEmail(boolean email)
email
- The email to set.public boolean isCreditCard()
public void setCreditCard(boolean creditCard)
creditCard
- The creditCard to set.public java.lang.String getMatches()
public void setMatches(java.lang.String regex)
regex
- The matches to set.public java.lang.Object getNotEqual()
public java.lang.Integer getMaxSize()
public void setMaxSize(java.lang.Integer maxSize)
maxSize
- The maxSize to set.public java.lang.Integer getMinSize()
public 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()
public 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()
public void setUrl(boolean url)
url
- The url to set.public boolean isDisplay()
public void setDisplay(boolean display)
display
- The display to set.public boolean isEditable()
public void setEditable(boolean editable)
editable
- The editable to set.public int getOrder()
public void setOrder(int order)
order
- The order to set.public java.lang.String getFormat()
public void setFormat(java.lang.String format)
public boolean isPassword()
public 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(MessageSource source)
source
- The MessageSource instance to use to resolve messagespublic void validate(java.lang.Object target, java.lang.Object propertyValue, 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)
constraintName
- The name of the constraintpublic void applyConstraint(java.lang.String constraintName, java.lang.Object constrainingValue)
constraintName
- 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.String toString()
toString
in class java.lang.Object
public 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