KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > client > AssertionFailedErrorWrapper


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.internal.client;
21
22 import java.io.PrintStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 import junit.framework.AssertionFailedError;
26
27 /**
28  * Same as <code>ServletExceptionWrapper</code> except that this exception class
29  * extends JUnit <code>AssertionFailedError</code> so that JUnit will
30  * print a different message in it's runner console.
31  *
32  * @version $Id: AssertionFailedErrorWrapper.java,v 1.1 2004/05/22 11:34:47 vmassol Exp $
33  */

34 public class AssertionFailedErrorWrapper extends AssertionFailedError
35 {
36     /**
37      * The stack trace that was sent back from the servlet redirector as a
38      * string.
39      */

40     private String JavaDoc stackTrace;
41
42     /**
43      * The class name of the exception that was raised on the server side.
44      */

45     private String JavaDoc className;
46
47     /**
48      * Standard throwable constructor.
49      *
50      * @param theMessage the exception message
51      */

52     public AssertionFailedErrorWrapper(String JavaDoc theMessage)
53     {
54         super(theMessage);
55     }
56
57     /**
58      * Standard throwable constructor.
59      */

60     public AssertionFailedErrorWrapper()
61     {
62         super();
63     }
64
65     /**
66      * The constructor to use to simulate a real exception.
67      *
68      * @param theMessage the server exception message
69      * @param theClassName the server exception class name
70      * @param theStackTrace the server exception stack trace
71      */

72     public AssertionFailedErrorWrapper(String JavaDoc theMessage, String JavaDoc theClassName,
73         String JavaDoc theStackTrace)
74     {
75         super(theMessage);
76         this.className = theClassName;
77         this.stackTrace = theStackTrace;
78     }
79
80     /**
81      * Simulates a printing of a stack trace by printing the string stack trace
82      *
83      * @param thePs the stream to which to output the stack trace
84      */

85     public void printStackTrace(PrintStream JavaDoc thePs)
86     {
87         if (this.stackTrace == null)
88         {
89             thePs.print(getMessage());
90         }
91         else
92         {
93             thePs.print(this.stackTrace);
94         }
95     }
96
97     /**
98      * Simulates a printing of a stack trace by printing the string stack trace
99      *
100      * @param thePw the writer to which to output the stack trace
101      */

102     public void printStackTrace(PrintWriter JavaDoc thePw)
103     {
104         if (this.stackTrace == null)
105         {
106             thePw.print(getMessage());
107         }
108         else
109         {
110             thePw.print(this.stackTrace);
111         }
112     }
113
114     /**
115      * @return the wrapped class name
116      */

117     public String JavaDoc getWrappedClassName()
118     {
119         return this.className;
120     }
121 }
122
Popular Tags