01: /*
02: * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>.
03: *
04: * This file is part of
05: * CleanSheets - a spreadsheet application for the Java platform.
06: *
07: * CleanSheets is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * CleanSheets is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with CleanSheets; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: package csheets.core;
22:
23: /**
24: * An exception that is thrown when an illegal value is encountered.
25: * @author Einar Pehrson
26: */
27: public class IllegalValueTypeException extends Exception {
28:
29: /** The serialVersionUID of the IllegalValueTypeException.java */
30: private static final long serialVersionUID = 1642715350728576100L;
31:
32: /** The value */
33: private Value value;
34:
35: /** The expected type of the value */
36: private Value.Type expectedValueType;
37:
38: /**
39: * Creates a new illegal value type exception.
40: * @param value the value
41: * @param expectedValueType the expected type of the value
42: */
43: public IllegalValueTypeException(Value value,
44: Value.Type expectedValueType) {
45: this .value = value;
46: this .expectedValueType = expectedValueType;
47: }
48:
49: /**
50: * Returns the value.
51: * @return the value
52: */
53: public Value getValue() {
54: return value;
55: }
56:
57: /**
58: * Returns the expected type of the value.
59: * @return the expected type of the value
60: */
61: public Value.Type getExpectedValueType() {
62: return expectedValueType;
63: }
64:
65: /**
66: * Returns a message describing the exception.
67: * @return a message describing the exception
68: */
69: public String getMessage() {
70: return "The value '" + value + "' was expected to be of type "
71: + expectedValueType.toString().toLowerCase() + ".";
72: }
73:
74: /**
75: * Returns a string representation of the exception.
76: * @return a string representation of the exception
77: */
78: public String toString() {
79: if (value.toAny() == null)
80: return "#NULL!";
81: else
82: return "#TYPE!";
83: }
84: }
|