2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.internal.client;
22  
23  import java.io.PrintStream;
24  import java.io.PrintWriter;
25  
26  import junit.framework.AssertionFailedError;
27  
28  /**
29   * Same as <code>ServletExceptionWrapper</code> except that this exception class
30   * extends JUnit <code>AssertionFailedError</code> so that JUnit will
31   * print a different message in it's runner console.
32   *
33   * @version $Id: AssertionFailedErrorWrapper.java 238991 2004-05-22 11:34:50Z vmassol $
34   */
35  public class AssertionFailedErrorWrapper extends AssertionFailedError
36  {
37      /**
38       * The stack trace that was sent back from the servlet redirector as a
39       * string.
40       */
41      private String stackTrace;
42  
43      /**
44       * The class name of the exception that was raised on the server side.
45       */
46      private String className;
47  
48      /**
49       * Standard throwable constructor.
50       *
51       * @param theMessage the exception message
52       */
53      public AssertionFailedErrorWrapper(String theMessage)
54      {
55          super(theMessage);
56      }
57  
58      /**
59       * Standard throwable constructor.
60       */
61      public AssertionFailedErrorWrapper()
62      {
63          super();
64      }
65  
66      /**
67       * The constructor to use to simulate a real exception.
68       *
69       * @param theMessage the server exception message
70       * @param theClassName the server exception class name
71       * @param theStackTrace the server exception stack trace
72       */
73      public AssertionFailedErrorWrapper(String theMessage, String theClassName, 
74          String theStackTrace)
75      {
76          super(theMessage);
77          this.className = theClassName;
78          this.stackTrace = theStackTrace;
79      }
80  
81      /**
82       * Simulates a printing of a stack trace by printing the string stack trace.
83       *
84       * @param thePs the stream to which to output the stack trace
85       */
86      public void printStackTrace(PrintStream thePs)
87      {
88          if (this.stackTrace == null)
89          {
90              thePs.print(getMessage());
91          }
92          else
93          {
94              thePs.print(this.stackTrace);
95          }
96      }
97  
98      /**
99       * Simulates a printing of a stack trace by printing the string stack trace.
100      *
101      * @param thePw the writer to which to output the stack trace
102      */
103     public void printStackTrace(PrintWriter thePw)
104     {
105         if (this.stackTrace == null)
106         {
107             thePw.print(getMessage());
108         }
109         else
110         {
111             thePw.print(this.stackTrace);
112         }
113     }
114 
115     /**
116      * @return the wrapped class name
117      */
118     public String getWrappedClassName()
119     {
120         return this.className;
121     }
122 }