ConstrainedProperty (Grails 2.3.8)
Date: 2014-04-24

Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.grails.validation
[Java] Class ConstrainedProperty

    java.lang.Object
      org.codehaus.groovy.grails.validation.ConstrainedProperty

    @java.lang.SuppressWarnings("serial")
    public class ConstrainedProperty
    extends java.lang.Object

Provides the ability to set contraints against a properties of a class. Constraints can either be set via the property setters or via the

    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)`

Authors:
  Graeme Rocher

Since:
  07-Nov-2005

Field Summary
`static java.lang.String` | `BLANK_CONSTRAINT`
`static java.lang.String` | `CREDIT_CARD_CONSTRAINT`
`protected static java.util.Map` | `DEFAULT_MESSAGES`
`static java.lang.String` | `EMAIL_CONSTRAINT`
`protected static java.lang.String` | `EXCEEDED_SUFFIX`
`protected static java.lang.String` | `INVALID_SUFFIX`
`static java.lang.String` | `IN_LIST_CONSTRAINT`
`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`
`static java.lang.String` | `MIN_CONSTRAINT`
`static java.lang.String` | `MIN_SIZE_CONSTRAINT`
`protected static java.lang.String` | `NOTMET_SUFFIX`
`static java.lang.String` | `NOT_EQUAL_CONSTRAINT`
`protected static java.lang.String` | `NOT_PREFIX`
`static java.lang.String` | `NULLABLE_CONSTRAINT`
`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`
`protected java.util.Map` | `appliedConstraints`
`protected static java.util.ResourceBundle` | `bundle`
`protected static java.util.Map` | `constraints`
`protected org.springframework.context.MessageSource` | `messageSource`
`protected java.lang.Class` | `owningClass`
`protected java.lang.String` | `propertyName`
`protected java.lang.Class` | `propertyType`

Constructor Summary
`ConstrainedProperty(java.lang.Class clazz, java.lang.String propertyName, java.lang.Class propertyType)`

Method Summary
`void` | `addMetaConstraint(java.lang.String name, java.lang.Object value)` Obtains the value of the named meta 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)` @param constraintName The name of the constraint to check
`java.util.Collection` | `getAppliedConstraints()` Obtains an applied constraint by name.
`java.util.Map` | `getAttributes()`
`java.lang.String` | `getFormat()`
`java.util.List` | `getInList()` @return Returns the inList.
`java.lang.String` | `getMatches()` @return Returns the matches.
`java.lang.Comparable` | `getMax()`
`java.lang.Integer` | `getMaxSize()`
`java.lang.Object` | `getMetaConstraintValue(java.lang.String name)`
`java.lang.Comparable` | `getMin()` @return Returns the min.
`java.lang.Integer` | `getMinSize()` @return Returns the minSize.
`java.lang.Object` | `getNotEqual()` @return Returns the notEqual.
`int` | `getOrder()` @param order The order to set.
`java.lang.String` | `getPropertyName()` @return Returns the propertyName.
`java.lang.Class` | `getPropertyType()` @return Returns the max.
`groovy.lang.Range` | `getRange()` @return Returns the range.
`java.lang.Integer` | `getScale()` @return The scale, if defined for this property; null, otherwise
`groovy.lang.Range` | `getSize()` @param size The size to set.
`java.lang.String` | `getWidget()`
`boolean` | `hasAppliedConstraint(java.lang.String constraintName)` @return Returns the propertyType.
`static boolean` | `hasRegisteredConstraint(java.lang.String constraintName)` @return Returns the appliedConstraints.
`boolean` | `isBlank()` @return the blank.
`boolean` | `isCreditCard()`
`boolean` | `isDisplay()` @return Returns the display.
`boolean` | `isEditable()` @param editable The editable to set.
`boolean` | `isEmail()` @return Returns the email.
`boolean` | `isNullable()` @return Returns the nullable.
`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, java.lang.Class constraintClass)`
`static void` | `removeConstraint(java.lang.String name)`
`void` | `setAttributes(java.util.Map attributes)`
`void` | `setBlank(boolean blank)`
`void` | `setCreditCard(boolean creditCard)`
`void` | `setDisplay(boolean display)` @return Returns the editable.
`void` | `setEditable(boolean editable)` @return Returns the order.
`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)` @param max The max to set.
`void` | `setMaxSize(java.lang.Integer maxSize)` @param maxSize The maxSize to set.
`void` | `setMessageSource(org.springframework.context.MessageSource source)`
`void` | `setMin(java.lang.Comparable min)` @param min The min to set.
`void` | `setMinSize(java.lang.Integer minSize)` @param minSize The minLength to set.
`void` | `setNotEqual(java.lang.Object notEqual)` @param notEqual The notEqual to set.
`void` | `setNullable(boolean nullable)`
`void` | `setOrder(int order)`
`void` | `setPassword(boolean password)`
`void` | `setPropertyName(java.lang.String propertyName)` @return Returns the url.
`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)`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### BLANK_CONSTRAINT

    public static final java.lang.String BLANK_CONSTRAINT

