KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtBridge


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

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

25
26   public void setImplementor (Object JavaDoc implementor) {
27      this.implementor = implementor;
28
29   }
30
31 /**
32   * Returns the implementor.
33   */

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

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

66      if (implementor == null) {
67        handleError ("JtBridge.process: the implementor attribute needs to be set");
68        return (null);
69      }
70
71      // Let the implementor process the request
72

73      return (sendMessage (implementor, event));
74
75 /*
76      if (msgid.equals ("JtREMOVE")) {
77        return (this);
78      }
79
80
81      handleError ("JtBridge.processMessage: invalid message id:" + msgid);
82      return (null);
83 */

84
85   }
86
87  
88   /**
89    * Unit tests the messages processed by JtBridge.
90    */

91
92
93   public static void main(String JavaDoc[] args) {
94
95     JtFactory factory = new JtFactory ();
96     JtBridge bridge;
97
98     JtMessage msg;
99
100     // Create an instance of JtBridge
101

102     bridge = (JtBridge) factory.createObject ("Jt.JtBridge", "bridge");
103
104     // Remove the object
105

106     factory.removeObject ("bridge");
107
108
109   }
110
111
112 }
113
114
115
Popular Tags