FileDocCategorySizeDatePackage
ZeroToMaxIntegerConstraint.javaAPI DocGlassfish v2 API4883Fri May 04 22:35:00 BST 2007com.sun.enterprise.tools.common.validation.constraints

ZeroToMaxIntegerConstraint

public class ZeroToMaxIntegerConstraint extends ConstraintUtils implements Constraint
ZeroToMaxIntegerConstraint is a {@link Constraint} to validate numbers between Zero to Integer.MAX_VALUE. It implements Constraint interface and extends {@link ConstraintUtils} class. match method of this object returns empty Collection if the value being validated is a number between Zero to Integer.MAX_VALUE; 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 ZeroToMaxIntegerConstraint()
Creates a new instance of NumberConstraint.

    
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. This method will fail, if the given value is not between Zero and Integer.MAX_VALUE.

        ArrayList failed_constrained_list = new ArrayList();
        if((value != null) && (value.length() != 0)){
            try {
                int intValue = Integer.parseInt(value);
                if((intValue < 0) || (intValue > Integer.MAX_VALUE)){
                    String failureMessage = formatFailureMessage(toString(),
                        value, name);
                    failed_constrained_list.add(new ConstraintFailure(toString(),
                        value, name, failureMessage, BundleReader.getValue(
                           "MSG_ZeroToMaxIntegerConstraint_Failure"))); //NOI18N
                }
                return failed_constrained_list;
            } catch(NumberFormatException e) {
                String failureMessage = formatFailureMessage(toString(), value,
                    name);
                failed_constrained_list.add(new ConstraintFailure(toString(),
                    value, name, failureMessage, BundleReader.getValue(
                        "MSG_NumberConstraint_Failure")));              //NOI18N
            }
        }
        return failed_constrained_list;