Package muntjac :: Package data :: Package validators :: Module composite_validator :: Class CompositeValidator
[hide private]
[frames] | no frames]

Class CompositeValidator

source code

                      object --+        
                               |        
            validator.IValidator --+    
                                   |    
abstract_validator.AbstractValidator --+
                                       |
                                      CompositeValidator

The CompositeValidator allows you to chain (compose) many validators to validate one field. The contained validators may be required to all validate the value to validate or it may be enough that one contained validator validates the value. This behaviour is controlled by the modes AND and OR.


Authors:
Vaadin Ltd., Richard Lincoln

Version: 1.1.2

Instance Methods [hide private]
 
__init__(self, mode=None, errorMessage=None)
Constructs a composite validator in given mode.
source code
 
validate(self, value)
Validates the given value.
source code
 
isValid(self, value)
Checks the validity of the the given value.
source code
 
getMode(self)
Gets the mode of the validator.
source code
 
setMode(self, mode)
Sets the mode of the validator.
source code
 
getErrorMessage(self)
Gets the error message for the composite validator.
source code
 
addValidator(self, validator)
Adds validator to the interface.
source code
 
removeValidator(self, validator)
Removes a validator from the composite.
source code
 
getSubValidators(self, validatorType)
Gets sub-validators by class.
source code

Inherited from abstract_validator.AbstractValidator: setErrorMessage

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  MODE_AND = 0
The validators are combined with AND clause: validity of
  MODE_OR = 1
The validators are combined with OR clause: validity of the
  MODE_DEFAULT = 0
The validators are combined with and clause: validity of the composite
Instance Variables [hide private]
  _mode
Operation mode.
  _validators
List of contained validators.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, mode=None, errorMessage=None)
(Constructor)

source code 

Constructs a composite validator in given mode.

Parameters:
  • errorMessage - the message to be included in an InvalidValueException (with "{0}" replaced by the value that failed validation).
Overrides: object.__init__

validate(self, value)

source code 

Validates the given value.

The value is valid, if:

  • MODE_AND: All of the sub-validators are valid
  • MODE_OR: Any of the sub-validators are valid

If the value is invalid, validation error is thrown. If the error message is set (non-null), it is used. If the error message has not been set, the first error occurred is thrown.

Parameters:
  • value - the value to check.
Raises:
Overrides: validator.IValidator.validate

isValid(self, value)

source code 

Checks the validity of the the given value. The value is valid, if:

  • MODE_AND: All of the sub-validators are valid
  • MODE_OR: Any of the sub-validators are valid
Parameters:
  • value - the value to check.
Returns:
True if the value is valid, False otherwise.
Overrides: validator.IValidator.isValid

getMode(self)

source code 

Gets the mode of the validator.

Returns:
Operation mode of the validator: MODE_AND or MODE_OR.

setMode(self, mode)

source code 

Sets the mode of the validator. The valid modes are:

  • MODE_AND (default)
  • MODE_OR
Parameters:
  • mode - the mode to set.

getErrorMessage(self)

source code 

Gets the error message for the composite validator. If the error message is None, original error messages of the sub-validators are used instead.

Returns:
the error message provided in the constructor or using setErrorMessage.
Overrides: abstract_validator.AbstractValidator.getErrorMessage

addValidator(self, validator)

source code 

Adds validator to the interface.

Parameters:
  • validator - the Validator object which performs validation checks on this set of data field values.

removeValidator(self, validator)

source code 

Removes a validator from the composite.

Parameters:
  • validator - the Validator object which performs validation checks on this set of data field values.

getSubValidators(self, validatorType)

source code 

Gets sub-validators by class.

If the component contains directly or recursively (it contains another composite containing the validator) validators compatible with given type they are returned. This only applies to AND mode composite validators.

If the validator is in OR mode or does not contain any validators of given type null is returned.

Returns:
iterable of validators compatible with given type that must apply or null if none found.