| ReporterEvent.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: ReporterEvent.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.common.util;
23
24 import java.util.EventObject;
25
26 import org.crosswire.common.icu.NumberShaper;
27
28 /**
29 * An event indicating that some bit of data needs capturing.
30 *
31 * @see gnu.lgpl.License for license details.<br>
32 * The copyright to this program is held by it's authors.
33 * @author Joe Walker [joe at eireneh dot com]
34 */
35 public class ReporterEvent extends EventObject {
36 /**
37 * Constructs an CaptureEvent object.
38 *
39 * @param source
40 * The event originator (typically <code>this</code>)
41 * @param ex
42 * An exception
43 */
44 public ReporterEvent(Object source, Throwable ex) {
45 super(source);
46
47 this.ex = ex;
48 this.message = null;
49 }
50
51 /**
52 * Constructs an CaptureEvent object.
53 *
54 * @param source
55 * The event originator (typically <code>this</code>)
56 * @param message
57 * An message to log
58 */
59 public ReporterEvent(Object source, String message) {
60 super(source);
61
62 this.ex = null;
63 this.message = new NumberShaper().shape(message);
64 }
65
66 /**
67 * Returns a string specifying the source of the message.
68 *
69 * @return The Source as a String
70 */
71 public String getSourceName() {
72 Object src = getSource();
73
74 Class<?> clazz;
75 if (src instanceof Class<?>) {
76 clazz = (Class<?>) src;
77 } else {
78 clazz = src.getClass();
79 }
80
81 String full = clazz.getName();
82 int lastDot = full.lastIndexOf('.');
83 if (lastDot == -1) {
84 return full;
85 }
86 return full.substring(lastDot + 1);
87 }
88
89 /**
90 * Returns the exception.
91 *
92 * @return the Exception
93 */
94 public Throwable getException() {
95 return ex;
96 }
97
98 /**
99 * Returns the message.
100 *
101 * @return the message
102 */
103 public String getMessage() {
104 return message;
105 }
106
107 /**
108 * The thing that went wrong
109 */
110 private Throwable ex;
111
112 /**
113 * The message that is being passed around
114 */
115 private String message;
116
117 /**
118 * Serialization ID
119 */
120 private static final long serialVersionUID = 4121978048640988213L;
121 }
122