KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > examples > patterns > OffSwitch


1 package Jt.examples.patterns;
2 import java.util.*;
3 import java.lang.reflect.*;
4 import java.beans.*;
5 import java.io.*;
6 import Jt.*;
7
8
9
10 /**
11  * Demonstrates the use of the State pattern (see Flyweight.java).
12  */

13
14
15 public class OffSwitch extends JtState {
16
17
18
19   public OffSwitch () {
20   }
21
22
23
24
25   /**
26     * Process object messages.
27     * <ul>
28     * </ul>
29     * @param event Jt Message
30     */

31
32   public Object JavaDoc processMessage (Object JavaDoc event) {
33
34    String JavaDoc msgid = null;
35    JtMessage e = (JtMessage) event;
36    Object JavaDoc content;
37    Object JavaDoc data;
38    JtMessage aux;
39
40
41      if (e == null)
42     return null;
43
44      msgid = (String JavaDoc) e.getMsgId ();
45
46      if (msgid == null)
47     return null;
48
49      content = e.getMsgContent();
50
51      if (msgid.equals ("JtREMOVE")) {
52        return (this);
53      }
54
55      if (msgid.equals ("JtSWITCH_VALUE")) {
56        return ("Off");
57      }
58      handleError ("processMessage: invalid message id:" + msgid);
59      return (null);
60
61   }
62
63  
64 }
65
Popular Tags