KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > model > StateModel


1 package org.oddjob.monitor.model;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.StringWriter JavaDoc;
5 import java.util.Observable JavaDoc;
6
7 import org.oddjob.state.JobStateEvent;
8
9 /**
10  * This class encapsualtes the model of a job state.
11  *
12  * @author Rob Gordon
13  */

14
15
16 public class StateModel extends Observable JavaDoc {
17
18     private String JavaDoc state;
19     private String JavaDoc time;
20     private String JavaDoc exception;
21                     
22
23     public void change(JobStateEvent event) {
24         state = event.getJobState().toString();
25         time = event.getTime().toString();
26         StringWriter JavaDoc stackBuffer = new StringWriter JavaDoc();
27         
28         Throwable JavaDoc t = event.getException();
29         if (t != null) {
30             PrintWriter JavaDoc writer = new PrintWriter JavaDoc(stackBuffer);
31             t.printStackTrace(writer);
32             exception = stackBuffer.toString();
33         }
34         else {
35             exception = "";
36         }
37         setChanged();
38         notifyObservers();
39     }
40         
41     /**
42      * @return Returns the exception.
43      */

44     public String JavaDoc getException() {
45         return exception;
46     }
47     /**
48      * @return Returns the state.
49      */

50     public String JavaDoc getState() {
51         return state;
52     }
53     /**
54      * @return Returns the time.
55      */

56     public String JavaDoc getTime() {
57         return time;
58     }
59     
60     public void clear() {
61         state = "";
62         time = "";
63         exception = "";
64         setChanged();
65         notifyObservers();
66     }
67
68 }
69
Popular Tags