KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtVisitor


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

11
12
13 public class JtVisitor extends JtObject {
14
15
16   public JtVisitor() {
17   }
18
19
20
21   /**
22     * Process object messages.
23     * <ul>
24     * <li>JtVISIT - visit the object specified by msgContent. Subclasses need to
25     * override this method and provide a complete implementation for this message.
26     * </ul>
27     * @param event Jt Message
28     */

29
30   public Object JavaDoc processMessage (Object JavaDoc event) {
31
32    String JavaDoc msgid = null;
33    JtMessage e = (JtMessage) event;
34    Object JavaDoc content;
35    Object JavaDoc data;
36
37
38      if (e == null)
39     return null;
40
41      msgid = (String JavaDoc) e.getMsgId ();
42
43      if (msgid == null)
44     return null;
45
46      content = e.getMsgContent();
47
48      if (msgid.equals ("JtREMOVE")) {
49        return (this);
50      }
51
52      if (msgid.equals ("JtVISIT")) {
53        return (this);
54      }
55
56      handleError ("JtVisitor.processMessage: invalid message id:" + msgid);
57      return (null);
58
59   }
60
61   /**
62     * Unit Tests the messages processed by JtVisitor.
63     */

64
65   public static void main(String JavaDoc[] args) {
66
67     JtObject main = new JtFactory ();
68     JtMessage msg;
69     JtVisitor visitor;
70
71
72     // Create an instance of JtVisitor
73

74     visitor = (JtVisitor)
75       main.createObject ("Jt.JtVisitor",
76       "visitor");
77
78
79     main.removeObject (visitor);
80
81
82     
83          
84
85   }
86
87 }
88
Popular Tags