1 23 24 package com.sun.enterprise.tools.common.validation.constraints; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.text.MessageFormat ; 29 30 import com.sun.enterprise.tools.common.validation.constraints.ConstraintFailure; 31 import com.sun.enterprise.tools.common.validation.util.BundleReader; 32 33 48 public class IntegerGreaterThanConstraint extends ConstraintUtils 49 implements Constraint { 50 51 54 private int value = -1; 55 56 57 58 public IntegerGreaterThanConstraint() { 59 value = -1; 60 } 61 62 63 64 public IntegerGreaterThanConstraint(String inputValue) { 65 try { 66 this.value = Integer.parseInt(inputValue); 67 } catch(NumberFormatException e) { 68 69 String format = 70 BundleReader.getValue("Error_failed_to_create"); Object [] arguments = 72 new Object []{"IntegerGreaterThanConstraint"}; 74 System.out.println(MessageFormat.format(format, arguments)); 75 } 76 } 77 78 79 92 public Collection match(String inputValue, String name) { 93 ArrayList failed_constrained_list = new ArrayList (); 94 if((inputValue != null) && (inputValue.length() != 0)){ 95 try { 96 int intValue = Integer.parseInt(inputValue); 97 98 if((intValue <= value) || (intValue > Integer.MAX_VALUE)){ 99 addFailure(failed_constrained_list, name, inputValue); 100 } 101 } catch(NumberFormatException e) { 102 addFailure(failed_constrained_list, name, inputValue); 103 } 104 } 105 return failed_constrained_list; 106 } 107 108 109 114 public void setValue(String value){ 115 try { 116 this.value = Integer.parseInt(value); 117 } catch(NumberFormatException e) { 118 String format = 119 BundleReader.getValue("Error_failed_to_set"); Object [] arguments = 121 new Object []{this.toString(), "Value"}; 123 System.out.println(MessageFormat.format(format, arguments)); 124 } 125 } 126 127 128 133 public void setValue(Integer value){ 134 this.value = value.intValue(); 135 } 136 137 138 141 public void print() { 142 super.print(); 143 144 String format = BundleReader.getValue("Name_Value_Pair_Format"); Object [] arguments = 146 new Object []{"Value", String.valueOf(value)}; System.out.println(MessageFormat.format(format, arguments)); 148 } 149 150 151 private void addFailure(Collection failed_constrained_list, 152 String name, String inputValue){ 153 String failureMessage = formatFailureMessage(toString(), 154 inputValue, name); 155 156 String format = BundleReader.getValue( 157 "MSG_IntegerGreaterThanConstraint_Failure"); Object [] arguments = 159 new Object []{String.valueOf(value)}; 160 String genericFailureMessage = MessageFormat.format(format, arguments); 161 162 failed_constrained_list.add(new ConstraintFailure(toString(), 163 inputValue, name, failureMessage, genericFailureMessage)); 164 } 165 } 166 | Popular Tags |