[Figleaf-developer] Validation mechanism
Status: Alpha
Brought to you by:
steckman
|
From: <sam...@ma...> - 2004-07-06 09:01:30
|
I've been kicking around some ideas for the validation mechanism. My plan is for a ValidationRule object, which is associated with a ProperyDescriptor. A CompositeValidationRule will allow for multiple ValidationRules to apply to a single property. The interface defines one method: boolean validate(Object value, ValidationCallback callback); If it validates, true is returned. If it doesn't, false is returned. In either case a callbackmethod will be called - ValidationCallback looks like this: void valid(PropertyDescriptor property, Object validValue); void invalid(PropertyDescriptor property, Object invalidValue, String errorMessage); The method names suck, but I think the idea is sound. The GUI can then register a callback to automatically seed the UI with validation messages. We could take this a step further - when calling the write methods, automatically invoke the validation firing callback methods as required. Ideas for ValidationRules: RegexpValidationRule <- Passes if string value of Object matches the whole regexp CompositeValidationRule <- Wraps several rules DateValidationRule <- Validates date regions NumberValidationRule <- Ditto for dates We'll also want to add an AbstractValidationRule to make it easy for users to add their own - it'll simply add the callback support. This is all fairly easy to write and test so shouldn't take me too long to write - I can probably check in the interfaces for you to hook into before the weekend (and probably at least one concrete implementation). The only question to answer now, is where do we get the rules from? The obvious place is a PropertyDescriptor - lets add this method: ValidationRule getValidationRule(); sam http://www.magpiebrain.com/ |