Class CollectionFieldExpressionValidator

java.lang.Object
com.opensymphony.xwork2.validator.validators.ValidatorSupport
com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
com.opensymphony.xwork2.validator.validators.FieldExpressionValidator
org.nuiton.validator.xwork2.field.NuitonFieldExpressionValidator
org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator
All Implemented Interfaces:
com.opensymphony.xwork2.validator.FieldValidator, com.opensymphony.xwork2.validator.ShortCircuitableValidator, com.opensymphony.xwork2.validator.Validator

public class CollectionFieldExpressionValidator
extends NuitonFieldExpressionValidator
Un validateur basé sur FieldExpressionValidator qui valide sur une collection de propriéte.
Author:
Tony Chemit - chemit@codelutin.com
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  CollectionFieldExpressionValidator.Mode  
    class  CollectionFieldExpressionValidator.WalkerContext  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected CollectionFieldExpressionValidator.WalkerContext c
    le context de parcours
    protected java.lang.String collectionFieldName
    pour indiquer la propriété qui contient la liste à valider.
    protected java.lang.String expressionForFirst
    expression a valider sur la premiètre entrée de la collection.
    protected java.lang.String expressionForLast
    expression a valider sur la dernière entrée de la collection.
    protected java.lang.String[] keys
    la liste des propriétés d'une entrée de la collection qui définit la clef unique (en mode UNIQUE_KEY).
    protected CollectionFieldExpressionValidator.Mode mode
    le mode de validation sur la liste
    protected com.opensymphony.xwork2.util.ValueStack stack  
    protected boolean useSensitiveContext
    drapeau pour utiliser le contexte de parcours pour valider l'expression, on dispose donc alors des variables previous, current, index, size et empty dans l'expression.

    Fields inherited from class org.nuiton.validator.xwork2.field.NuitonFieldExpressionValidator

    skip

    Fields inherited from class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport

    currentValue, fieldName, type

    Fields inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport

    defaultMessage, EMPTY_STRING, messageKey, textProviderFactory
  • Constructor Summary

    Constructors 
    Constructor Description
    CollectionFieldExpressionValidator()  
  • Method Summary

    Modifier and Type Method Description
    protected boolean evaluateExpression​(java.lang.String expression, java.lang.Object object)  
    protected java.util.Collection<?> getCollection​(java.lang.Object object)  
    java.lang.String getCollectionFieldName()  
    java.lang.String getExpressionForFirst()  
    java.lang.String getExpressionForLast()  
    java.lang.String[] getKeys()  
    java.lang.String getMessage​(java.lang.Object object)  
    CollectionFieldExpressionValidator.Mode getMode()  
    protected java.lang.Object getPropertyValue​(java.lang.String key, java.lang.Object o)  
    protected java.lang.Integer getUniqueKeyHashCode​(java.lang.Object o)
    Calcule pour une entrée donné, le hash de la clef unique
    java.lang.String getValidatorType()  
    boolean isUseSensitiveContext()  
    void setCollectionFieldName​(java.lang.String collectionFieldName)  
    void setExpressionForFirst​(java.lang.String expressionForFirst)  
    void setExpressionForLast​(java.lang.String expressionForLast)  
    void setKeys​(java.lang.String[] keys)  
    void setMode​(CollectionFieldExpressionValidator.Mode mode)  
    void setUseSensitiveContext​(boolean useSensitiveContext)  
    void setValueStack​(com.opensymphony.xwork2.util.ValueStack stack)  
    protected java.lang.Boolean validateAllEntries​(java.util.Collection<?> col)  
    protected java.lang.Boolean validateAtLeastOneEntry​(java.util.Collection<?> col)  
    protected java.lang.Boolean validateExtacltyOneEntry​(java.util.Collection<?> col)  
    protected java.lang.Boolean validateNoneEntry​(java.util.Collection<?> col)  
    protected boolean validateOneEntry​(java.lang.Object object)  
    protected java.lang.Boolean validateUniqueKey​(java.util.Collection<?> col)  
    void validateWhenNotSkip​(java.lang.Object object)
    Method to be invoked when skip parameter was not evaludated to true.

    Methods inherited from class org.nuiton.validator.xwork2.field.NuitonFieldExpressionValidator

    evaluateSkipParameter, setSkip, validate

    Methods inherited from class com.opensymphony.xwork2.validator.validators.FieldExpressionValidator

    getExpression, setExpression

    Methods inherited from class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport

    getCurrentValue, getFieldName, setFieldName, setValidatorType

    Methods inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport

    addActionError, addFieldError, getDefaultMessage, getFieldValue, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.opensymphony.xwork2.validator.Validator

    getDefaultMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext
  • Field Details

    • mode

      le mode de validation sur la liste
    • collectionFieldName

      protected java.lang.String collectionFieldName
      pour indiquer la propriété qui contient la liste à valider. Si cette prorpiété n'est pas renseignée alors on utilise la FieldValidatorSupport.getFieldName() pour obtenir la collection. Cela permet d'effectuer une validation si une collection mais portant en fait sur un autre champs
      Since:
      1.5
    • useSensitiveContext

      protected boolean useSensitiveContext
      drapeau pour utiliser le contexte de parcours pour valider l'expression, on dispose donc alors des variables previous, current, index, size et empty dans l'expression. Sinon l'expression s'applique directement sur l'entrée courant dans le parcours sans préfixe.
    • expressionForFirst

      protected java.lang.String expressionForFirst
      expression a valider sur la premiètre entrée de la collection. Note : Pour le moment, on autorise uniquement cela en mode ALL.
    • expressionForLast

      protected java.lang.String expressionForLast
      expression a valider sur la dernière entrée de la collection. Note : Pour le moment, on autorise uniquement cela en mode ALL.
    • keys

      protected java.lang.String[] keys
      la liste des propriétés d'une entrée de la collection qui définit la clef unique (en mode UNIQUE_KEY).
    • c

      le context de parcours
    • stack

      protected com.opensymphony.xwork2.util.ValueStack stack
  • Constructor Details

  • Method Details

    • getMode

    • setMode

      public void setMode​(CollectionFieldExpressionValidator.Mode mode)
    • getCollectionFieldName

      public java.lang.String getCollectionFieldName()
    • setCollectionFieldName

      public void setCollectionFieldName​(java.lang.String collectionFieldName)
    • isUseSensitiveContext

      public boolean isUseSensitiveContext()
    • setUseSensitiveContext

      public void setUseSensitiveContext​(boolean useSensitiveContext)
    • getExpressionForFirst

      public java.lang.String getExpressionForFirst()
    • setExpressionForFirst

      public void setExpressionForFirst​(java.lang.String expressionForFirst)
    • getExpressionForLast

      public java.lang.String getExpressionForLast()
    • setExpressionForLast

      public void setExpressionForLast​(java.lang.String expressionForLast)
    • getKeys

      public java.lang.String[] getKeys()
    • setKeys

      public void setKeys​(java.lang.String[] keys)
    • validateWhenNotSkip

      public void validateWhenNotSkip​(java.lang.Object object) throws com.opensymphony.xwork2.validator.ValidationException
      Description copied from class: NuitonFieldExpressionValidator
      Method to be invoked when skip parameter was not evaludated to true.
      Overrides:
      validateWhenNotSkip in class NuitonFieldExpressionValidator
      Parameters:
      object - the object to be validated.
      Throws:
      com.opensymphony.xwork2.validator.ValidationException - is thrown if there is validation error(s).
    • setValueStack

      public void setValueStack​(com.opensymphony.xwork2.util.ValueStack stack)
      Specified by:
      setValueStack in interface com.opensymphony.xwork2.validator.Validator
      Overrides:
      setValueStack in class com.opensymphony.xwork2.validator.validators.ValidatorSupport
    • getMessage

      public java.lang.String getMessage​(java.lang.Object object)
      Specified by:
      getMessage in interface com.opensymphony.xwork2.validator.Validator
      Overrides:
      getMessage in class com.opensymphony.xwork2.validator.validators.ValidatorSupport
    • validateAllEntries

      protected java.lang.Boolean validateAllEntries​(java.util.Collection<?> col) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • validateNoneEntry

      protected java.lang.Boolean validateNoneEntry​(java.util.Collection<?> col) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • validateAtLeastOneEntry

      protected java.lang.Boolean validateAtLeastOneEntry​(java.util.Collection<?> col) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • validateExtacltyOneEntry

      protected java.lang.Boolean validateExtacltyOneEntry​(java.util.Collection<?> col) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • validateUniqueKey

      protected java.lang.Boolean validateUniqueKey​(java.util.Collection<?> col) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • validateOneEntry

      protected boolean validateOneEntry​(java.lang.Object object) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • evaluateExpression

      protected boolean evaluateExpression​(java.lang.String expression, java.lang.Object object) throws com.opensymphony.xwork2.validator.ValidationException
      Throws:
      com.opensymphony.xwork2.validator.ValidationException
    • getCollection

      protected java.util.Collection<?> getCollection​(java.lang.Object object) throws com.opensymphony.xwork2.validator.ValidationException
      Parameters:
      object - the incoming object containing the collection to test
      Returns:
      the collection of the incoming object given by the fieldName property
      Throws:
      com.opensymphony.xwork2.validator.ValidationException - if any pb to retreave the collection
    • getUniqueKeyHashCode

      protected java.lang.Integer getUniqueKeyHashCode​(java.lang.Object o) throws com.opensymphony.xwork2.validator.ValidationException
      Calcule pour une entrée donné, le hash de la clef unique
      Parameters:
      o - l'entree de la collection dont on va calculer le hash de la clef unique
      Returns:
      le hashCode calclé de la clef unique sur l'entrée donné
      Throws:
      com.opensymphony.xwork2.validator.ValidationException - if any pb to retreave properties values
    • getValidatorType

      public java.lang.String getValidatorType()
      Specified by:
      getValidatorType in interface com.opensymphony.xwork2.validator.Validator
      Overrides:
      getValidatorType in class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
    • getPropertyValue

      protected java.lang.Object getPropertyValue​(java.lang.String key, java.lang.Object o)