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 java.lang.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:
chemit

Field Summary
protected  B bean
          bean to be watched
static java.lang.String BEAN_PROERTY
          la nom de la propriété bean
protected  java.lang.Class<B> beanClass
          the type of bean to watch
protected  java.beans.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 java.lang.String CHANGED_PROERTY
          la nom de l'état changed
static java.lang.String CONTEXT_NAME_PROPERTY
          la nom de la propriété contextName
protected  java.lang.String contextName
          the validation named context (can be null)
protected  java.util.Map<java.lang.String,java.lang.String> conversionErrors
          map of conversion errors detected by this validator
protected  java.util.Set<BeanValidatorField<B>> fields
          list of fields watched by this validator
protected  java.beans.PropertyChangeListener l
          listener that listens on bean modification
protected  javax.swing.event.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  java.beans.PropertyChangeSupport pcs
          delegate property change support
protected  boolean valid
          state of the validator (is true if no errors of error scope is found)
static java.lang.String VALID_PROERTY
          la nom de l'état valid
protected  java.util.EnumMap<BeanValidatorScope,XWorkBeanValidator<B>> validators
          xworks scope validator
 
Constructor Summary
BeanValidator(java.lang.Class<B> beanClass, java.lang.String contextName)
           
 
Method Summary
 void addBeanValidatorListener(BeanValidatorListener listener)
           
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
protected  boolean canValidate()
           
 boolean containsField(java.lang.String fieldName)
          Test a the validator contains the field given his name
<T> T
convert(java.lang.String fieldName, java.lang.String value, java.lang.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, java.lang.String[] toAdd, java.lang.String[] toDelete)
           
 B getBean()
           
 java.lang.Class<B> getBeanClass()
           
protected  java.beans.EventSetDescriptor getBeanEventDescriptor(B bean)
           
 BeanValidatorListener[] getBeanValidatorListeners()
           
 java.lang.String getContextName()
           
 BeanValidatorField<B> getField(java.lang.String fieldName)
           
 java.util.Set<BeanValidatorField<B>> getFields()
           
 BeanValidator<?> getParentValidator()
           
 java.util.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(java.lang.String fieldName)
           
 void removeBeanValidatorListener(BeanValidatorListener listener)
           
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.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(java.lang.String contextName)
           
 void setParentValidator(BeanValidator<?> parentValidator)
           
 void setValid(boolean valid)
           
 java.lang.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 java.lang.String BEAN_PROERTY
la nom de la propriété bean

See Also:
Constant Field Values

CONTEXT_NAME_PROPERTY

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

See Also:
Constant Field Values

VALID_PROERTY

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

See Also:
Constant Field Values

CHANGED_PROERTY

public static final java.lang.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(\"...\");


beanClass

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


contextName

protected java.lang.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 java.beans.EventSetDescriptor beanEventDescriptor
to add and remove PropertyChangeListener on watched beans


fields

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


conversionErrors

protected java.util.Map<java.lang.String,java.lang.String> conversionErrors
map of conversion errors detected by this validator


validators

protected java.util.EnumMap<BeanValidatorScope,XWorkBeanValidator<B>> validators
xworks scope validator


l

protected java.beans.PropertyChangeListener l
listener that listens on bean modification


pcs

protected java.beans.PropertyChangeSupport pcs
delegate property change support


listenerList

protected javax.swing.event.EventListenerList listenerList
A list of event listeners for this validators

Constructor Detail

BeanValidator

public BeanValidator(java.lang.Class<B> beanClass,
                     java.lang.String contextName)
Method Detail

getBeanClass

public java.lang.Class<B> getBeanClass()

getParentValidator

public BeanValidator<?> getParentValidator()

getContextName

public java.lang.String getContextName()

getFields

public java.util.Set<BeanValidatorField<B>> getFields()

getScopes

public java.util.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(java.lang.String fieldName)

hasErrors

public boolean hasErrors()

hasWarnings

public boolean hasWarnings()

hasInfos

public boolean hasInfos()

containsField

public boolean containsField(java.lang.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(java.lang.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(java.lang.String contextName)

setParentValidator

public void setParentValidator(BeanValidator<?> parentValidator)

convert

public <T> T convert(java.lang.String fieldName,
                     java.lang.String value,
                     java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

addBeanValidatorListener

public void addBeanValidatorListener(BeanValidatorListener listener)

removeBeanValidatorListener

public void removeBeanValidatorListener(BeanValidatorListener listener)

getBeanValidatorListeners

public BeanValidatorListener[] getBeanValidatorListeners()

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)

canValidate

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

fireFieldChanged

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

initFields

protected void initFields()

getBeanEventDescriptor

protected java.beans.EventSetDescriptor getBeanEventDescriptor(B bean)


Copyright © 2008-2010 CodeLutin. All Rights Reserved.