001: /*
002: * Copyright 2002-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.validation;
018:
019: import java.util.List;
020: import java.util.Map;
021:
022: import org.springframework.beans.PropertyEditorRegistry;
023: import org.springframework.util.Assert;
024:
025: /**
026: * Thrown when binding errors are considered fatal. Implements the
027: * BindingResult interface (and thus its super-interface Errors)
028: * to allow for the direct analysis of binding errors.
029: *
030: * <p>As of Spring 2.0, this is a special-purpose class. Normally, application
031: * code will work with the BindingResult interface, or a DataBinder that
032: * in turn exposes a BindingResult via
033: * {@link org.springframework.validation.DataBinder#getBindingResult()}.
034: *
035: * @author Rod Johnson
036: * @author Juergen Hoeller
037: * @author Rob Harrop
038: * @see BindingResult
039: * @see DataBinder#getBindingResult()
040: * @see DataBinder#close()
041: */
042: public class BindException extends Exception implements BindingResult {
043:
044: /**
045: * Prefix for the name of the BindException instance in a model,
046: * followed by the object name.
047: * @deprecated in favor of <code>BindingResult.MODEL_KEY_PREFIX</code>
048: * @see BindingResult#MODEL_KEY_PREFIX
049: */
050: public static final String ERROR_KEY_PREFIX = BindException.class
051: .getName()
052: + ".";
053:
054: private final BindingResult bindingResult;
055:
056: /**
057: * Create a new BindException instance for a BindingResult.
058: * @param bindingResult the BindingResult instance to wrap
059: */
060: public BindException(BindingResult bindingResult) {
061: Assert.notNull(bindingResult, "BindingResult must not be null");
062: this .bindingResult = bindingResult;
063: }
064:
065: /**
066: * Create a new BindException instance for a target bean.
067: * @param target target bean to bind onto
068: * @param objectName the name of the target object
069: * @see BeanPropertyBindingResult
070: */
071: public BindException(Object target, String objectName) {
072: Assert.notNull(target, "Target object must not be null");
073: this .bindingResult = new BeanPropertyBindingResult(target,
074: objectName);
075: }
076:
077: /**
078: * Return the BindingResult that this BindException wraps.
079: * Will typically be a BeanPropertyBindingResult.
080: * @see BeanPropertyBindingResult
081: */
082: public final BindingResult getBindingResult() {
083: return this .bindingResult;
084: }
085:
086: /**
087: * Return the PropertyEditorRegistry that the underlying BindingResult uses.
088: * @see #getBindingResult()
089: */
090: public final PropertyEditorRegistry getPropertyEditorRegistry() {
091: return this .bindingResult.getPropertyEditorRegistry();
092: }
093:
094: public String getObjectName() {
095: return this .bindingResult.getObjectName();
096: }
097:
098: public void setNestedPath(String nestedPath) {
099: this .bindingResult.setNestedPath(nestedPath);
100: }
101:
102: public String getNestedPath() {
103: return this .bindingResult.getNestedPath();
104: }
105:
106: public void pushNestedPath(String subPath) {
107: this .bindingResult.pushNestedPath(subPath);
108: }
109:
110: public void popNestedPath() throws IllegalStateException {
111: this .bindingResult.popNestedPath();
112: }
113:
114: public void reject(String errorCode) {
115: this .bindingResult.reject(errorCode);
116: }
117:
118: public void reject(String errorCode, String defaultMessage) {
119: this .bindingResult.reject(errorCode, defaultMessage);
120: }
121:
122: public void reject(String errorCode, Object[] errorArgs,
123: String defaultMessage) {
124: this .bindingResult.reject(errorCode, errorArgs, defaultMessage);
125: }
126:
127: public void rejectValue(String field, String errorCode) {
128: this .bindingResult.rejectValue(field, errorCode);
129: }
130:
131: public void rejectValue(String field, String errorCode,
132: String defaultMessage) {
133: this .bindingResult
134: .rejectValue(field, errorCode, defaultMessage);
135: }
136:
137: public void rejectValue(String field, String errorCode,
138: Object[] errorArgs, String defaultMessage) {
139: this .bindingResult.rejectValue(field, errorCode, errorArgs,
140: defaultMessage);
141: }
142:
143: public void addAllErrors(Errors errors) {
144: this .bindingResult.addAllErrors(errors);
145: }
146:
147: public boolean hasErrors() {
148: return this .bindingResult.hasErrors();
149: }
150:
151: public int getErrorCount() {
152: return this .bindingResult.getErrorCount();
153: }
154:
155: public List getAllErrors() {
156: return this .bindingResult.getAllErrors();
157: }
158:
159: public boolean hasGlobalErrors() {
160: return this .bindingResult.hasGlobalErrors();
161: }
162:
163: public int getGlobalErrorCount() {
164: return this .bindingResult.getGlobalErrorCount();
165: }
166:
167: public List getGlobalErrors() {
168: return this .bindingResult.getGlobalErrors();
169: }
170:
171: public ObjectError getGlobalError() {
172: return this .bindingResult.getGlobalError();
173: }
174:
175: public boolean hasFieldErrors() {
176: return this .bindingResult.hasFieldErrors();
177: }
178:
179: public int getFieldErrorCount() {
180: return this .bindingResult.getFieldErrorCount();
181: }
182:
183: public List getFieldErrors() {
184: return this .bindingResult.getFieldErrors();
185: }
186:
187: public FieldError getFieldError() {
188: return this .bindingResult.getFieldError();
189: }
190:
191: public boolean hasFieldErrors(String field) {
192: return this .bindingResult.hasFieldErrors(field);
193: }
194:
195: public int getFieldErrorCount(String field) {
196: return this .bindingResult.getFieldErrorCount(field);
197: }
198:
199: public List getFieldErrors(String field) {
200: return this .bindingResult.getFieldErrors(field);
201: }
202:
203: public FieldError getFieldError(String field) {
204: return this .bindingResult.getFieldError(field);
205: }
206:
207: public Object getFieldValue(String field) {
208: return this .bindingResult.getFieldValue(field);
209: }
210:
211: public Class getFieldType(String field) {
212: return this .bindingResult.getFieldType(field);
213: }
214:
215: public Object getTarget() {
216: return this .bindingResult.getTarget();
217: }
218:
219: public Map getModel() {
220: return this .bindingResult.getModel();
221: }
222:
223: public void recordSuppressedField(String fieldName) {
224: this .bindingResult.recordSuppressedField(fieldName);
225: }
226:
227: public String[] getSuppressedFields() {
228: return this .bindingResult.getSuppressedFields();
229: }
230:
231: public void addError(ObjectError error) {
232: this .bindingResult.addError(error);
233: }
234:
235: public String[] resolveMessageCodes(String errorCode, String field) {
236: return this .bindingResult.resolveMessageCodes(errorCode, field);
237: }
238:
239: /**
240: * Returns diagnostic information about the errors held in this object.
241: */
242: public String getMessage() {
243: return this .bindingResult.toString();
244: }
245:
246: public boolean equals(Object other) {
247: return (this == other || this .bindingResult.equals(other));
248: }
249:
250: public int hashCode() {
251: return this.bindingResult.hashCode();
252: }
253:
254: }
|