1 19 20 package org.netbeans.modules.j2ee.sun.validation.constraints; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.text.MessageFormat ; 25 26 import org.netbeans.modules.j2ee.sun.validation.constraints.ConstraintFailure; 27 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader; 28 29 44 public class IntegerGreaterThanConstraint extends ConstraintUtils 45 implements Constraint { 46 47 50 private int value = -1; 51 52 53 54 public IntegerGreaterThanConstraint() { 55 value = -1; 56 } 57 58 59 60 public IntegerGreaterThanConstraint(String inputValue) { 61 try { 62 this.value = Integer.parseInt(inputValue); 63 } catch(NumberFormatException e) { 64 65 String format = 66 BundleReader.getValue("Error_failed_to_create"); Object [] arguments = 68 new Object []{"IntegerGreaterThanConstraint"}; 70 System.out.println(MessageFormat.format(format, arguments)); 71 } 72 } 73 74 75 88 public Collection match(String inputValue, String name) { 89 ArrayList failed_constrained_list = new ArrayList (); 90 if((inputValue != null) && (inputValue.length() != 0)){ 91 try { 92 int intValue = Integer.parseInt(inputValue); 93 94 if((intValue <= value) || (intValue > Integer.MAX_VALUE)){ 95 addFailure(failed_constrained_list, name, inputValue); 96 } 97 } catch(NumberFormatException e) { 98 addFailure(failed_constrained_list, name, inputValue); 99 } 100 } 101 return failed_constrained_list; 102 } 103 104 105 110 public void setValue(String value){ 111 try { 112 this.value = Integer.parseInt(value); 113 } catch(NumberFormatException e) { 114 String format = 115 BundleReader.getValue("Error_failed_to_set"); Object [] arguments = 117 new Object []{this.toString(), "Value"}; 119 System.out.println(MessageFormat.format(format, arguments)); 120 } 121 } 122 123 124 129 public void setValue(Integer value){ 130 this.value = value.intValue(); 131 } 132 133 134 137 public void print() { 138 super.print(); 139 140 String format = BundleReader.getValue("Name_Value_Pair_Format"); Object [] arguments = 142 new Object []{"Value", String.valueOf(value)}; System.out.println(MessageFormat.format(format, arguments)); 144 } 145 146 147 private void addFailure(Collection failed_constrained_list, 148 String name, String inputValue){ 149 String failureMessage = formatFailureMessage(toString(), 150 inputValue, name); 151 152 String format = BundleReader.getValue( 153 "MSG_IntegerGreaterThanConstraint_Failure"); Object [] arguments = 155 new Object []{String.valueOf(value)}; 156 String genericFailureMessage = MessageFormat.format(format, arguments); 157 158 failed_constrained_list.add(new ConstraintFailure(toString(), 159 inputValue, name, failureMessage, genericFailureMessage)); 160 } 161 } 162 | Popular Tags |