Source code: com/eireneh/util/event/ReporterEvent.java
1
2 package com.eireneh.util.event;
3
4 import java.util.*;
5
6 import com.eireneh.util.*;
7
8 /**
9 * An event indicating that some bit of data needs capturing.
10 *
11 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
12 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
13 * Distribution Licence:<br />
14 * Project B is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General Public License,
16 * version 2 as published by the Free Software Foundation.<br />
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.<br />
21 * The License is available on the internet
22 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
23 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
25 * The copyright to this program is held by it's authors.
26 * </font></td></tr></table>
27 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
28 * @see docs.Licence
29 * @author Joe Walker
30 */
31 public class ReporterEvent extends EventObject
32 {
33 /**
34 * Constructs an CaptureEvent object.
35 * @param source The event originator (typically <code>this</code>)
36 * @param ev An exception
37 */
38 public ReporterEvent(Throwable ex)
39 {
40 super(Reporter.class);
41
42 this.ex = ex;
43 this.message = null;
44 }
45
46 /**
47 * Constructs an CaptureEvent object.
48 * @param source The event originator (typically <code>this</code>)
49 * @param ev An exception
50 */
51 public ReporterEvent(String message)
52 {
53 super(Reporter.class);
54
55 this.ex = null;
56 this.message = message;
57 }
58
59 /**
60 * Returns a string specifying the source of the message.
61 * @return The Source as a String
62 */
63 public String getSourceName()
64 {
65 Class clazz;
66 Object source = getSource();
67 if (source instanceof Class)
68 clazz = (Class) source;
69 else
70 clazz = source.getClass();
71
72 String full = clazz.getName();
73 int last_dot = full.lastIndexOf(".");
74
75 if (last_dot == -1)
76 return full;
77 else
78 return full.substring(last_dot+1);
79 }
80
81 /**
82 * Returns the exception.
83 * @return the Exception
84 */
85 public Throwable getException()
86 {
87 return ex;
88 }
89
90 /**
91 * Returns the message.
92 * @return the message
93 */
94 public String getMessage()
95 {
96 return message;
97 }
98
99 /** The thing that went wrong */
100 private Throwable ex;
101
102 /** The message that is being passed around */
103 private String message;
104 }