### CREDIT_CARD_CONSTRAINT

    public static final java.lang.String CREDIT_CARD_CONSTRAINT

### DEFAULT_MESSAGES

    protected static final java.util.Map DEFAULT_MESSAGES

### EMAIL_CONSTRAINT

    public static final java.lang.String EMAIL_CONSTRAINT

### EXCEEDED_SUFFIX

    protected static final java.lang.String EXCEEDED_SUFFIX

### INVALID_SUFFIX

    protected static final java.lang.String INVALID_SUFFIX

### IN_LIST_CONSTRAINT

    public static final java.lang.String IN_LIST_CONSTRAINT

### LOG

    protected static final org.apache.commons.logging.Log LOG

### MATCHES_CONSTRAINT

    public static final java.lang.String MATCHES_CONSTRAINT

### MAX_CONSTRAINT

    public static final java.lang.String MAX_CONSTRAINT

### MAX_SIZE_CONSTRAINT

    public static final java.lang.String MAX_SIZE_CONSTRAINT

### MIN_CONSTRAINT

    public static final java.lang.String MIN_CONSTRAINT

### MIN_SIZE_CONSTRAINT

    public static final java.lang.String MIN_SIZE_CONSTRAINT

### NOTMET_SUFFIX

    protected static final java.lang.String NOTMET_SUFFIX

### NOT_EQUAL_CONSTRAINT

    public static final java.lang.String NOT_EQUAL_CONSTRAINT

### NOT_PREFIX

    protected static final java.lang.String NOT_PREFIX

### NULLABLE_CONSTRAINT

    public static final java.lang.String NULLABLE_CONSTRAINT

### RANGE_CONSTRAINT

    public static final java.lang.String RANGE_CONSTRAINT

### SCALE_CONSTRAINT

    public static final java.lang.String SCALE_CONSTRAINT

### SIZE_CONSTRAINT

    public static final java.lang.String SIZE_CONSTRAINT

### TOOBIG_SUFFIX

    protected static final java.lang.String TOOBIG_SUFFIX

### TOOLONG_SUFFIX

    protected static final java.lang.String TOOLONG_SUFFIX

### TOOSHORT_SUFFIX

    protected static final java.lang.String TOOSHORT_SUFFIX

### TOOSMALL_SUFFIX

    protected static final java.lang.String TOOSMALL_SUFFIX

### URL_CONSTRAINT

    public static final java.lang.String URL_CONSTRAINT

### VALIDATOR_CONSTRAINT

    public static final java.lang.String VALIDATOR_CONSTRAINT

### appliedConstraints

    protected java.util.Map appliedConstraints

### bundle

    protected static final java.util.ResourceBundle bundle

### constraints

    protected static java.util.Map constraints

### messageSource

    protected org.springframework.context.MessageSource messageSource

### owningClass

    protected java.lang.Class owningClass

### propertyName

    protected java.lang.String propertyName

### propertyType

    protected java.lang.Class propertyType

Constructor Detail

### ConstrainedProperty

    public ConstrainedProperty(java.lang.Class clazz, java.lang.String propertyName, java.lang.Class propertyType)

Method Detail

### addMetaConstraint

    public void addMetaConstraint(java.lang.String name, java.lang.Object value)

  Obtains the value of the named meta constraint.
  Parameters:
    `name` - The name of the constraint
  Returns:
    The value

### applyConstraint

    public void applyConstraint(java.lang.String constraintName, java.lang.Object constrainingValue)

  Applies a constraint for the specified name and consraint value.
  throws:
    ConstraintException Thrown when the specified constraint is not supported by this ConstrainedProperty. Use `supportsContraint(String constraintName)` to check before calling
  Parameters:
    `constraintName` - The name of the constraint
    `constrainingValue` - The constraining value

### getAppliedConstraint

    public Constraint getAppliedConstraint(java.lang.String name)

  Parameters:
    `constraintName` - The name of the constraint to check
  Returns:
    Returns true if the specified constraint name is being applied to this property

### getAppliedConstraints

    public java.util.Collection getAppliedConstraints()

  Obtains an applied constraint by name.
  Parameters:
    `name` - The name of the constraint
  Returns:
    The applied constraint

### getAttributes

    @java.lang.SuppressWarningsreturn widget;
    public java.util.Map getAttributes()

### getFormat

    public java.lang.String getFormat()

