Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ReporterEvent |
|
| 1.6;1.6 |
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 or later | |
5 | * as published by the Free Software Foundation. This program is distributed | |
6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
7 | * the 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 | * © CrossWire Bible Society, 2005 - 2016 | |
18 | * | |
19 | */ | |
20 | package org.crosswire.common.util; | |
21 | ||
22 | import java.util.EventObject; | |
23 | ||
24 | import org.crosswire.common.icu.NumberShaper; | |
25 | ||
26 | /** | |
27 | * An event indicating that some bit of data needs capturing. | |
28 | * | |
29 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
30 | * @author Joe Walker | |
31 | */ | |
32 | public class ReporterEvent extends EventObject { | |
33 | /** | |
34 | * Constructs an CaptureEvent object. | |
35 | * | |
36 | * @param source | |
37 | * The event originator (typically <code>this</code>) | |
38 | * @param ex | |
39 | * An exception | |
40 | */ | |
41 | public ReporterEvent(Object source, Throwable ex) { | |
42 | 0 | super(source); |
43 | ||
44 | 0 | this.ex = ex; |
45 | 0 | this.message = null; |
46 | 0 | } |
47 | ||
48 | /** | |
49 | * Constructs an CaptureEvent object. | |
50 | * | |
51 | * @param source | |
52 | * The event originator (typically <code>this</code>) | |
53 | * @param message | |
54 | * An message to log | |
55 | */ | |
56 | public ReporterEvent(Object source, String message) { | |
57 | 0 | super(source); |
58 | ||
59 | 0 | this.ex = null; |
60 | 0 | this.message = new NumberShaper().shape(message); |
61 | 0 | } |
62 | ||
63 | /** | |
64 | * Returns a string specifying the source of the message. | |
65 | * | |
66 | * @return The Source as a String | |
67 | */ | |
68 | public String getSourceName() { | |
69 | 0 | Object src = getSource(); |
70 | ||
71 | Class<?> clazz; | |
72 | 0 | if (src instanceof Class<?>) { |
73 | 0 | clazz = (Class<?>) src; |
74 | } else { | |
75 | 0 | clazz = src.getClass(); |
76 | } | |
77 | ||
78 | 0 | String full = clazz.getName(); |
79 | 0 | int lastDot = full.lastIndexOf('.'); |
80 | 0 | if (lastDot == -1) { |
81 | 0 | return full; |
82 | } | |
83 | 0 | return full.substring(lastDot + 1); |
84 | } | |
85 | ||
86 | /** | |
87 | * Returns the exception. | |
88 | * | |
89 | * @return the Exception | |
90 | */ | |
91 | public Throwable getException() { | |
92 | 0 | return ex; |
93 | } | |
94 | ||
95 | /** | |
96 | * Returns the message. | |
97 | * | |
98 | * @return the message | |
99 | */ | |
100 | public String getMessage() { | |
101 | 0 | return message; |
102 | } | |
103 | ||
104 | /** | |
105 | * The thing that went wrong | |
106 | */ | |
107 | private Throwable ex; | |
108 | ||
109 | /** | |
110 | * The message that is being passed around | |
111 | */ | |
112 | private String message; | |
113 | ||
114 | /** | |
115 | * Serialization ID | |
116 | */ | |
117 | private static final long serialVersionUID = 4121978048640988213L; | |
118 | } |