IT Consultant – Java, J2EE, IBM WebSphere Portal, Lotus Notes/Domino
RSS icon Home icon
  • OVal 1.40 released

    1 Star2 Stars3 Stars4 Stars5 Stars
    Loading...
    Posted on 28 September 2009 Sebastian Thomschke*/?> No comments

    I am happy to announce the immediate availability of Version 1.40 OVal the Object Validation Framework for Java. This release fixes some minor issues and provides the following two new features:

    1. Enabling/disabling constraints based on the object state:
    Using the newly introduced when attribute for constraints it is possible to specify under which circumstances the constraint will be considered during object validation. The when attribute holds a formula in one of the supported scripting languages. If the formula returns true, the constraint will be activated for the current validation cycle otherwise it is ignored. In the following example the alias attribute must have a value only when the name attribute is not set.

    public class User {
       private String name;
    
       @NotNull(when = "groovy:_this.name == null")
       private String alias;
    
       // . . .
    }
    

    2. Fine grain control over how constraints are applied on arrays, maps, collections and their elements
    The newly introduced attribute appliesTo allows you to specify if and how a constraint declared for a map, a collection or an array is applied to their elements as well or exclusively. See the following example how this works:

    public class BusinessObject {
    
       // the ids field may be null, but if it is not null 
       // none of it's items must be null
       @NotNull(appliesTo = { ConstraintTarget.VALUES })
       private String[] ids;
    
       // only the field itself must not be null,
       // the list can contain null values
       @NotNull(appliesTo = { ConstraintTarget.CONTAINER })
       private List items;
    
       // the field must not be null as well as all keys 
       // and values of the map
       @NotNull(appliesTo = { ConstraintTarget.CONTAINER, ConstraintTarget.KEYS, ConstraintTarget.VALUES })
       private Map itemsByGroup;
    
       // . . .
    }
    

    Download
    You can get the latest binaries and source files of OVal from here: http://sourceforge.net/projects/oval/files/