001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.platform;
006:
007: import java.util.ArrayList;
008: import java.util.List;
009:
010: /**
011: * Base class for exceptions generated by a service.
012: * <p>
013: * This class is based off the OGC idea of an exception, which contains
014: * a {@link #code}, and {@link #locator}. Futhermore optional fragments of
015: * {@link #exceptionText} may be associated with the exception.
016: * </p>
017: *
018: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
019: *
020: */
021: public class ServiceException extends RuntimeException {
022: /**
023: * Serial UID
024: */
025: private static final long serialVersionUID = 7254349181794561723L;
026:
027: /**
028: * Application specfic code.
029: */
030: String code;
031:
032: /**
033: * Application specific locator
034: */
035: String locator;
036:
037: /**
038: * List of text recording information about the exception
039: */
040: List exceptionText = new ArrayList();
041:
042: /**
043: * Constructs the exception from a message.
044: *
045: * @param message The message describing the exception.
046: */
047: public ServiceException(String message) {
048: super (message);
049: }
050:
051: /**
052: * Constructs the exception from a message and causing exception.
053: *
054: * @param message The message describing the exception.
055: * @param cause The case of the exception.
056: */
057: public ServiceException(String message, Throwable cause) {
058: super (message, cause);
059: }
060:
061: /**
062: * Constructs the exception from a message, causing exception, and code.
063: *
064: * @param message The message describing the exception.
065: * @param cause The case of the exception.
066: * @param code The application specific exception code for the exception.
067: */
068: public ServiceException(String message, Throwable cause, String code) {
069: this (message, cause);
070: this .code = code;
071: }
072:
073: /**
074: * Constructs the exception from a message, causing exception, code, and
075: * locator.
076: *
077: * @param message The message describing the exception.
078: * @param cause The case of the exception.
079: * @param code The application specific exception code for the exception.
080: * @param locator The application specific locator for the exception.
081: */
082: public ServiceException(String message, Throwable cause,
083: String code, String locator) {
084: this (message, cause, code);
085: this .locator = locator;
086: }
087:
088: /**
089: * Constructs the exception from a message, and code.
090: *
091: * @param message The message describing the exception.
092: * @param code The application specific exception code for the exception.
093: */
094: public ServiceException(String message, String code) {
095: super (message);
096: this .code = code;
097: }
098:
099: /**
100: * Constructs the exception from a message,code, and
101: * locator.
102: *
103: * @param message The message describing the exception.
104: * @param code The application specific exception code for the exception.
105: * @param locator The application specific locator for the exception.
106: */
107: public ServiceException(String message, String code, String locator) {
108: this (message, code);
109: this .locator = locator;
110: }
111:
112: /**
113: * Constructs the exception from a causing exception.
114: *
115: * @param cause The case of the exception.
116: */
117: public ServiceException(Throwable cause) {
118: super (cause);
119: }
120:
121: /**
122: * Constructs the exception from causing exception, and code.
123: *
124: * @param cause The case of the exception.
125: * @param code The application specific exception code for the exception.
126: */
127: public ServiceException(Throwable cause, String code) {
128: this (cause);
129: this .code = code;
130: }
131:
132: /**
133: * Constructs the exception from a causing exception, code, and locator.
134: *
135: * @param cause The case of the exception.
136: * @param code The application specific exception code for the exception.
137: * @param locator The application specific locator for the exception.
138: */
139: public ServiceException(Throwable cause, String code, String locator) {
140: this (cause, code);
141: this .locator = locator;
142: }
143:
144: /**
145: * @return The application specifc code of the exception.
146: */
147: public String getCode() {
148: return code;
149: }
150:
151: /**
152: * Sets the code for the exception.
153: *
154: * @param code The application specific code.
155: */
156: public void setCode(String code) {
157: this .code = code;
158: }
159:
160: /**
161: * @return The application specific locator.
162: */
163: public String getLocator() {
164: return locator;
165: }
166:
167: /**
168: * Sets the locator for the exception.
169: *
170: * @return The application specific locator.
171: */
172: public void setLocator(String locator) {
173: this .locator = locator;
174: }
175:
176: /**
177: * Returns the list of text fragments which provide additonal information
178: * about the exception.
179: * <p>
180: * Text fragements may be added directly to the list with:
181: * <code>
182: * exception.getExceptionTest().add( "text fragment" );
183: * </code>
184: * </p>
185: * @return A list of String recording information about the exception.
186: */
187: public List getExceptionText() {
188: return exceptionText;
189: }
190: }
|