1 21 22 package org.apache.commons.validator; 23 24 import java.io.Serializable ; 25 import java.util.Collections ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.Set ; 30 31 35 public class ValidatorResults implements Serializable { 36 37 40 protected Map hResults = new HashMap (); 41 42 45 public void merge(ValidatorResults results) { 46 this.hResults.putAll(results.hResults); 47 } 48 49 52 public void add(Field field, String validatorName, boolean result) { 53 this.add(field, validatorName, result, null); 54 } 55 56 59 public void add( 60 Field field, 61 String validatorName, 62 boolean result, 63 Object value) { 64 65 ValidatorResult validatorResult = this.getValidatorResult(field.getKey()); 66 67 if (validatorResult == null) { 68 validatorResult = new ValidatorResult(field); 69 this.hResults.put(field.getKey(), validatorResult); 70 } 71 72 validatorResult.add(validatorName, result, value); 73 } 74 75 78 public void clear() { 79 this.hResults.clear(); 80 } 81 82 86 public boolean isEmpty() { 87 return this.hResults.isEmpty(); 88 } 89 90 98 public ValidatorResult getValidatorResult(String key) { 99 return (ValidatorResult) this.hResults.get(key); 100 } 101 102 107 public Set getPropertyNames() { 108 return Collections.unmodifiableSet(this.hResults.keySet()); 109 } 110 111 115 public Map getResultValueMap() { 116 Map results = new HashMap (); 117 118 for (Iterator i = hResults.keySet().iterator(); i.hasNext();) { 119 String propertyKey = (String ) i.next(); 120 ValidatorResult vr = this.getValidatorResult(propertyKey); 121 122 Map actions = vr.getActionMap(); 123 for (Iterator x = actions.keySet().iterator(); x.hasNext();) { 124 String actionKey = (String ) x.next(); 125 ValidatorResult.ResultStatus rs = 126 (ValidatorResult.ResultStatus) actions.get(actionKey); 127 128 if (rs != null) { 129 Object result = rs.getResult(); 130 131 if (result != null && !(result instanceof Boolean )) { 132 results.put(propertyKey, result); 133 } 134 } 135 } 136 } 137 138 return results; 139 } 140 141 } 142 | Popular Tags |