1 /*
2 * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResult.java,v 1.11 2004/02/21 17:10:29 rleland Exp $
3 * $Revision: 1.11 $
4 * $Date: 2004/02/21 17:10:29 $
5 *
6 * ====================================================================
7 * Copyright 2001-2004 The Apache Software Foundation
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
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.Map;
28
29 /***
30 * This contains the results of a set of validation rules processed
31 * on a JavaBean.
32 */
33 public class ValidatorResult implements Serializable {
34
35 /***
36 * Map of results. The key is the name of the <code>ValidatorAction</code>
37 * and the value is whether or not this field passed or not.
38 */
39 protected Map hAction = new HashMap();
40
41 /***
42 * <code>Field</code> being validated.
43 * TODO This variable is not used. Need to investigate removing it.
44 */
45 protected Field field = null;
46
47 /***
48 * Constructs a <code>ValidatorResult</code> with the associated field being
49 * validated.
50 */
51 public ValidatorResult(Field field) {
52 this.field = field;
53 }
54
55 /***
56 * Add the result of a validator action.
57 */
58 public void add(String validatorName, boolean result) {
59 this.add(validatorName, result, null);
60 }
61
62 /***
63 * Add the result of a validator action.
64 */
65 public void add(String validatorName, boolean result, Object value) {
66 hAction.put(validatorName, new ResultStatus(result, value));
67 }
68
69 public boolean containsAction(String validatorName) {
70 return hAction.containsKey(validatorName);
71 }
72
73 public boolean isValid(String validatorName) {
74 ResultStatus status = (ResultStatus) hAction.get(validatorName);
75 return (status == null) ? false : status.isValid();
76 }
77
78 public Map getActionMap() {
79 return Collections.unmodifiableMap(hAction);
80 }
81
82 /***
83 * Returns the Field that was validated.
84 */
85 public Field getField() {
86 return this.field;
87 }
88
89 /***
90 * Contains the status of the validation.
91 */
92 protected class ResultStatus implements Serializable {
93 private boolean valid = false;
94 private Object result = null;
95
96 public ResultStatus(boolean valid, Object result) {
97 this.valid = valid;
98 this.result = result;
99 }
100
101 /***
102 * Gets whether or not the validation passed.
103 * @deprecated Use isValid() instead.
104 */
105 public boolean getValid() {
106 return valid;
107 }
108
109 /***
110 * Tests whether or not the validation passed.
111 */
112 public boolean isValid() {
113 return valid;
114 }
115
116 /***
117 * Sets whether or not the validation passed.
118 */
119 public void setValid(boolean valid) {
120 this.valid = valid;
121 }
122
123 /***
124 * Gets the result returned by a validation method.
125 * This can be used to retrieve to the correctly
126 * typed value of a date validation for example.
127 */
128 public Object getResult() {
129 return result;
130 }
131
132 /***
133 * Sets the result returned by a validation method.
134 * This can be used to retrieve to the correctly
135 * typed value of a date validation for example.
136 */
137 public void setResult(Object result) {
138 this.result = result;
139 }
140
141 }
142
143 }
This page was automatically generated by Maven