interface Constraint

The Constraint interface is used to implement Constraint checking implementations.

Description

Constraint implementations are declared on Composites that require Constraint checking of method arguments and/or Property set() methods.

The Constraint will co-operate with a custom annotation, which is used to mark which method argument to be linked to the Constraint. The annotation can also contain arguments, for instance to provide range checks.

The Constraint will be provided the annotation and the value that is passed in the method.

The Constraint simply returns true if the argument is Ok, and otherwise false. It should avoid throwing exceptions.

Declaration

package org.qi4j.api.constraint;

import java.lang.annotation.Annotation;

/**
* All Constraints must implement this interface, which
* is used for each value validation.
*/
public interface Constraint<A extends Annotation, P>
{
    /**
     * For each value or parameter which should be checked
     * this method will be invoked.
     * If the method returns true the value is valid. If it
     * returns false the value is considered invalid.
     * When all constraints have been checked a
     * ConstraintViolationException will be thrown with all
     * the constraint violations that were found.
     *
     * @param annotation the annotation to match
     * @param value      the value to be checked
     * @return true if valid, false if invalid
     * @throws NullPointerException NPE can be thrown if the value was null
     */
    boolean isValid( A annotation, P value )
        throws NullPointerException;
}

Example

Description of Example goes here...
  if( ... )

Qi4j and the Qi4j logo are trademarks of Richard Öberg, Niclas Hedhman and the members of the Qi4j Core Team. See Qi4j licensing for more information.
Powered by SiteVisionexternal link.