public abstract class DBObjectValidator<T extends DBObject> extends CascadeWorker<T> implements DBObjectValidator<T>
Implementors use this class as a starting point for validation logic as validation of name, schema name (if appropriate) and duplication of name are provided by the base implementation.
 To validate SchemaObject implementation, subclass
 SchemaObjectValidator
 
 To implement property specific validation, the DBObjectValidator.PropertyValidator
 annotation can be used to mark methods as being the validation for a given
 property or properties. Such methods are automatically called when a call
 to validateObjectProperty(DBObject,DBObject,String) is made. They
 are all called when validateObject(DBObject,DBObject) is called.
 
For example to validate getMyProp/setMyProp on DBObject subclass MyObject:
public class MyObjectValidator extends DBObjectValidator{ public MyObjectValidator( DBObjectProvider pro ) { super( pro ); } 
   @PropertyValidator( Property.myProp )
   public void validateMyProp( MyObject original, MyObject update )
   throws ValidationException
   {
     // TODO: validation logic here
   }
 }
 
 This is now a complete validator implementation for MyObject with its one
 myProp property.| Modifier and Type | Class and Description | 
|---|---|
static class  | 
DBObjectValidator.NamespaceType
Types of namespace check that can be done when verifying that a given
 object's name is unqiue with the database. 
 | 
protected static interface  | 
DBObjectValidator.PropertyDependency
Identifiers the property that a method that has a PropertyValidator is
 dependent on the value of other properties, and therefore the validation
 is also co-dependent. 
 | 
protected static interface  | 
DBObjectValidator.PropertyValidator
Marks a method as being the validation logic for a given property, or
 properties. 
 | 
| Modifier | Constructor and Description | 
|---|---|
protected  | 
DBObjectValidator(DBObjectProvider pro)  | 
| Modifier and Type | Method and Description | 
|---|---|
protected boolean | 
canHaveEmptyName()
By default names cannot be empty (or null). 
 | 
protected boolean | 
canRename()
Default name validation is to allow rename on update. 
 | 
protected void | 
checkInterrupt()
Checks whether validation has been interrupted or cancelled and throws
 an exception to stop validation. 
 | 
protected boolean | 
enforceChildNameUniqueInSchema(DBObject child)
Deprecated. 
 
replaced by  
#getNamespaceType(DBObject). | 
protected T | 
findExistingObject(T object)
Finds an existing object for the given object. 
 | 
java.util.Collection<java.lang.String[]> | 
getDependencies(java.lang.String path)  | 
DBObjectValidator.NamespaceType | 
getNamespaceType()
Gets the type of namespace check that should be done by
  
validateNameInUse(T). | 
boolean | 
initializeWithDefaultName()
Tests whether a newly created object should be initialized with a
 default base name. 
 | 
protected boolean | 
isChildOfPendingObject(DBObject obj)
Tests whether the given object has a SchemaObject parent that is a pending
 (templated) object. 
 | 
protected boolean | 
isPendingObject(SchemaObject obj)
Tests whether the given SchemaObject is pending a template expansion. 
 | 
protected java.util.Collection<java.lang.String> | 
listAlwaysValidProperties()
Lists the properties that are always valid for this object. 
 | 
protected void | 
logException(DBException dbe,
            java.util.logging.Level level)
Logs the message for the given DBException to an appropriate level. 
 | 
void | 
validateComment(T original,
               T update)  | 
protected void | 
validateMissingPath(T original,
                   T updated,
                   java.lang.String property)
When a path is validated, and the start of that path is missing the
 root object, this method is called to allow subclasses to customise
 validation for mandatory child properties when their parent is missing. 
 | 
void | 
validateName(java.lang.String type,
            java.lang.String externalName)
Validates that the given name is a valid identifier for the given
 object type. 
 | 
protected void | 
validateName(T obj)
Validates the given object's name to see if it is a legal identifier. 
 | 
void | 
validateName(T original,
            T updated)  | 
protected void | 
validateNameInUse(T object)
Validates whether the given name is already in use. 
 | 
protected void | 
validateNonNullableProperty(DBObject original,
                           DBObject updated,
                           java.lang.String propName)
Validate that the property has not been updated from not null to null in
 an online database. 
 | 
void | 
validateObject(T object)
Tests whether the specified DBObject is valid for creation. 
 | 
void | 
validateObject(T original,
              T updated)
Determines whether the specified "updated" object is valid. 
 | 
void | 
validateObjectProperty(T object,
                      java.lang.String property)
Tries to find an existing object for the given object and calls
  
#validateObject(DBObject original, DBObject updated, Object property)
 This is final - all subclasses should implement
 #validateObject(DBObject original, DBObject updated, Object property) | 
void | 
validateObjectProperty(T original,
                      T updated,
                      java.lang.String property)
Validates the given property for the given object. 
 | 
protected void | 
validateOwnedObjects(DBObject[] children)
Convenience method to call validateObject on the provider for each of
 the owned objects in the given array. 
 | 
void | 
validateType(T original,
            T updated)
Shouldn't be necessary but hey! 
 | 
static void | 
validateUniqueNames(DBObject[] objs)
Deprecated. 
 
with no replacement. Unique name validation is done by
 validateNameInUse. 
 | 
