Package muntjac :: Package data :: Module validatable
[hide private]
[frames] | no frames]

Source Code for Module muntjac.data.validatable

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  """Interface for validatable objects.""" 
 17   
 18   
19 -class IValidatable(object):
20 """Interface for validatable objects. Defines methods to verify if the 21 object's value is valid or not, and to add, remove and list registered 22 validators of the object. 23 24 @author: Vaadin Ltd. 25 @author: Richard Lincoln 26 @version: 1.1.2 27 @see: L{IValidator} 28 """ 29
30 - def addValidator(self, validator):
31 """Adds a new validator for this object. The validator's 32 L{Validator.validate} method is activated every time the 33 object's value needs to be verified, that is, when the L{isValid} 34 method is called. This usually happens when the object's value changes. 35 36 @param validator: 37 the new validator 38 """ 39 raise NotImplementedError
40 41
42 - def removeValidator(self, validator):
43 """Removes a previously registered validator from the object. The 44 specified validator is removed from the object and its C{validate} 45 method is no longer called in L{isValid}. 46 47 @param validator: 48 the validator to remove 49 """ 50 raise NotImplementedError
51 52
53 - def getValidators(self):
54 """Lists all validators currently registered for the object. If no 55 validators are registered, returns C{None}. 56 57 @return: collection of validators or C{None} 58 """ 59 raise NotImplementedError
60 61
62 - def isValid(self):
63 """Tests the current value of the object against all registered 64 validators. The registered validators are iterated and for each the 65 L{Validator.validate} method is called. If any validator 66 throws the L{InvalidValueException} this method returns 67 C{False}. 68 69 @return: C{True} if the registered validators concur that the 70 value is valid, C{False} otherwise 71 """ 72 raise NotImplementedError
73 74
75 - def validate(self):
76 """Checks the validity of the validatable. If the validatable is valid 77 this method should do nothing, and if it's not valid, it should throw 78 C{InvalidValueException} 79 80 @raise InvalidValueException: 81 if the value is not valid 82 """ 83 raise NotImplementedError
84 85
86 - def isInvalidAllowed(self):
87 """Checks the validabtable object accept invalid values.The default 88 value is C{True}. 89 """ 90 raise NotImplementedError
91 92
93 - def setInvalidAllowed(self, invalidValueAllowed):
94 """Should the validabtable object accept invalid values. Supporting 95 this configuration possibility is optional. By default invalid values 96 are allowed. 97 98 @raise NotImplementedError: 99 if the setInvalidAllowed is not supported. 100 """ 101 raise NotImplementedError
102