jaxx.runtime.validator
Class BeanValidator<B>

java.lang.Object
  extended by jaxx.runtime.validator.BeanValidator<B>
Type Parameters:
B - type of the bean to validate.
Direct Known Subclasses:
SwingValidator

public class BeanValidator<B>
extends Object

A customized validator for a given bean.

Note: The bean must be listenable on properyChange events (means must have public addPropertychangeListener and removePropertyChangeListener methods).

Author:
tchemit

Field Summary
protected  B bean
          bean to be watched
static String BEAN_PROERTY
          la nom de la propriété bean
protected  Class<B> beanClass
          the type of bean to watch
protected  EventSetDescriptor beanEventDescriptor
          to add and remove PropertyChangeListener on watched beans
protected  boolean changed
          state to indicate that validator has changed since the last time bean was setted
static String CHANGED_PROERTY
          la nom de l'état changed
static String CONTEXT_NAME_PROPERTY
          la nom de la propriété contextName
protected  String contextName
          the validation named context (can be null)
protected  Map<String,String> conversionErrors
          map of conversion errors detected by this validator
protected  Set<BeanValidatorField<B>> fields
          list of fields watched by this validator
protected static BeanValidatorScope[] FILTER_SCOPES_EMPTY
           
protected  BeanValidatorScope[] filterScopes
          filter scopes (if null, no filter on scopes)
protected  PropertyChangeListener l
          listener that listens on bean modification
protected  EventListenerList listenerList
          A list of event listeners for this validators
