1 23 24 28 29 package com.sun.enterprise.tools.common.validation.constraints; 30 31 import java.util.ArrayList ; 32 import java.util.Collection ; 33 import java.util.Iterator ; 34 import java.text.MessageFormat ; 35 36 import com.sun.enterprise.tools.common.validation.constraints.ConstraintFailure; 37 import com.sun.enterprise.tools.common.validation.util.BundleReader; 38 39 40 54 public class InConstraint extends ConstraintUtils implements Constraint { 55 56 59 private Collection enumeration = null; 60 61 62 63 public InConstraint() { 64 enumeration = new ArrayList (); 65 } 66 67 68 69 public InConstraint(Collection enumeration) { 70 this.enumeration = enumeration; 71 } 72 73 74 75 public InConstraint(String [] enumeration) { 76 this.enumeration = new ArrayList (); 77 int size = enumeration.length; 78 for(int i=0; i<size; i++) { 79 this.enumeration.add(enumeration[i]); 80 } 81 } 82 83 84 97 public java.util.Collection match(String value, String name) { 98 Collection failed_constrained_list = new ArrayList (); 99 if((value != null) && (value.length() != 0)) { 100 if(!enumeration.contains(value)){ 101 String failureMessage = formatFailureMessage(toString(), 102 value, name); 103 104 String format = BundleReader.getValue( 105 "MSG_InConstraint_Failure"); String set = ""; Iterator iterator = enumeration.iterator(); 108 String member; 109 while(iterator.hasNext()){ 110 member = (String )iterator.next(); 111 set = set + " " + member; } 113 114 Object [] arguments = new Object []{set}; 115 116 String genericFailureMessage = 117 MessageFormat.format(format, arguments); 118 119 failed_constrained_list.add(new ConstraintFailure(toString(), 120 value, name, failureMessage, genericFailureMessage)); 121 } 122 } 123 return failed_constrained_list; 124 } 125 126 127 134 public void setEnumerationValue(Collection enumeration){ 135 this.enumeration = enumeration; 136 } 137 138 139 146 public void setEnumerationValue(String value){ 147 enumeration.add(value); 148 } 149 150 151 154 void print() { 155 super.print(); 156 String format = BundleReader.getValue("Name_Value_Pair_Format"); Iterator iterator = enumeration.iterator(); 158 String values = ""; 159 while(iterator.hasNext()){ 160 values = values + " " + (String )iterator.next(); } 162 163 if(values != null){ 164 Object [] arguments = 165 new Object []{"Enumeration Values", values}; System.out.println(MessageFormat.format(format, arguments)); 167 } 168 } 169 } 170 | Popular Tags |