Validation services for complex domain objects.
Generally you will write Validators for each of your domain
objects, and add a {@link ValidationManager} to your application context. You
will need to wire a suitable {@link IntrospectionManager} against the
ValidationManager so that children of a domain object presented
for validation can be identified and in turn also validated.
The {@link ValidationInterceptor} and {@link ValidationAdvisor} are provided,
although their use is not recommended against DAOs given many Validators
require a DAO and this will cause a loop that results in the DAO not being
advised. Instead your DAO implementations should have their mutator methods
pass the object to the ValidationManager prior to persistence. This
is a non-AOP approach, but represetns a practical solution.
If you domain objects themselves wish to ensure they are in a valid state
prior to internal business methods being invoked, it is suggested they provide
a ValidationManager collaborator, and fire its validate method.
Such collaborator can be autowired during both instance retrieval and creation.
It should generally also be marked as transient, to avoid possible
serialisation issues if used inside a HttpSession or similar.
Sometimes domain objects need to internally update themselves before being
validated. Any such domain objects should implement {@link BindBeforeValidation}.
The ValidationManager will fire the related method just prior to
validation, and you can do it manually using {@link BindBeforeValidationUtils}.
Using the utility class is generally preferred over calling the method
directly, as it ignores classes that do not implement
BindBeforeValidation.
Finally, sometimes Validators might need to perform queries
against a persistence or services layer. For example, the Validator
may be checking no other user has this username, or comparing the object's old
state to detect modifications that violate business rules. If using an ORM tool
such as Hibernate, it is recommended you use the EvictionUtils
static methods to remove objects from the session.