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

IntegerGreaterThanConstraint

public class IntegerGreaterThanConstraint extends ConstraintUtils implements Constraint
IntegerGreaterThanConstraint is a {@link Constraint} to validate numbers between the given value and 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 the given value and 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
private int
value
A value represented by this Constraint.
Constructors Summary
public IntegerGreaterThanConstraint()
Creates a new instance of IntegerGreaterThanConstraint.


    
           
      
        value = -1;
    
public IntegerGreaterThanConstraint(String inputValue)
Creates a new instance of IntegerGreaterThanConstraint.

        try {
           this.value = Integer.parseInt(inputValue);
        } catch(NumberFormatException e) {

            String format = 
                BundleReader.getValue("Error_failed_to_create");        //NOI18N
            Object[] arguments = 
                new Object[]{"IntegerGreaterThanConstraint"};           //NOI18N

            System.out.println(MessageFormat.format(format, arguments));
        }
    
Methods Summary
private voidaddFailure(java.util.Collection failed_constrained_list, java.lang.String name, java.lang.String inputValue)

        String failureMessage = formatFailureMessage(toString(),
            inputValue, name);

        String format = BundleReader.getValue(
            "MSG_IntegerGreaterThanConstraint_Failure");                //NOI18N
        Object[] arguments = 
            new Object[]{String.valueOf(value)};
        String genericFailureMessage = MessageFormat.format(format, arguments);

        failed_constrained_list.add(new ConstraintFailure(toString(),
            inputValue, name, failureMessage, genericFailureMessage));
    
public java.util.Collectionmatch(java.lang.String inputValue, 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 the value this Constraint represents and Integer.MAX_VALUE.

        ArrayList failed_constrained_list = new ArrayList();
        if((inputValue != null) && (inputValue.length() != 0)){
            try {
                int intValue = Integer.parseInt(inputValue);
                
                if((intValue <= value) || (intValue > Integer.MAX_VALUE)){
                    addFailure(failed_constrained_list, name, inputValue);
                }
            } catch(NumberFormatException e) {
                addFailure(failed_constrained_list, name, inputValue);
            }
        }
        return failed_constrained_list;
    
public voidprint()
Prints this Constraint.

        super.print();

        String format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
        Object[] arguments = 
            new Object[]{"Value", String.valueOf(value)};               //NOI18N
        System.out.println(MessageFormat.format(format, arguments));
    
public voidsetValue(java.lang.String value)
Sets the value represented by this object.

param
value the value represented by this object.

        try {
           this.value = Integer.parseInt(value);
        } catch(NumberFormatException e) {
            String format = 
                BundleReader.getValue("Error_failed_to_set");           //NOI18N
            Object[] arguments = 
                new Object[]{this.toString(), "Value"};                 //NOI18N

            System.out.println(MessageFormat.format(format, arguments));
        }
    
public voidsetValue(java.lang.Integer value)
Sets the value represented by this object.

param
value the value represented by this object.

        this.value = value.intValue();