Package: grails.validation

## [Java] Class ConstrainedProperty

- grails.validation.ConstrainedProperty

- All Implemented Interfaces and Traits:
    Constrained

      @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

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static java.lang.String` | `BLANK_CONSTRAINT` |
    `static java.lang.String` | `CREDIT_CARD_CONSTRAINT` |
    `static java.lang.String` | `DEFAULT_BLANK_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_DOESNT_MATCH_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_EMAIL_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_MAX_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_MIN_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_RANGE_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_SIZE_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_URL_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE` |
    `protected static java.util.Map<java.lang.String, java.lang.String>` | `DEFAULT_MESSAGES` |
    `static java.lang.String` | `DEFAULT_NOT_EQUAL_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_NOT_INLIST_MESSAGE_CODE` |
    `static java.lang.String` | `DEFAULT_NULL_MESSAGE_CODE` |
    `static java.lang.String` | `EMAIL_CONSTRAINT` |
    `static java.lang.String` | `EXCEEDED_SUFFIX` |
    `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` |
    `static java.lang.String` | `NOTMET_SUFFIX` |
    `static java.lang.String` | `NOT_EQUAL_CONSTRAINT` |
    `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` |
    `static java.lang.String` | `TOOBIG_SUFFIX` |
    `static java.lang.String` | `TOOLONG_SUFFIX` |
    `static java.lang.String` | `TOOSHORT_SUFFIX` |
    `static java.lang.String` | `TOOSMALL_SUFFIX` |
    `static java.lang.String` | `URL_CONSTRAINT` |
    `static java.lang.String` | `VALIDATOR_CONSTRAINT` |
    `protected java.util.Map<java.lang.String, Constraint>` | `appliedConstraints` |
    `protected static java.util.ResourceBundle` | `bundle` |
    `protected static java.util.Map<java.lang.String, java.util.List<java.lang.Object>>` | `constraints` |
    `protected org.springframework.context.MessageSource` | `messageSource` |
    `protected java.lang.Class<?>` | `owningClass` |
    `protected java.lang.String` | `propertyName` |
    `protected java.lang.Class<?>` | `propertyType` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ConstrainedProperty (java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> propertyType)` Constructs a new ConstrainedProperty for the given arguments.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name 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()` @return Returns the appliedConstraints.
    `` | `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()` @return Returns the max.
    `` | `java.lang.Integer` | `getMaxSize()` @return Returns the maxSize.
    `` | `java.lang.Object` | `getMetaConstraintValue(java.lang.String name)` Obtains the value of the named meta constraint.
    `` | `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()` @return Returns the order.
    `` | `java.lang.Class` | `getOwner()`
    `` | `java.lang.String` | `getPropertyName()` @return Returns the propertyName.
    `` | `java.lang.Class<?>` | `getPropertyType()` @return Returns the propertyType.
    `` | `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()` @return Returns the size.
    `` | `java.lang.String` | `getWidget()`
    `` | `boolean` | `hasAppliedConstraint(java.lang.String constraintName)` @param constraintName The name of the constraint to check
    `` | `static boolean` | `hasRegisteredConstraint(java.lang.String constraintName)`
    `` | `boolean` | `isBlank()` @return the blank.
    `` | `boolean` | `isCreditCard()` @return Returns the creditCard.
    `` | `boolean` | `isDisplay()` @return Returns the display.
    `` | `boolean` | `isEditable()` @return Returns the editable.
    `` | `boolean` | `isEmail()` @return Returns the email.
    `` | `boolean` | `isNullable()` @return Returns the nullable.
    `` | `boolean` | `isPassword()`
    `` | `boolean` | `isUrl()` @return Returns the url.
    `` | `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)` @param blank The blank to set.
    `` | `void` | `setCreditCard(boolean creditCard)` @param creditCard The creditCard to set.
    `` | `void` | `setDisplay(boolean display)` @param display The display to set.
    `` | `void` | `setEditable(boolean editable)` @param editable The editable to set.
    `` | `void` | `setEmail(boolean email)` @param email The email to set.
    `` | `void` | `setFormat(java.lang.String format)`
    `` | `void` | `setInList(java.util.List inList)` @param inList The inList to set.
    `` | `void` | `setMatches(java.lang.String regex)` @param regex The matches to set.
    `` | `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)` The message source used to evaluate error messages
    `` | `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)` @param nullable The nullable to set.
    `` | `void` | `setOrder(int order)` @param order The order to set.
    `` | `void` | `setPassword(boolean password)`
    `` | `void` | `setPropertyName(java.lang.String propertyName)` @param propertyName The propertyName to set.
    `` | `void` | `setRange(groovy.lang.Range range)` @param range The range to set.
    `` | `void` | `setSize(groovy.lang.Range size)` @param size The size to set.
    `` | `void` | `setUrl(boolean url)` @param url The url to set.
    `` | `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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `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

    - #### public static final java.lang.String BLANK_CONSTRAINT

    - #### public static final java.lang.String CREDIT_CARD_CONSTRAINT

    - #### public static final java.lang.String DEFAULT_BLANK_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_DOESNT_MATCH_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_EMAIL_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_MAX_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_MIN_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_RANGE_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_SIZE_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_URL_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE

    - #### protected static final java.util.Map<java.lang.String, java.lang.String> DEFAULT_MESSAGES

    - #### public static final java.lang.String DEFAULT_NOT_EQUAL_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_NOT_INLIST_MESSAGE_CODE

    - #### public static final java.lang.String DEFAULT_NULL_MESSAGE_CODE

    - #### public static final java.lang.String EMAIL_CONSTRAINT

    - #### public static final java.lang.String EXCEEDED_SUFFIX

    - #### public static final java.lang.String INVALID_SUFFIX

    - #### public static final java.lang.String IN_LIST_CONSTRAINT

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

    - #### public static final java.lang.String MATCHES_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_CONSTRAINT

    - #### public static final java.lang.String MIN_SIZE_CONSTRAINT

    - #### public static final java.lang.String NOTMET_SUFFIX

    - #### public static final java.lang.String NOT_EQUAL_CONSTRAINT

    - #### public static final java.lang.String NOT_PREFIX

    - #### public static final java.lang.String NULLABLE_CONSTRAINT

    - #### public static final java.lang.String RANGE_CONSTRAINT

    - #### public static final java.lang.String SCALE_CONSTRAINT

    - #### public static final java.lang.String SIZE_CONSTRAINT

    - #### public static final java.lang.String TOOBIG_SUFFIX

    - #### public static final java.lang.String TOOLONG_SUFFIX

    - #### public static final java.lang.String TOOSHORT_SUFFIX

    - #### public static final java.lang.String TOOSMALL_SUFFIX

    - #### public static final java.lang.String URL_CONSTRAINT

    - #### public static final java.lang.String VALIDATOR_CONSTRAINT

    - #### protected java.util.Map<java.lang.String, Constraint> appliedConstraints

    - #### protected static final java.util.ResourceBundle bundle

    - #### protected static java.util.Map<java.lang.String, java.util.List<java.lang.Object>> constraints

    - #### protected org.springframework.context.MessageSource messageSource

    - #### protected java.lang.Class<?> owningClass

    - #### protected java.lang.String propertyName

    - #### protected java.lang.Class<?> propertyType

  - ### Constructor Detail

    - #### public ConstrainedProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> propertyType)

      Constructs a new ConstrainedProperty for the given arguments.

      Parameters:
        `clazz` - The owning class
        `propertyName` - The name of the property
        `propertyType` - The property type

  - ### Method Detail

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

      Adds a meta constraints which is a non-validating informational constraint.

      Parameters:
        `name` - The name of the constraint
        `value` - The value

    - #### @java.lang.Override 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

    - #### public Constraint getAppliedConstraint(java.lang.String name)

      Obtains an applied constraint by name.

      Parameters:
        `name` - The name of the constraint
      Returns:
        The applied constraint

    - #### public java.util.Collection<Constraint> getAppliedConstraints()

      Returns:
        Returns the appliedConstraints.

    - #### @java.lang.SuppressWarnings("rawtypes") public java.util.Map getAttributes()

    - #### @java.lang.Override public java.lang.String getFormat()

    - #### @java.lang.Override @java.lang.SuppressWarnings("rawtypes") public java.util.List getInList()

      Returns:
        Returns the inList.

    - #### @java.lang.Override public java.lang.String getMatches()

      Returns:
        Returns the matches.

    - #### @java.lang.Override @java.lang.SuppressWarnings({ "unchecked", "rawtypes" }) public java.lang.Comparable getMax()

      Returns:
        Returns the max.

    - #### @java.lang.Override public java.lang.Integer getMaxSize()

      Returns:
        Returns the maxSize.

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

      Obtains the value of the named meta constraint.

      Parameters:
        `name` - The name of the constraint
      Returns:
        The value

    - #### @java.lang.Override @java.lang.SuppressWarnings({ "unchecked", "rawtypes" }) public java.lang.Comparable getMin()

      Returns:
        Returns the min.

    - #### @java.lang.Override public java.lang.Integer getMinSize()

      Returns:
        Returns the minSize.

    - #### @java.lang.Override public java.lang.Object getNotEqual()

      Returns:
        Returns the notEqual.

    - #### @java.lang.Override public int getOrder()

      Returns:
        Returns the order.

    - #### @java.lang.Override public java.lang.Class getOwner()

    - #### public java.lang.String getPropertyName()

      Returns:
        Returns the propertyName.

    - #### @java.lang.Override public java.lang.Class<?> getPropertyType()

      Returns:
        Returns the propertyType.

    - #### @java.lang.Override @java.lang.SuppressWarnings("rawtypes") public groovy.lang.Range getRange()

      Returns:
        Returns the range.

    - #### @java.lang.Override public java.lang.Integer getScale()

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

    - #### @java.lang.Override @java.lang.SuppressWarnings("rawtypes") public groovy.lang.Range getSize()

      Returns:
        Returns the size.

    - #### public java.lang.String getWidget()

    - #### @java.lang.Override public boolean hasAppliedConstraint(java.lang.String constraintName)

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

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

    - #### @java.lang.Override public boolean isBlank()

      Returns:
        the blank.

    - #### @java.lang.Override public boolean isCreditCard()

      Returns:
        Returns the creditCard.

    - #### @java.lang.Override public boolean isDisplay()

      Returns:
        Returns the display.

    - #### @java.lang.Override public boolean isEditable()

      Returns:
        Returns the editable.

    - #### @java.lang.Override public boolean isEmail()

      Returns:
        Returns the email.

    - #### @java.lang.Override public boolean isNullable()

      Returns:
        Returns the nullable.

    - #### @java.lang.Override public boolean isPassword()

    - #### @java.lang.Override public boolean isUrl()

      Returns:
        Returns the url.

    - #### public static void registerNewConstraint(java.lang.String name, java.lang.Class<?> constraintClass)

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

    - #### public static void removeConstraint(java.lang.String name, java.lang.Class<?> constraintClass)

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

    - #### @java.lang.SuppressWarnings("rawtypes") public void setAttributes(java.util.Map attributes)

    - #### public void setBlank(boolean blank)

      Parameters:
        `blank` - The blank to set.

    - #### public void setCreditCard(boolean creditCard)

      Parameters:
        `creditCard` - The creditCard to set.

    - #### public void setDisplay(boolean display)

      Parameters:
        `display` - The display to set.

    - #### public void setEditable(boolean editable)

      Parameters:
        `editable` - The editable to set.

    - #### public void setEmail(boolean email)

      Parameters:
        `email` - The email to set.

    - #### public void setFormat(java.lang.String format)

    - #### @java.lang.SuppressWarnings("rawtypes") public void setInList(java.util.List inList)

      Parameters:
        `inList` - The inList to set.

    - #### public void setMatches(java.lang.String regex)

      Parameters:
        `regex` - The matches to set.

    - #### @java.lang.SuppressWarnings("rawtypes") public void setMax(java.lang.Comparable max)

      Parameters:
        `max` - The max to set.

    - #### public void setMaxSize(java.lang.Integer maxSize)

      Parameters:
        `maxSize` - The maxSize to set.

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

      The message source used to evaluate error messages

      Parameters:
        `source` - The MessageSource instance to use to resolve messages

    - #### @java.lang.SuppressWarnings("rawtypes") public void setMin(java.lang.Comparable min)

      Parameters:
        `min` - The min to set.

    - #### public void setMinSize(java.lang.Integer minSize)

      Parameters:
        `minSize` - The minLength to set.

    - #### public void setNotEqual(java.lang.Object notEqual)

      Parameters:
        `notEqual` - The notEqual to set.

    - #### public void setNullable(boolean nullable)

      Parameters:
        `nullable` - The nullable to set.

    - #### public void setOrder(int order)

      Parameters:
        `order` - The order to set.

    - #### public void setPassword(boolean password)

    - #### public void setPropertyName(java.lang.String propertyName)

      Parameters:
        `propertyName` - The propertyName to set.

    - #### @java.lang.SuppressWarnings("rawtypes") public void setRange(groovy.lang.Range range)

      Parameters:
        `range` - The range to set.

    - #### @java.lang.SuppressWarnings("rawtypes") public void setSize(groovy.lang.Range size)

      Parameters:
        `size` - The size to set.

    - #### public void setUrl(boolean url)

      Parameters:
        `url` - The url to set.

    - #### public void setWidget(java.lang.String widget)

    - #### @java.lang.Override 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

    - #### @java.lang.Override public java.lang.String toString()

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

      Validate this constrainted property against specified property value

      Parameters:
        `target` - The target object to validate
        `propertyValue` - The value of the property to validate
        `errors` - The Errors instances to report errors to