cascadeDelete, cascadeDelete, cascadePropertyChange, cascadeUpdate, getCascadeProperties, getLogger, getProvider, removeReferenceprotected DBObjectValidator(DBObjectProvider pro)
protected void checkInterrupt()
                       throws ValidationCancelledException
ValidationCancelledException - if validation should stopprotected void logException(DBException dbe, java.util.logging.Level level) throws ValidationCancelledException
Use this method to log non-fatal exceptions ( e.g. resolveID() ) during validation so that a cancel/interrupt is not missed.
dbe - the exception to loglevel - the level to log the exception's message at.ValidationCancelledException - if the DBException is a
 CancelledException.public final void validateObject(T object) throws ValidationException
validateObject(DBObject,DBObject) to validate
 that an object can be updated.validateObject in interface DBObjectValidator<T extends DBObject>object - the DBObject to validateValidationException - if the object is not valid to createpublic final void validateObjectProperty(T object, java.lang.String property) throws ValidationException
#validateObject(DBObject original, DBObject updated, Object property)
 This is final - all subclasses should implement
 #validateObject(DBObject original, DBObject updated, Object property)validateObjectProperty in interface DBObjectValidator<T extends DBObject>object - the DBObject to validateproperty - the property identfier for the specific property to
 validate.ValidationException - if the object is not valid.public void validateObject(T original, T updated) throws ValidationException
In general this should not need to be overridden. Validation should be complete by simply providing property specific validation methods. See the class javadoc for more details.
validateObject in interface DBObjectValidator<T extends DBObject>object - the original DBObject (or null)object - the updated DBObject to validateValidationException - if the object is not valid.public void validateObjectProperty(T original, T updated, java.lang.String property) throws ValidationException
DBObjectValidator.PropertyValidatorannotation for the requested property.
 If no such method is registered, a
 MissingValidatorExceptionis thrown.validateObjectProperty in interface DBObjectValidator<T extends DBObject>property - the property identfier for the specific property to
 validate.ValidationException - if the object is not valid.protected void validateMissingPath(T original, T updated, java.lang.String property) throws ValidationException
original - the original objectupdated - the updated objectproperty - the property path whose first property is null on the
 updated object.ValidationExceptionprotected java.util.Collection<java.lang.String> listAlwaysValidProperties()
This should not be used to simply suppress warnings for properties that genuinely require validation. Add a validation method instead.
This will be checked after an annotated validation method cannot be found, so that if you subclass another validator that lists a property as "always valid" and you wish to add validation for it, your annotated validation method will still be called regardless of the contents of this collection.
In order to support heirarchical listing subclasses are expected to add to the super's return value. For example:
protected CollectionlistAlwaysValidProperties() { final Collection retval = super.listAlwaysValidProperties(); retval.add( Property.myValidProperty ); return retval; } 
public final void validateType(T original, T updated) throws ValidationException
ValidationExceptionpublic final void validateName(T original, T updated) throws ValidationException
ValidationExceptionprotected final boolean isChildOfPendingObject(DBObject obj)
protected final boolean isPendingObject(SchemaObject obj)
protected void validateName(T obj) throws InvalidNameException
 This method should only be overridden to provide logic specific to
 an actual object. For generic name validation subclasses must override
 validateName(String,String), as that is also called by
 DBObjectProvider.validateName(String,String).
obj - the object whose name requires validationInvalidNameExceptionvalidateNameInUse(DBObject)public void validateName(java.lang.String type,
                java.lang.String externalName)
                  throws InvalidNameException
type will be an object type that this validator
 is registered against in a provider.
 
 The default implementation just calls
 DatabaseDescriptor.validateName(String,String) to validate
 invalid characters and reserved words. Override to include custom
 logic.
type - the object typeexternalName - the name to validateInvalidNameExceptionprotected final void validateNonNullableProperty(DBObject original, DBObject updated, java.lang.String propName) throws ValidationException
original - the orginal object owning the propertyupdated - the updated objectpropName - the name of the propertyValidationException - if the property value has been updated from
 a non-null value to null and the context provider is an online database.protected boolean canHaveEmptyName()
DBObjectValidator.NamespaceType.NONE
 to indicate no name validation. To allow null names but also validate
 their uniqueness override both methods.protected boolean canRename()
protected void validateNameInUse(T object) throws NameInUseException
NameInUseExceptionprotected T findExistingObject(T object) throws ValidationException
object - the object to look for an existing version ofValidationException - if the types of the given object and existing
 object don't match.public DBObjectValidator.NamespaceType getNamespaceType()
validateNameInUse(T). By default this will return TYPE unless
 canHaveEmptyName() returns true, then it will return NONE.
 Override as appropriate.public boolean initializeWithDefaultName()
canHaveEmptyName() and getNamespaceType().@Deprecated protected boolean enforceChildNameUniqueInSchema(DBObject child)
#getNamespaceType(DBObject).public void validateComment(T original, T update) throws ValidationException
ValidationExceptionpublic java.util.Collection<java.lang.String[]> getDependencies(java.lang.String path)
protected final void validateOwnedObjects(DBObject[] children) throws ValidationException
children - the children to validateuniqueNames - whether to validate that the name of each child in
 the array is uniqueValidationException - if any of the children is invalid@Deprecated public static void validateUniqueNames(DBObject[] objs) throws ValidationException
ValidationException