Business component validation follows the JavaBeans PropertyChange
mechanism. A change to an attribute leads to a VetoableChange event
notification followed by PropertyChange notification. A PropertyChangeEvent
object is passed along with the event containing the entity object reference
to which the attribute belongs and the new value to be set for the attribute
that is being validated. The validators implement VetoableChangeListener
events and attach themselves to the listeners list in the attribute descriptors
and hence get notified of the changes to an attribute. When a setCurrentRow
call changes the current row in a view object, the Business Components for Java
framework invokes entity object validation.
To validate an entity object, a validator object is created and attached to
the entity object as a VetoableChangeListener. When the entity object's validate method is called, the listeners are
activated, which in turn perform their validate methods and
throw VetoableChangeException in case of failures.
An entity object has one public validate method that is
called both at change of row currency and commit time. The logic of
the validate method is:
Call validateEntity. You can override this method, but you
should call super.validate before your own code to invoke the
framework's validation mechanism. Note that Entity.validate()
is not overridable (is final).
For a composition, validateEntity calls validateChildren
on the entity object. The entity object traverses each of its ownership
associations where it is the source entity object, and examines the entity
object on the destination end. If the destination entity object is marked
invalid, the traversing entity object calls the validate method
on it.
Perform validations on declarative rules attached to this entity object.
Call setValidated(true) to reset the invalid flag and/or
remove the entity object from its owner's list of invalid entities. If the
entity object is a top-level entity object, then remove it from the transaction's
list of invalid entity objects.
The following figure is a high-level illustration of the sequence of events and method calls that executes when an attribute value is set in the business logic tier.
The next figure illustrates what happens if the entity object is part of a composition relationship. In this case, the framework tries to lock the topmost entity object.