KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > output > ErrorResult


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server.output;
10
11 import java.io.PrintWriter JavaDoc;
12 import java.io.StringWriter JavaDoc;
13
14 import org.jboss.portal.server.WindowContext;
15
16 /**
17  * Application level error.
18  *
19  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
20  * @version $Revision: 1.2 $
21  */

22 public class ErrorResult extends Result
23 {
24    /** The logged throwable if any. */
25    private final Throwable JavaDoc throwable;
26
27    /** There must be one error message. */
28    private final String JavaDoc message;
29
30    public ErrorResult(WindowContext producer, String JavaDoc message)
31    {
32       super(producer);
33       if (message == null)
34       {
35          throw new IllegalArgumentException JavaDoc("There must be a message");
36       }
37       this.throwable = null;
38       this.message = message;
39    }
40
41    public ErrorResult(WindowContext producer, Throwable JavaDoc throwable)
42    {
43       super(producer);
44       if (throwable == null)
45       {
46          throw new IllegalArgumentException JavaDoc("There must be a throwable");
47       }
48       this.throwable = throwable;
49       this.message = throwable.getMessage();
50    }
51
52    /**
53     * The throwable. Can be a null object.
54     */

55    public Throwable JavaDoc getThrowable()
56    {
57       return throwable;
58    }
59
60    /**
61     * The logged message.
62     */

63    public String JavaDoc getMessage()
64    {
65       return message;
66    }
67
68    public String JavaDoc toString()
69    {
70       if (throwable != null)
71       {
72          StringWriter JavaDoc writer = new StringWriter JavaDoc();
73          writer.write("Error :\n");
74          throwable.printStackTrace(new PrintWriter JavaDoc(writer));
75          return writer.toString();
76       }
77       else
78       {
79          return "Error";
80       }
81    }
82 }
83
Popular Tags