001: /*
002: * $Id: TilesException.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.tiles;
023:
024: /**
025: * Root class for all Tiles-exceptions.
026: */
027: public class TilesException extends Exception {
028:
029: /**
030: * Any "wrapped" exception will be exposed when this is serialized.
031: * @serial
032: */
033: private Exception exception;
034:
035: /**
036: * Constructor.
037: */
038: public TilesException() {
039: super ();
040: this .exception = null;
041: }
042:
043: /**
044: * Constructor.
045: * @param message The error or warning message.
046: */
047: public TilesException(String message) {
048: super (message);
049: this .exception = null;
050: }
051:
052: /**
053: * Create a new <code>TilesException</code> wrapping an existing exception.
054: *
055: * <p>The existing exception will be embedded in the new
056: * one, and its message will become the default message for
057: * the TilesException.</p>
058: *
059: * @param e The exception to be wrapped.
060: */
061: public TilesException(Exception e) {
062: super ();
063: this .exception = e;
064: }
065:
066: /**
067: * Create a new <code>TilesException</code> from an existing exception.
068: *
069: * <p>The existing exception will be embedded in the new
070: * one, but the new exception will have its own message.</p>
071: *
072: * @param message The detail message.
073: * @param e The exception to be wrapped.
074: */
075: public TilesException(String message, Exception e) {
076: super (message);
077: this .exception = e;
078: }
079:
080: /**
081: * Return a detail message for this exception.
082: *
083: * <p>If there is a embedded exception, and if the TilesException
084: * has no detail message of its own, this method will return
085: * the detail message from the embedded exception.</p>
086: *
087: * @return The error or warning message.
088: */
089: public String getMessage() {
090: String message = super .getMessage();
091:
092: if (message == null && exception != null) {
093: return exception.getMessage();
094: } else {
095: return message;
096: }
097: }
098:
099: /**
100: * Return the embedded exception, if any.
101: *
102: * @return The embedded exception, or <code>null</code> if there is none.
103: */
104: public Exception getException() {
105: return exception;
106: }
107:
108: }
|