KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > ejb > RemoteTestException


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.util.ejb;
23
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import java.io.StringWriter JavaDoc;
27
28 /**
29  * RemoteTestException is the client-side view of a throwable on the server.
30  *
31  * All throwables caught on the server are wrapped with a RemoteTestException
32  * and rethrown. On the client side the exception is caught, and if the
33  * server side exception is an instance of AssertionFailedError, it is
34  * wrapped with a RemoteAssertionFailedError and rethrown. That makes the
35  * exception an instance of AssertionFailedError so it is reconized as
36  * a failure and not an Error.
37  *
38  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
39  * @version $Revision: 37406 $
40  */

41 public class RemoteTestException extends Exception JavaDoc
42 {
43    private Throwable JavaDoc remoteThrowable;
44    private String JavaDoc remoteStackTrace;
45
46    /**
47     * Constructs a remote test exception that wrapps the the specified
48     * throwable.
49     * @param e the Throwable that was thrown on the server side
50     */

51    public RemoteTestException(Throwable JavaDoc e)
52    {
53       remoteThrowable = e;
54
55       StringWriter JavaDoc stringWriter = new StringWriter JavaDoc();
56       PrintWriter JavaDoc writer = new PrintWriter JavaDoc(stringWriter);
57       e.printStackTrace(writer);
58       StringBuffer JavaDoc buffer = stringWriter.getBuffer();
59       remoteStackTrace = buffer.toString();
60    }
61
62    /**
63     * Gets the message exactly as it appeared on server side.
64     * @return the message exactly as it appeared on server side
65     */

66    public String JavaDoc getMessage()
67    {
68       return remoteThrowable.getMessage();
69    }
70
71    /**
72     * Prints the stack trace exactly as it appeared on the server side.
73     * @param ps the PrintStream on which the stack trace is printed
74     */

75    public void printStackTrace(java.io.PrintStream JavaDoc ps)
76    {
77       ps.print(remoteStackTrace);
78    }
79
80    /**
81     * Prints the stack trace exactly as it appeared on the server side.
82     */

83    public void printStackTrace()
84    {
85       printStackTrace(System.err);
86    }
87
88    /**
89     * Prints the stack trace exactly as it appeared on the server side.
90     * @param pw the PrintWriter on which the stack trace is printed
91     */

92    public void printStackTrace(java.io.PrintWriter JavaDoc pw)
93    {
94       pw.print(remoteStackTrace);
95    }
96
97    /**
98     * Gets the throwable object from the server side.
99     * Note: the stack trace of this object is not available because
100     * exceptions don't seralize the stack trace. Use
101     * getRemoteStackTrace to get the stack trace as it appeared
102     * on the server.
103     * @return the Throwable object from the server side.
104     */

105    public Throwable JavaDoc getRemoteThrowable()
106    {
107       return remoteThrowable;
108    }
109
110    /**
111     * Gets the stack trace exactly as it appeared on the server side.
112     * @return the stack trace exactly as it appeared on the server side
113     */

114    public String JavaDoc getRemoteStackTrace()
115    {
116       return remoteStackTrace;
117    }
118 }
119
Popular Tags