protected static org.apache.commons.logging.Log log
          to use log facility, just put in your code: log.info(\"...\");
protected  BeanValidator<?> parentValidator
          to chain to a prent validator
protected  PropertyChangeSupport pcs
          delegate property change support
protected  boolean valid
          state of the validator (is true if no errors of error scope is found)
static String VALID_PROERTY
          la nom de l'état valid
protected  EnumMap<BeanValidatorScope,XWorkBeanValidator<B>> validators
          xworks scope validator *
 
Constructor Summary
BeanValidator(Class<B> beanClass, String contextName)
           
BeanValidator(Class<B> beanClass, String contextName, BeanValidatorScope... filterScopes)
           
 
Method Summary
 void addBeanValidatorListener(BeanValidatorListener listener)
           
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
protected  boolean canValidate()
           
 boolean containsField(String fieldName)
          Test a the validator contains the field given his name
<T> T
convert(String fieldName, String value, Class<T> valueClass)
          Convert a value.
 void doValidate()
          Methode pour forcer la revalidation d'un bean en mettant a jour les etats internes.
protected  void fireFieldChanged(BeanValidatorField<B> field, BeanValidatorScope scope, String[] toAdd, String[] toDelete)
           
 B getBean()
           
 Class<B> getBeanClass()
           
protected  EventSetDescriptor getBeanEventDescriptor(B bean)
           
 BeanValidatorListener[] getBeanValidatorListeners()
           
 String getContextName()
           
 BeanValidatorField<B> getField(String fieldName)
           
 Set<BeanValidatorField<B>> getFields()
           
 BeanValidator<?> getParentValidator()
           
 Set<BeanValidatorScope> getScopes()
           
 boolean hasErrors()
           
 boolean hasInfos()
           
 boolean hasWarnings()
           
protected  void initFields()
           
 boolean isChanged()
          Retourne vrai si l'objet bean a ete modifie depuis le dernier setBean(B)
 boolean isValid()
           
 boolean isValid(String fieldName)
           
 void removeBeanValidatorListener(BeanValidatorListener listener)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void setBean(B bean)
           
 void setChanged(boolean changed)
          Permet de force la remise a false de l'etat de changement du bean
 void setContextName(String contextName)
           
 void setFilterScopes(BeanValidatorScope... filterScopes)
          Sets the filter scopes.
 void setParentValidator(BeanValidator<?> parentValidator)
           
 void setValid(boolean valid)
           
 String toString()
           
 void validate()
          il faut eviter le code re-intrant (durant une validation, une autre est demandee).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BEAN_PROERTY

public static final String BEAN_PROERTY
la nom de la propriété bean

See Also:
Constant Field Values

CONTEXT_NAME_PROPERTY

public static final String CONTEXT_NAME_PROPERTY
la nom de la propriété contextName

See Also:
Constant Field Values

VALID_PROERTY

public static final String VALID_PROERTY
la nom de l'état valid

See Also:
Constant Field Values

CHANGED_PROERTY

public static final String CHANGED_PROERTY
la nom de l'état changed

See Also:
Constant Field Values

log

protected static final org.apache.commons.logging.Log log
to use log facility, just put in your code: log.info(\"...\");


FILTER_SCOPES_EMPTY

protected static final BeanValidatorScope[] FILTER_SCOPES_EMPTY

beanClass

protected final Class<B> beanClass
the type of bean to watch


contextName

protected String contextName
the validation named context (can be null)


parentValidator

protected BeanValidator<?> parentValidator
to chain to a prent validator


changed

protected boolean changed
state to indicate that validator has changed since the last time bean was setted


valid

protected boolean valid
state of the validator (is true if no errors of error scope is found)


bean

protected B bean
bean to be watched


beanEventDescriptor

protected EventSetDescriptor beanEventDescriptor
to add and remove PropertyChangeListener on watched beans


fields

protected Set<BeanValidatorField<B>> fields
list of fields watched by this validator


conversionErrors

protected Map<String,String> conversionErrors
map of conversion errors detected by this validator


validators

protected EnumMap<BeanValidatorScope,XWorkBeanValidator<B>> validators
xworks scope validator *


filterScopes

protected BeanValidatorScope[] filterScopes
filter scopes (if null, no filter on scopes)


l

protected PropertyChangeListener l
listener that listens on bean modification


pcs

protected PropertyChangeSupport pcs
delegate property change support


listenerList

protected EventListenerList listenerList
A list of event listeners for this validators

Constructor Detail

BeanValidator

public BeanValidator(Class<B> beanClass,
                     String contextName)

BeanValidator

public BeanValidator(Class<B> beanClass,
                     String contextName,
                     BeanValidatorScope... filterScopes)
Method Detail

getBeanClass

public Class<B> getBeanClass()

getParentValidator

public BeanValidator<?> getParentValidator()

getContextName

public String getContextName()

getFields

public Set<BeanValidatorField<B>> getFields()

getScopes

public Set<BeanValidatorScope> getScopes()

isChanged

public boolean isChanged()
Retourne vrai si l'objet bean a ete modifie depuis le dernier setBean(B)

Returns:
true if bean was modify since last setBean(Object) invocation

isValid

public boolean isValid()

getBean

public B getBean()

getField

public BeanValidatorField<B> getField(String fieldName)

hasErrors

public boolean hasErrors()

hasWarnings

public boolean hasWarnings()

hasInfos

public boolean hasInfos()

containsField

public boolean containsField(String fieldName)
Test a the validator contains the field given his name

Parameters:
fieldName - the name of the searched field
Returns:
true if validator contaisn this field, false otherwise

isValid

public boolean isValid(String fieldName)

setChanged

public void setChanged(boolean changed)
Permet de force la remise a false de l'etat de changement du bean

Parameters:
changed - flag to force reset of property changed

setValid

public void setValid(boolean valid)

setBean

public void setBean(B bean)

setContextName

public void setContextName(String contextName)

setFilterScopes

public void setFilterScopes(BeanValidatorScope... filterScopes)
Sets the filter scopes.

Parameters:
filterScopes - the scopes to used

setParentValidator

public void setParentValidator(BeanValidator<?> parentValidator)

convert

public <T> T convert(String fieldName,
                     String value,
                     Class<T> valueClass)
Convert a value.

If an error occurs, then add an error in validator.

Type Parameters:
T - the type of conversion
Parameters:
fieldName - the name of the bean property
value - the value to convert
valueClass - the type of converted value
Returns:
the converted value, or null if conversion was not ok

doValidate

public void doValidate()
Methode pour forcer la revalidation d'un bean en mettant a jour les etats internes.

La méthode appelle validate() puis met à jour les etats internes valid et changed.

Since:
1.5

validate

public void validate()
il faut eviter le code re-intrant (durant une validation, une autre est demandee). Pour cela on fait la validation dans un thread, et tant que la premiere validation n'est pas fini, on ne repond pas aux solicitations. Cette method est public pour permettre de force une validation par programmation, ce qui est utile par exemple si le bean ne supporte pas les PropertyChangeListener

TODO la methode devra repasser en protected et on utilise la methode doValidate() car validate() ne modifie pas les etats internes et cela en rend son utilisation delicate (le validateur entre dans un etat incoherent par rapport aux messages envoyés).


toString

public String toString()
Overrides:
toString in class Object

addBeanValidatorListener

public void addBeanValidatorListener(BeanValidatorListener listener)

removeBeanValidatorListener

public void removeBeanValidatorListener(BeanValidatorListener listener)

getBeanValidatorListeners

public BeanValidatorListener[] getBeanValidatorListeners()

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)

canValidate

protected boolean canValidate()
Returns:
true if validation is enabled, false otherwise.

fireFieldChanged

protected void fireFieldChanged(BeanValidatorField<B> field,
                                BeanValidatorScope scope,
                                String[] toAdd,
                                String[] toDelete)

initFields

protected void initFields()

getBeanEventDescriptor

protected EventSetDescriptor getBeanEventDescriptor(B bean)


Copyright © 2008-2010 CodeLutin. All Rights Reserved.