Source code: com/eireneh/util/event/CaptureEvent.java
1
2 package com.eireneh.util.event;
3
4 import java.util.*;
5
6 /**
7 * An event indicating that some bit of data needs capturing.
8 *
9 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
10 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
11 * Distribution Licence:<br />
12 * Project B is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General Public License,
14 * version 2 as published by the Free Software Foundation.<br />
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.<br />
19 * The License is available on the internet
20 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
21 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
23 * The copyright to this program is held by it's authors.
24 * </font></td></tr></table>
25 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
26 * @see docs.Licence
27 * @author Joe Walker
28 */
29 public class CaptureEvent extends EventObject
30 {
31 /**
32 * Constructs an CaptureEvent object.
33 * @param source The event originator (typically <code>this</code>)
34 * @param ev An exception
35 */
36 public CaptureEvent(Object source, Throwable ex, int level)
37 {
38 super(source);
39
40 this.ex = ex;
41 this.message = null;
42 this.level = level;
43 }
44
45 /**
46 * Constructs an CaptureEvent object.
47 * @param source The event originator (typically <code>this</code>)
48 * @param ev An exception
49 */
50 public CaptureEvent(Object source, String message, int level)
51 {
52 super(source);
53
54 this.ex = null;
55 this.message = message;
56 this.level = level;
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 /**
100 * Returns the level.
101 * @return the level
102 */
103 public int getLevel()
104 {
105 return level;
106 }
107
108 /** The thing that went wrong */
109 private Throwable ex;
110
111 /** The message that is being passed around */
112 private String message;
113
114 /** The level */
115 private int level;
116 }