com.interface21.beans
Class AbstractVetoableChangeListener
java.lang.Object
|
+--com.interface21.beans.AbstractVetoableChangeListener
- All Implemented Interfaces:
- java.util.EventListener, java.beans.VetoableChangeListener
- public abstract class AbstractVetoableChangeListener
- extends java.lang.Object
- implements java.beans.VetoableChangeListener
Convenience superclass for JavaBeans VetoableChangeListeners. This class implements the
VetoableChangeListener interface to delegate the method call to one of any number
of validation methods defined in concrete subclasses. This is a typical use of
reflection to avoid the need for a chain of if/else statements, discussed in
Expert One-on-One J2EE Design and Development.
Because validation methods are cached by this class's constructor, the
overhead of reflection is not great.
The signature for validation methods must be of this form (the following
example validates an int property named age):
public void validateAge(int age, PropertyChangeEvent e) throws PropertyVetoException
Note that the field can be expected to have been converted to the required type,
simplifying validation logic.
Validation methods must be public or protected. The return value is not required,
but will be ignored.
NB:Validation methods will receive a reversion event after they have
vetoed a change. So, if an email property is initially null and an invalid email address
is supplied and vetoed by the first call to validateEmail for the given validator,
a second event will be sent when the email field is reverted to null. This means that
validation methods must be able to cope with initial values. They can, however,
throw another PropertyVetoException, which will be ignored by the caller.
Subclasses should be threadsafe: nothing in this superclass will cause a problem.
- Version:
- $Id: AbstractVetoableChangeListener.java,v 1.2 2003/02/27 10:09:31 jhoeller Exp $
- Author:
- Rod Johnson
|
Field Summary |
protected static java.lang.String |
VALIDATE_METHOD_PREFIX
Prefix for validation methods: a typical name might be
validateAge() |
|
Method Summary |
void |
vetoableChange(java.beans.PropertyChangeEvent e)
Implementation of VetoableChangeListener.
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
VALIDATE_METHOD_PREFIX
protected static final java.lang.String VALIDATE_METHOD_PREFIX
- Prefix for validation methods: a typical name might be
validateAge()
AbstractVetoableChangeListener
public AbstractVetoableChangeListener()
throws java.lang.SecurityException
- Creates new AbstractVetoableChangeListener.
Caches validation methods for efficiency.
vetoableChange
public final void vetoableChange(java.beans.PropertyChangeEvent e)
throws java.beans.PropertyVetoException
- Implementation of VetoableChangeListener.
Will attempt to locate the appropriate validator method and
invoke it. Will do nothing if there is no validation method for this
property.
- Specified by:
vetoableChange in interface java.beans.VetoableChangeListener
Rod Johnson and Spring contributors 2001-2003.