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.util.Iterator ; 25 import java.text.MessageFormat ; 26 27 import org.netbeans.modules.j2ee.sun.validation.constraints.ConstraintFailure; 28 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader; 29 30 31 45 public class InConstraint extends ConstraintUtils implements Constraint { 46 47 50 private Collection enumeration = null; 51 52 53 54 public InConstraint() { 55 enumeration = new ArrayList (); 56 } 57 58 59 60 public InConstraint(Collection enumeration) { 61 this.enumeration = enumeration; 62 } 63 64 65 66 public InConstraint(String [] enumeration) { 67 this.enumeration = new ArrayList (); 68 int size = enumeration.length; 69 for(int i=0; i<size; i++) { 70 this.enumeration.add(enumeration[i]); 71 } 72 } 73 74 75 88 public java.util.Collection match(String value, String name) { 89 Collection failed_constrained_list = new ArrayList (); 90 if((value != null) && (value.length() != 0)) { 91 if(!enumeration.contains(value)){ 92 String failureMessage = formatFailureMessage(toString(), 93 value, name); 94 95 String format = BundleReader.getValue( 96 "MSG_InConstraint_Failure"); String set = ""; Iterator iterator = enumeration.iterator(); 99 String member; 100 while(iterator.hasNext()){ 101 member = (String )iterator.next(); 102 set = set + " " + member; } 104 105 Object [] arguments = new Object []{set}; 106 107 String genericFailureMessage = 108 MessageFormat.format(format, arguments); 109 110 failed_constrained_list.add(new ConstraintFailure(toString(), 111 value, name, failureMessage, genericFailureMessage)); 112 } 113 } 114 return failed_constrained_list; 115 } 116 117 118 125 public void setEnumerationValue(Collection enumeration){ 126 this.enumeration = enumeration; 127 } 128 129 130 137 public void setEnumerationValue(String value){ 138 enumeration.add(value); 139 } 140 141 142 145 void print() { 146 super.print(); 147 String format = BundleReader.getValue("Name_Value_Pair_Format"); Iterator iterator = enumeration.iterator(); 149 String values = ""; 150 while(iterator.hasNext()){ 151 values = values + " " + (String )iterator.next(); } 153 154 if(values != null){ 155 Object [] arguments = 156 new Object []{"Enumeration Values", values}; System.out.println(MessageFormat.format(format, arguments)); 158 } 159 } 160 } 161 | Popular Tags |