KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > validation > BindException


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.validation;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.springframework.beans.PropertyEditorRegistry;
23 import org.springframework.util.Assert;
24
25 /**
26  * Thrown when binding errors are considered fatal. Implements the
27  * BindingResult interface (and thus its super-interface Errors)
28  * to allow for the direct analysis of binding errors.
29  *
30  * <p>As of Spring 2.0, this is a special-purpose class. Normally, application
31  * code will work with the BindingResult interface, or a DataBinder that
32  * in turn exposes a BindingResult via
33  * {@link org.springframework.validation.DataBinder#getBindingResult()}.
34  *
35  * @author Rod Johnson
36  * @author Juergen Hoeller
37  * @author Rob Harrop
38  * @see BindingResult
39  * @see DataBinder#getBindingResult()
40  * @see DataBinder#close()
41  */

42 public class BindException extends Exception JavaDoc implements BindingResult {
43
44     /**
45      * Prefix for the name of the BindException instance in a model,
46      * followed by the object name.
47      * @deprecated in favor of <code>BindingResult.MODEL_KEY_PREFIX</code>
48      * @see BindingResult#MODEL_KEY_PREFIX
49      */

50     public static final String JavaDoc ERROR_KEY_PREFIX = BindException.class.getName() + ".";
51
52
53     private final BindingResult bindingResult;
54
55
56     /**
57      * Create a new BindException instance for a BindingResult.
58      * @param bindingResult the BindingResult instance to wrap
59      */

60     public BindException(BindingResult bindingResult) {
61         Assert.notNull(bindingResult, "BindingResult must not be null");
62         this.bindingResult = bindingResult;
63     }
64
65     /**
66      * Create a new BindException instance for a target bean.
67      * @param target target bean to bind onto
68      * @param objectName the name of the target object
69      * @see BeanPropertyBindingResult
70      */

71     public BindException(Object JavaDoc target, String JavaDoc objectName) {
72         Assert.notNull(target, "Target object must not be null");
73         this.bindingResult = new BeanPropertyBindingResult(target, objectName);
74     }
75
76
77     /**
78      * Return the BindingResult that this BindException wraps.
79      * Will typically be a BeanPropertyBindingResult.
80      * @see BeanPropertyBindingResult
81      */

82     public final BindingResult getBindingResult() {
83         return this.bindingResult;
84     }
85
86     /**
87      * Return the PropertyEditorRegistry that the underlying BindingResult uses.
88      * @see #getBindingResult()
89      */

90     public final PropertyEditorRegistry getPropertyEditorRegistry() {
91         return this.bindingResult.getPropertyEditorRegistry();
92     }
93
94
95     public String JavaDoc getObjectName() {
96         return this.bindingResult.getObjectName();
97     }
98
99     public void setNestedPath(String JavaDoc nestedPath) {
100         this.bindingResult.setNestedPath(nestedPath);
101     }
102
103     public String JavaDoc getNestedPath() {
104         return this.bindingResult.getNestedPath();
105     }
106
107     public void pushNestedPath(String JavaDoc subPath) {
108         this.bindingResult.pushNestedPath(subPath);
109     }
110
111     public void popNestedPath() throws IllegalStateException JavaDoc {
112         this.bindingResult.popNestedPath();
113     }
114
115
116     public void reject(String JavaDoc errorCode) {
117         this.bindingResult.reject(errorCode);
118     }
119
120     public void reject(String JavaDoc errorCode, String JavaDoc defaultMessage) {
121         this.bindingResult.reject(errorCode, defaultMessage);
122     }
123
124     public void reject(String JavaDoc errorCode, Object JavaDoc[] errorArgs, String JavaDoc defaultMessage) {
125         this.bindingResult.reject(errorCode, errorArgs, defaultMessage);
126     }
127
128     public void rejectValue(String JavaDoc field, String JavaDoc errorCode) {
129         this.bindingResult.rejectValue(field, errorCode);
130     }
131
132     public void rejectValue(String JavaDoc field, String JavaDoc errorCode, String JavaDoc defaultMessage) {
133         this.bindingResult.rejectValue(field, errorCode, defaultMessage);
134     }
135
136     public void rejectValue(String JavaDoc field, String JavaDoc errorCode, Object JavaDoc[] errorArgs, String JavaDoc defaultMessage) {
137         this.bindingResult.rejectValue(field, errorCode, errorArgs, defaultMessage);
138     }
139
140     public void addAllErrors(Errors errors) {
141         this.bindingResult.addAllErrors(errors);
142     }
143
144
145     public boolean hasErrors() {
146         return this.bindingResult.hasErrors();
147     }
148
149     public int getErrorCount() {
150         return this.bindingResult.getErrorCount();
151     }
152
153     public List JavaDoc getAllErrors() {
154         return this.bindingResult.getAllErrors();
155     }
156
157     public boolean hasGlobalErrors() {
158         return this.bindingResult.hasGlobalErrors();
159     }
160
161     public int getGlobalErrorCount() {
162         return this.bindingResult.getGlobalErrorCount();
163     }
164
165     public List JavaDoc getGlobalErrors() {
166         return this.bindingResult.getGlobalErrors();
167     }
168
169     public ObjectError getGlobalError() {
170         return this.bindingResult.getGlobalError();
171     }
172
173     public boolean hasFieldErrors() {
174         return this.bindingResult.hasFieldErrors();
175     }
176
177     public int getFieldErrorCount() {
178         return this.bindingResult.getFieldErrorCount();
179     }
180
181     public List JavaDoc getFieldErrors() {
182         return this.bindingResult.getFieldErrors();
183     }
184
185     public FieldError getFieldError() {
186         return this.bindingResult.getFieldError();
187     }
188
189     public boolean hasFieldErrors(String JavaDoc field) {
190         return this.bindingResult.hasFieldErrors(field);
191     }
192
193     public int getFieldErrorCount(String JavaDoc field) {
194         return this.bindingResult.getFieldErrorCount(field);
195     }
196
197     public List JavaDoc getFieldErrors(String JavaDoc field) {
198         return this.bindingResult.getFieldErrors(field);
199     }
200
201     public FieldError getFieldError(String JavaDoc field) {
202         return this.bindingResult.getFieldError(field);
203     }
204
205     public Object JavaDoc getFieldValue(String JavaDoc field) {
206         return this.bindingResult.getFieldValue(field);
207     }
208
209     public Class JavaDoc getFieldType(String JavaDoc field) {
210         return this.bindingResult.getFieldType(field);
211     }
212
213     public Object JavaDoc getTarget() {
214         return this.bindingResult.getTarget();
215     }
216
217     public Map JavaDoc getModel() {
218         return this.bindingResult.getModel();
219     }
220
221     public void recordSuppressedField(String JavaDoc fieldName) {
222         this.bindingResult.recordSuppressedField(fieldName);
223     }
224
225     public String JavaDoc[] getSuppressedFields() {
226         return this.bindingResult.getSuppressedFields();
227     }
228
229     public void addError(ObjectError error) {
230         this.bindingResult.addError(error);
231     }
232
233     public String JavaDoc[] resolveMessageCodes(String JavaDoc errorCode, String JavaDoc field) {
234         return this.bindingResult.resolveMessageCodes(errorCode, field);
235     }
236
237
238     /**
239      * Returns diagnostic information about the errors held in this object.
240      */

241     public String JavaDoc getMessage() {
242         return this.bindingResult.toString();
243     }
244
245     public boolean equals(Object JavaDoc other) {
246         return (this == other || this.bindingResult.equals(other));
247     }
248
249     public int hashCode() {
250         return this.bindingResult.hashCode();
251     }
252
253 }
254
Popular Tags