View Javadoc

1   /*
2    * $Id: TilesException.java 471754 2006-11-06 14:55:09Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  package org.apache.struts.tiles;
24  
25  
26  /**
27   * Root class for all Tiles-exceptions.
28   */
29  public class TilesException extends Exception
30  {
31  
32  
33    /**
34     * Any "wrapped" exception will be exposed when this is serialized.
35     * @serial
36     */
37    private Exception exception;
38    /**
39      * Constructor.
40      */
41    public TilesException()
42      {
43      super();
44      this.exception = null;
45    }
46  
47    /**
48      * Constructor.
49      * @param message The error or warning message.
50      */
51    public TilesException(String message)
52      {
53      super(message);
54      this.exception = null;
55    }
56  
57  
58    /**
59      * Create a new <code>TilesException</code> wrapping an existing exception.
60      *
61      * <p>The existing exception will be embedded in the new
62      * one, and its message will become the default message for
63      * the TilesException.</p>
64      *
65      * @param e The exception to be wrapped.
66      */
67    public TilesException(Exception e)
68    {
69      super();
70      this.exception = e;
71    }
72  
73  
74    /**
75      * Create a new <code>TilesException</code> from an existing exception.
76      *
77      * <p>The existing exception will be embedded in the new
78      * one, but the new exception will have its own message.</p>
79      *
80      * @param message The detail message.
81      * @param e The exception to be wrapped.
82      */
83    public TilesException(String message, Exception e)
84    {
85      super(message);
86      this.exception = e;
87    }
88  
89  
90    /**
91      * Return a detail message for this exception.
92      *
93      * <p>If there is a embedded exception, and if the TilesException
94      * has no detail message of its own, this method will return
95      * the detail message from the embedded exception.</p>
96      *
97      * @return The error or warning message.
98      */
99    public String getMessage ()
100   {
101     String message = super.getMessage ();
102 
103     if (message == null && exception != null) {
104       return exception.getMessage();
105     } else {
106       return message;
107     }
108   }
109 
110 
111   /**
112     * Return the embedded exception, if any.
113     *
114     * @return The embedded exception, or <code>null</code> if there is none.
115     */
116   public Exception getException ()
117   {
118     return exception;
119   }
120 
121 }