01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.springframework.binding.format;
17:
18: import org.springframework.core.NestedRuntimeException;
19:
20: /**
21: * Thrown when a formatted value is of the wrong form.
22: *
23: * @author Keith Donald
24: */
25: public class InvalidFormatException extends NestedRuntimeException {
26:
27: private String invalidValue;
28:
29: private String expectedFormat;
30:
31: /**
32: * Create a new invalid format exception.
33: * @param invalidValue the invalid value
34: * @param expectedFormat the expected format
35: */
36: public InvalidFormatException(String invalidValue,
37: String expectedFormat) {
38: this (invalidValue, expectedFormat, null);
39: }
40:
41: /**
42: * Create a new invalid format exception.
43: * @param invalidValue the invalid value
44: * @param expectedFormat the expected format
45: * @param cause the underlying cause of this exception
46: */
47: public InvalidFormatException(String invalidValue,
48: String expectedFormat, Throwable cause) {
49: super (
50: "Invalid format for value '" + invalidValue
51: + "'; the expected format was '"
52: + expectedFormat + "'", cause);
53: this .invalidValue = invalidValue;
54: this .expectedFormat = expectedFormat;
55: }
56:
57: /**
58: * Create a new invalid format exception.
59: * @param invalidValue the invalid value
60: * @param expectedFormat the expected format
61: * @param message a descriptive message
62: * @param cause the underlying cause of this exception
63: */
64: public InvalidFormatException(String invalidValue,
65: String expectedFormat, String message, Throwable cause) {
66: super (message, cause);
67: this .invalidValue = invalidValue;
68: this .expectedFormat = expectedFormat;
69: }
70:
71: /**
72: * Returns the invalid value.
73: */
74: public String getInvalidValue() {
75: return invalidValue;
76: }
77:
78: /**
79: * Returns the expected format.
80: */
81: public String getExpectedFormat() {
82: return expectedFormat;
83: }
84: }
|