KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtMediator


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 Mediator pattern.
11  */

12
13 public class JtMediator extends JtComposite {
14
15
16   public JtMediator () {
17   }
18
19
20
21   /**
22     * Process object messages. Let the superclass handle JtComposite related
23     * messages.
24     * <ul>
25     * </ul>
26     * @param message Jt Message
27     */

28
29
30   public Object JavaDoc processMessage (Object JavaDoc message) {
31
32    String JavaDoc msgid = null;
33    JtMessage e = (JtMessage) message;
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      data = e.getMsgData ();
48
49      // Remove this object
50
if (msgid.equals ("JtREMOVE")) {
51        return (this);
52      }
53
54      // Let the superclass handle JtComposite related
55

56      return (super.processMessage (message));
57
58   }
59
60  
61   /**
62    * Unit tests the messages processed by JtMediator
63    */

64
65   public static void main(String JavaDoc[] args) {
66
67     JtObject main = new JtFactory ();
68
69     JtMediator mediator;
70
71     // Create an instance of JtColletion
72

73     mediator = (JtMediator) main.createObject ("Jt.JtMediator", "mediator");
74
75
76     main.removeObject ("mediator");
77
78
79   }
80
81 }
82
83
84
Popular Tags