commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pål Oliver Kristiansen <>
Subject Commons validator: validators - no common interface ?
Date Wed, 17 Jan 2007 14:37:10 GMT
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 
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, 

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 
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:
For additional commands, e-mail:

View raw message