Hello !
I'm using the commons validator framework and am facing this problem:
I want in a dynamic way validate data of an object by binding the
objects type
to a certain type of validator class. However, the UrlValidator and the
EmailValidator
both extends object and does not implement any jakarta commons
interfaces. So
how can I achieve this ? I would like to do something on the lines of:
(code not tested obviously)
Map<ObjectType, ValidatorInterface> validators = new HashMap<ObjectType,
ValidatorInterface>();
validators.put(ObjectType.EMAIL, new EmailValidator());
validators.put(ObjectType.URL, new UrlValidator());
validators.put(ObjectType.Age, new IntegerValidator());
boolean validate(MyObject myObject){
return validators.get(myObject.getType()).validate();
}
The question#1 is; why isnt there a general "Validator" interface of
some sort ?
Question #2.
Comparing the three validator classes for Urls, Email and Generic types,
why is the basic usage
of these classes so different. Like this:
validating an Url: new UrlValidator().isValid(myUrl); // using default
constructor
validating an email: EmailValidator.getInstance().isValid(myEmail); //
singelton pattern
validating a generic Stirng for nulls:
GenericValidator.isBlankOrNull(node.getContent()); // static method
Thank you.
--
Pål Oliver Kristiansen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]