KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtState


1
2
3 package Jt;
4 import java.util.*;
5 import java.lang.reflect.*;
6 import java.beans.*;
7 import java.io.*;
8
9 /**
10  * Jt Implementation of the State pattern.
11  */

12
13 public class JtState extends JtObject {
14
15
16   private Object JavaDoc state;
17
18
19   public JtState () {
20   }
21
22 /**
23   * Specifies the state.
24   *
25   * @param state state
26   */

27
28   public void setState (Object JavaDoc state) {
29      this.state = state;
30
31   }
32
33 /**
34   * Returns the state.
35   */

36
37   public Object JavaDoc getState () {
38      return (state);
39   }
40
41
42   /**
43     * Process object messages.
44     * <ul>
45     * </ul>
46     */

47
48   public Object JavaDoc processMessage (Object JavaDoc event) {
49
50    String JavaDoc msgid = null;
51    JtMessage e = (JtMessage) event;
52    Object JavaDoc content;
53    Object JavaDoc data;
54
55
56      if (e == null)
57     return null;
58
59      msgid = (String JavaDoc) e.getMsgId ();
60
61      if (msgid == null)
62     return null;
63
64      content = e.getMsgContent();
65      //data = e.getMsgData ();
66

67      //return (super.processMessage (event));
68

69
70      if (msgid.equals ("JtREMOVE")) {
71        return (null);
72      }
73
74
75      handleError ("JtState.processMessage: invalid message id:" + msgid);
76      return (null);
77
78
79   }
80
81  
82   /**
83    * Unit tests the messages processed by JtState
84    */

85
86   public static void main(String JavaDoc[] args) {
87
88     JtFactory factory = new JtFactory ();
89     JtState state;
90
91
92     // Create an instance of JtState
93

94     state = (JtState) factory.createObject ("Jt.JtState", "state");
95
96
97     // Remove the object
98

99     factory.removeObject (state);
100
101
102   }
103
104 }
105
106
107
Popular Tags