The entity engine allows you to specify field validators in two places: in the 
fieldtypeXxx.xml files and in the the entity definition.

The validators in the fieldtype files are not used as far as I can tell.

The validators in the entity definitions require complicated client code to use 
them - they are not used automatically by the entity engine.

The bottom line is, specifying a validator in either location does absolutely 
nothing. I don't know if this was designed this way or not.

I have a design in mind that I think will be better...

1. Create a validator interface that can be used throughout the project:

public interface Validator {
  void isValid(Object obj;
}

The isValid method throws an IllegalArgumentException if the object is not 
valid.

2. Set up a library of commonly used validators and put them in a Validator 
factory. Modify ModelField and ModelFieldType so they load validators from the 
factory.

3. Have ModelField and ModelFieldType implement Validator. Those classes 
delegate the isValid method call to their contained validators.

4. Modify GenericEntity.set method to call the ModelField's isValid method.

The advantages to this approach are:

1. Validators are reusable. The same validators could be used on service 
parameters for example.
2. Client code is shielded from validation details. Just call the isValid 
method.
3. OFBiz users can implement custom Validator implementations and add them to 
the Validator factory.

What do you think?

-Adrian




Reply via email to