org.codehaus.groovy.grails.validation
Class GrailsDomainClassValidator

java.lang.Object
  extended by org.codehaus.groovy.grails.validation.GrailsDomainClassValidator
All Implemented Interfaces:
GrailsApplicationAware, CascadingValidator, Validator
Direct Known Subclasses:
HibernateDomainClassValidator

public class GrailsDomainClassValidator
extends Object
implements Validator, CascadingValidator, GrailsApplicationAware

A specialised Spring validator that validates a domain class instance using the constraints defined in the static constraints closure.

Since:
0.1 Created: 07-Nov-2005
Author:
Graeme Rocher

Constructor Summary
GrailsDomainClassValidator()
           
 
Method Summary
protected  void cascadeToAssociativeProperty(Errors errors, BeanWrapper bean, GrailsDomainClassProperty persistentProperty)
          Cascades validation onto an associative property maybe a one-to-many, one-to-one or many-to-one relationship
protected  void cascadeValidationToMany(Errors errors, BeanWrapper bean, GrailsDomainClassProperty persistentProperty, String propertyName)
          Cascades validation to a one-to-many type relationship.
protected  void cascadeValidationToOne(Errors errors, BeanWrapper bean, Object associatedObject, GrailsDomainClassProperty persistentProperty, String propertyName)
          Cascades validation to a one-to-one or many-to-one property
 GrailsDomainClass getDomainClass()
           
protected  void postValidate(Object obj, Errors errors)
          Subclasses can overrite to provide custom handling of the errors object post validation
 void setDomainClass(GrailsDomainClass domainClass)
           
 void setGrailsApplication(GrailsApplication grailsApplication)
          This method is called by the ApplicationContext that loads the Grails application.
 void setMessageSource(MessageSource messageSource)
           
 boolean supports(Class clazz)
           
 void validate(Object obj, Errors errors)
           
 void validate(Object obj, Errors errors, boolean cascade)
          An extended version of the validate(errors,obj) method that takes an additional argument specifying whether the Validator should cascade into associations or not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrailsDomainClassValidator

public GrailsDomainClassValidator()
Method Detail

supports

public boolean supports(Class clazz)
Specified by:
supports in interface Validator

setDomainClass

public void setDomainClass(GrailsDomainClass domainClass)
Parameters:
domainClass - The domainClass to set.

getDomainClass

public GrailsDomainClass getDomainClass()

setMessageSource

public void setMessageSource(MessageSource messageSource)
Parameters:
messageSource - The messageSource to set.

validate

public void validate(Object obj,
                     Errors errors,
                     boolean cascade)
Description copied from interface: CascadingValidator
An extended version of the validate(errors,obj) method that takes an additional argument specifying whether the Validator should cascade into associations or not

Specified by:
validate in interface CascadingValidator
Parameters:
obj - The Object to validate
errors - The Spring Errors instance
cascade - True if validation should cascade into associations
See Also:
CascadingValidator.validate(Object, org.springframework.validation.Errors, boolean)

postValidate

protected void postValidate(Object obj,
                            Errors errors)
Subclasses can overrite to provide custom handling of the errors object post validation

Parameters:
obj - The object to validate
errors - The Errors object

validate

public void validate(Object obj,
                     Errors errors)
Specified by:
validate in interface Validator
See Also:
Validator.validate(Object, org.springframework.validation.Errors)

cascadeToAssociativeProperty

protected void cascadeToAssociativeProperty(Errors errors,
                                            BeanWrapper bean,
                                            GrailsDomainClassProperty persistentProperty)
Cascades validation onto an associative property maybe a one-to-many, one-to-one or many-to-one relationship

Parameters:
errors - The Errors instnace
bean - The original bean
persistentProperty - The associative property

cascadeValidationToMany

protected void cascadeValidationToMany(Errors errors,
                                       BeanWrapper bean,
                                       GrailsDomainClassProperty persistentProperty,
                                       String propertyName)
Cascades validation to a one-to-many type relationship. Normally a collection such as a List or Set each element in the association will also be validated

Parameters:
errors - The Errors instance
bean - The original BeanWrapper
persistentProperty - An association whose isOneToMeny() method returns true
propertyName - The name of the property

cascadeValidationToOne

protected void cascadeValidationToOne(Errors errors,
                                      BeanWrapper bean,
                                      Object associatedObject,
                                      GrailsDomainClassProperty persistentProperty,
                                      String propertyName)
Cascades validation to a one-to-one or many-to-one property

Parameters:
errors - The Errors instance
bean - The original BeanWrapper
associatedObject - The associated object's current value
persistentProperty - The GrailsDomainClassProperty instance
propertyName - The name of the property

setGrailsApplication

public void setGrailsApplication(GrailsApplication grailsApplication)
Description copied from interface: GrailsApplicationAware

This method is called by the ApplicationContext that loads the Grails application. The GrailsApplication instance that represents the loaded Grails application is injected.

Specified by:
setGrailsApplication in interface GrailsApplicationAware
Parameters:
grailsApplication - the GrailsApplication object that represents this Grails application


Copyright (c) 2005-2009 The Grails project