FileDocCategorySizeDatePackage
BooleanConstraint.javaAPI DocGlassfish v2 API4867Fri May 04 22:34:58 BST 2007com.sun.enterprise.tools.common.validation.constraints

BooleanConstraint

public class BooleanConstraint extends ConstraintUtils implements Constraint
BooleanConstraint is a {@link Constraint} to validate boolean values. It implements Constraint interface and extends {@link ConstraintUtils} class. match method of this object returns empty Collection if the value being validated is boolean; else it returns a Collection with a {@link ConstraintFailure} object in it. ConstraintUtils class provides utility methods for formating failure messages and a print method to print this object.
author
Rajeshwar Patil
version
%I%, %G%

Fields Summary
Constructors Summary
public BooleanConstraint()
Creates a new instance of BooleanConstraint.

    
Methods Summary
public java.util.Collectionmatch(java.lang.String value, java.lang.String name)
Validates the given value against this Constraint.

param
value the value to be validated
param
name the element name, value of which is being validated. It is used only in case of Constraint failure, to construct the failure message.
return
Collection the Collection of ConstraintFailure Objects. Collection is empty if there are no failures. Failure can occur if value being validated is anything other than the following values : true, false , case ignored.

        Collection failed_constrained_list = new ArrayList();
        if((value != null) && (value.length() != 0)) {
            if (!( (value.equalsIgnoreCase("true")) ||                  //NOI18N
                    (value.equalsIgnoreCase("false")))){                //NOI18N
                String failureMessage = formatFailureMessage(toString(), value,
                    name);

                String format = BundleReader.getValue(
                    "MSG_BooleanConstraint_Failure");                   //NOI18N
                Object[] arguments = new Object[]{"True", "False"};     //NOI18N

                String genericFailureMessage = 
                    MessageFormat.format(format, arguments);

                failed_constrained_list.add(new ConstraintFailure(toString(),
                    value, name, failureMessage, genericFailureMessage));
            }
        }
        return failed_constrained_list;