### getInList

    @java.lang.SuppressWarningspublic void setInList(List inList) {
    public java.util.List getInList()

  Returns:
    Returns the inList.

### getMatches

    public java.lang.String getMatches()

  Returns:
    Returns the matches.

### getMax

    @java.lang.SuppressWarnings
    public java.lang.Comparable getMax()

### getMaxSize

    public java.lang.Integer getMaxSize()

### getMetaConstraintValue

    public java.lang.Object getMetaConstraintValue(java.lang.String name)

### getMin

    @java.lang.SuppressWarnings
    public java.lang.Comparable getMin()

  Returns:
    Returns the min.

### getMinSize

    public java.lang.Integer getMinSize()

  Returns:
    Returns the minSize.

### getNotEqual

    public java.lang.Object getNotEqual()

  Returns:
    Returns the notEqual.

### getOrder

    public int getOrder()

  Parameters:
    `order` - The order to set.

### getPropertyName

    public java.lang.String getPropertyName()

  Returns:
    Returns the propertyName.

### getPropertyType

    public java.lang.Class getPropertyType()

  Returns:
    Returns the max.

### getRange

    @java.lang.SuppressWarningspublic void setRange(Range range) {
    public groovy.lang.Range getRange()

  Returns:
    Returns the range.

### getScale

    public java.lang.Integer getScale()

  Returns:
    The scale, if defined for this property; null, otherwise

### getSize

    @java.lang.SuppressWarningspublic void setSize(Range size) {
    public groovy.lang.Range getSize()

  Parameters:
    `size` - The size to set.

### getWidget

    public java.lang.String getWidget()

### hasAppliedConstraint

    public boolean hasAppliedConstraint(java.lang.String constraintName)

  Returns:
    Returns the propertyType.

### hasRegisteredConstraint

    public static boolean hasRegisteredConstraint(java.lang.String constraintName)

  Returns:
    Returns the appliedConstraints.

### isBlank

    public boolean isBlank()

  Returns:
    the blank.

### isCreditCard

    public boolean isCreditCard()

### isDisplay

    public boolean isDisplay()

  Returns:
    Returns the display.

### isEditable

    public boolean isEditable()

  Parameters:
    `editable` - The editable to set.

### isEmail

    public boolean isEmail()

  Returns:
    Returns the email.

### isNullable

    public boolean isNullable()

  Returns:
    Returns the nullable.

### isPassword

    public boolean isPassword()

### isUrl

    public boolean isUrl()

### registerNewConstraint

    public static void registerNewConstraint(java.lang.String name, java.lang.Class constraintClass)

### registerNewConstraint

    public static void registerNewConstraint(java.lang.String name, ConstraintFactory factory)

### removeConstraint

    public static void removeConstraint(java.lang.String name, java.lang.Class constraintClass)

### removeConstraint

    public static void removeConstraint(java.lang.String name)

### setAttributes

    @java.lang.SuppressWarningsthis.widget = widget;
    public void setAttributes(java.util.Map attributes)

### setBlank

    public void setBlank(boolean blank)

### setCreditCard

    public void setCreditCard(boolean creditCard)

### setDisplay

    public void setDisplay(boolean display)

  Returns:
    Returns the editable.

### setEditable

    public void setEditable(boolean editable)

  Returns:
    Returns the order.

### setEmail

    public void setEmail(boolean email)

### setFormat

    public void setFormat(java.lang.String format)

### setInList

    @java.lang.SuppressWarningsc.setPropertyName(propertyName);
    public void setInList(java.util.List inList)

### setMatches

    public void setMatches(java.lang.String regex)

### setMax

    @java.lang.SuppressWarnings
    public void setMax(java.lang.Comparable max)

  Parameters:
    `max` - The max to set.

### setMaxSize

    public void setMaxSize(java.lang.Integer maxSize)

  Parameters:
    `maxSize` - The maxSize to set.

### setMessageSource

    public void setMessageSource(org.springframework.context.MessageSource source)

### setMin

    @java.lang.SuppressWarnings
    public void setMin(java.lang.Comparable min)

  Parameters:
    `min` - The min to set.

### setMinSize

    public void setMinSize(java.lang.Integer minSize)

  Parameters:
    `minSize` - The minLength to set.

### setNotEqual

    public void setNotEqual(java.lang.Object notEqual)

  Parameters:
    `notEqual` - The notEqual to set.

### setNullable

    public void setNullable(boolean nullable)

### setOrder

    public void setOrder(int order)

### setPassword

    public void setPassword(boolean password)

### setPropertyName

    public void setPropertyName(java.lang.String propertyName)

  Returns:
    Returns the url.

### setRange

    @java.lang.SuppressWarningsif (range == null) {
    public void setRange(groovy.lang.Range range)

### setSize

    @java.lang.SuppressWarningsc.setPropertyName(propertyName);
    public void setSize(groovy.lang.Range size)

### setUrl

    public void setUrl(boolean url)

### setWidget

    public void setWidget(java.lang.String widget)

### supportsContraint

    public boolean supportsContraint(java.lang.String constraintName)

  Checks with this ConstraintedProperty instance supports applying the specified constraint.
  Parameters:
    `constraintName` - The name of the constraint
  Returns:
    true if the constraint is supported

### toString

    @java.lang.Override* @param name The name of the constraint
    public java.lang.String toString()

### validate

    public void validate(java.lang.Object target, java.lang.Object propertyValue, org.springframework.validation.Errors errors)

Groovy Documentation