View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
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  /*
17   * This source code implements specifications defined by the Java
18   * Community Process. In order to remain compliant with the specification
19   * DO NOT add / change / or delete method signatures!
20   */
21  package javax.portlet;
22  
23  
24  
25  /***
26   * The <CODE>PortletException</CODE> class defines a general exception
27   * that a portlet can throw when it is unable to perform its operation
28   * successfully.
29   */
30  
31  public class PortletException extends java.lang.Exception
32  {
33  
34  
35    private Throwable _cause;
36  
37  
38    /***
39     * Constructs a new portlet exception.
40     */
41  
42    public PortletException ()
43    {
44      super();
45    }
46  
47    /***
48     * Constructs a new portlet exception with the given text. The
49     * portlet container may use the text write it to a log.
50     *
51     * @param   text
52     *          the exception text
53     */
54  
55    public PortletException (String text)
56    {
57      super (text);
58    }
59  
60    /***
61     * Constructs a new portlet exception when the portlet needs to do
62     * the following:
63     * <ul>
64     * <li>throw an exception 
65     * <li>include the "root cause" exception
66     * <li>include a description message
67     * </ul>
68     *
69     * @param   text
70     *          the exception text
71     * @param   cause
72     *          the root cause
73     */
74    
75    public PortletException (String text, Throwable cause)
76    {
77      super(text);
78      _cause = cause;
79      // change this when going to jdk1.4:    super (text, cause);
80    }
81  
82    /***
83     * Constructs a new portlet exception when the portlet needs to throw an
84     * exception. The exception's message is based on the localized message
85     * of the underlying exception.
86     *
87     * @param   cause
88     *          the root cause
89     */
90  
91    public PortletException (Throwable cause)
92    {
93      _cause = cause;
94      // change this when going to jdk1.4:        super (cause);
95    }
96  
97    /***
98     * Prints the stack trace of this exception to the standard error stream.
99     */
100   public void printStackTrace()
101   {
102     this.printStackTrace(System.err);
103   }
104   
105   /***
106    * Prints the stack trace of this exception to the specified print stream.
107    *
108    * @param out the <code>PrintStream</code> to be used for output
109    */
110   public void printStackTrace(java.io.PrintStream out) 
111   {
112     this.printStackTrace(new java.io.PrintWriter(out, true));
113   }
114 
115   /***
116    * Prints the stack trace of this exception to the specified print writer.
117    * 
118    * @param out the <code>PrintWriter</code> to be used for output
119    */
120   public void printStackTrace(java.io.PrintWriter out)
121   {
122     super.printStackTrace(out);
123 
124     if( getCause () != null ) {
125       out.println();
126       out.print("Nested Exception is ");
127       getCause ().printStackTrace(out);
128     }
129     // change this when going tojdk1.4:
130       /*
131         super.printStackTrace(out);
132 
133         if( getRootCause () != null )
134         {
135             out.println();
136             out.print("Nested Exception is ");
137             getRootCause ().printStackTrace(out);
138         }
139         */
140   }
141 
142   /***
143    * Returns the cause of this throwable or <code>null</code> if the
144    * cause is nonexistent or unknown.  (The cause is the throwable that
145    * caused this throwable to get thrown.)
146    *
147    * <p>This implementation returns the cause that was supplied via one of
148    * the constructors requiring a <tt>Throwable</tt>.
149    *
150    * @return  the cause of this throwable or <code>null</code> if the
151    *          cause is nonexistent or unknown.
152    */
153   public Throwable getCause() {
154     return (_cause!=null ? _cause : null);
155   }
156 
157 }