1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.defaults;
11
12 import com.sri.emo.wizard.WizardMonitor;
13 import com.sri.emo.wizard.WizardPage;
14 import org.apache.log4j.Logger;
15
16 import java.io.Externalizable;
17 import java.io.IOException;
18 import java.io.ObjectInput;
19 import java.io.ObjectOutput;
20
21
22 /***
23 * Default implementation that logs to Log4j Logger when the various events are
24 * invoked.
25 *
26 * @author Michael Rimov
27 */
28 public class Log4jWizMonitor implements WizardMonitor, Externalizable {
29 /***
30 *
31 */
32 private static final long serialVersionUID = 1L;
33 /***
34 * Log4j Logger instance. Category == class name
35 */
36 private static final Logger LOG = Logger.getLogger(Log4jWizMonitor.class);
37
38 /***
39 * Logs with debug priority the source event toString().
40 * <p>{@inheritDoc}</p>
41 *
42 * @param src the Wizard Page that is the source of the event.
43 */
44 public void onEnterPage(final WizardPage src) {
45 if (LOG.isDebugEnabled()) {
46 LOG.debug("Entering page: " + src.toString());
47 }
48 }
49
50 /***
51 * Logs with debug priority the source event toString().
52 * <p>{@inheritDoc}</p>
53 *
54 * @param src the Wizard Page that is the source of the event.
55 */
56 public void onForward(final WizardPage src) {
57 if (LOG.isDebugEnabled()) {
58 LOG.debug("Forward Event Fired: " + src.toString());
59 }
60 }
61
62 /***
63 * Logs with debug priority the source event toString().
64 * <p>{@inheritDoc}</p>
65 *
66 * @param src the Wizard Page that is the source of the event.
67 */
68 public void onBack(final WizardPage src) {
69 if (LOG.isDebugEnabled()) {
70 LOG.debug("Back Event Fired: " + src.toString());
71 }
72 }
73
74 /***
75 * Logs with debug priority the source event toString().
76 * <p>{@inheritDoc}</p>
77 *
78 * @param src the Wizard Page that is the source of the event.
79 */
80 public void onFinish(final WizardPage src) {
81 if (LOG.isDebugEnabled()) {
82 LOG.debug("Finish Event Fired: " + src.toString());
83 }
84 }
85
86 /***
87 * Logs with <em>info</em> priority the source event toString().
88 * <p>{@inheritDoc}</p>
89 *
90 * @param src the Wizard Page that is the source of the event.
91 */
92 public void onCancel(final WizardPage src) {
93 if (LOG.isInfoEnabled()) {
94 LOG.info("Cancel Event Fired: " + src.toString());
95 }
96 }
97
98 /***
99 * Logs with error priority the source event toString() and the
100 * exception.
101 * <p>{@inheritDoc}</p>
102 *
103 * @param src the Wizard Page that is the source of the event.
104 * @param error the Exception thrown while processing the wizard.
105 */
106 public void onError(WizardPage src, final Throwable error) {
107 LOG.error("Error in wizard: " + src.toString(), error);
108 }
109
110 /***
111 * Nothing to write.
112 *
113 * @param out the object output stream.
114 * @throws IOException upon error.
115 */
116 public void writeExternal(final ObjectOutput out) throws IOException {
117 if (LOG.isDebugEnabled()) {
118 LOG.debug("Writing External");
119 }
120 }
121
122 /***
123 * Nothing to read.
124 *
125 * @param in the object input stream.
126 * @throws IOException when the class cannot be read from the stream.
127 * @throws ClassNotFoundException when the class cannot be found.
128 */
129 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
130
131 if (LOG.isDebugEnabled()) {
132 LOG.debug("Reading External");
133 }
134 }
135
136 /***
137 * Override of equals.
138 * {@inheritDoc}
139 *
140 * @param parm1 the other object.
141 * @return true if they're equal
142 */
143 public boolean equals(final Object parm1) {
144 return Log4jWizMonitor.class.equals(parm1.getClass());
145 }
146
147 /***
148 * Override of toString();
149 * {@inheritDoc}
150 *
151 * @return java.lang.String
152 */
153 public String toString() {
154 return "Log4j Wizard Monitor";
155 }
156
157 /***
158 * Since all log4j wizard monitors are equal, hash the class.
159 * {@inheritDoc}
160 *
161 * @return integer
162 */
163 public int hashCode() {
164 return getClass().hashCode();
165 }
166 }