KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtEcho


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  * Echo the message received using XML format.
11  */

12
13 public class JtEcho extends JtObject {
14
15
16
17   public JtEcho() {
18   }
19
20
21
22
23   /**
24     * Process object messages (echoes the message using XML format).
25     * <ul>
26     * </ul>
27     */

28
29   public Object JavaDoc processMessage (Object JavaDoc event) {
30
31    String JavaDoc msgid = null;
32    JtMessage e = (JtMessage) event;
33    Object JavaDoc content;
34    Object JavaDoc data;
35
36
37      if (e == null)
38     return null;
39
40      msgid = (String JavaDoc) e.getMsgId ();
41
42      if (msgid == null)
43     return null;
44
45      content = e.getMsgContent();
46      //data = e.getMsgData ();
47
System.out.println ("JtEcho("+ this.getObjName() + "):received a message:"
48      + msgid + "...");
49
50      e.processMessage (new JtMessage ("JtPRINT_OBJECT"));
51
52 /*
53      if (msgid.equals ("JtPRINT_OBJECT")) {
54        return (super.processMessage (this));
55      }
56 */

57      return (this);
58
59 /*
60
61      if (msgid.equals ("JtREMOVE")) {
62        return (super.processMessage (null));
63      }
64
65
66      handleError ("JtECHO.processMessage: invalid message id:" + msgid);
67      return (null);
68 */

69
70   }
71
72  
73   /**
74    * Unit tests the messages processed by JtEcho.
75    */

76
77   public static void main(String JavaDoc[] args) {
78
79     JtFactory main = new JtFactory ();
80     JtEcho echo;
81  
82
83     // Create JtDecorator
84

85     echo = (JtEcho) main.createObject ("Jt.JtEcho", "echo");
86
87     main.sendMessage (echo, new JtMessage ("JtTEST"));
88
89
90     //main.removeObject ("echo");
91

92
93   }
94
95 }
96
97
98
Popular Tags