1 2 3 package Jt; 4 import java.util.*; 5 import java.lang.reflect.*; 6 import java.beans.*; 7 import java.io.*; 8 9 12 13 public class JtFacade extends JtComposite { 14 15 16 public JtFacade () { 17 } 18 19 20 22 private Object test () { 23 JtMessage msg, tmp; 24 25 28 System.out.println 29 ("Sending a JtTEST message to all the subsystems of the facade ..."); 30 31 msg = new JtMessage ("JtBROADCAST"); 32 33 tmp = new JtMessage ("JtTEST"); 34 35 msg.setMsgContent (tmp); 36 37 38 return (sendMessage (this, msg)); 39 40 } 41 42 48 49 public Object processMessage (Object event) { 50 51 String msgid = null; 52 JtMessage e = (JtMessage) event; 53 Object content; 54 Object data; 55 56 57 if (e == null) 58 return null; 59 60 msgid = (String ) e.getMsgId (); 61 62 if (msgid == null) 63 return null; 64 65 content = e.getMsgContent(); 66 68 69 if (msgid.equals ("JtTEST")) { 70 return (test ()); 71 } 72 73 return (super.processMessage (event)); 74 83 84 } 85 86 87 90 91 92 public static void main(String [] args) { 93 94 JtFactory factory = new JtFactory (); 95 JtFacade facade; 96 JtEcho echo1; 97 JtEcho echo2; 98 JtMessage msg; 99 100 102 facade = (JtFacade) factory.createObject ("Jt.JtFacade", "facade"); 103 104 105 echo1 = (JtEcho) factory.createObject ("Jt.JtEcho", "echo1"); 106 echo2 = (JtEcho) factory.createObject ("Jt.JtEcho", "echo2"); 107 108 109 System.out.println ("JtFacade(JtADD_CHILD): adding a subsystem ..."); 110 111 msg = new JtMessage ("JtADD_CHILD"); 112 113 factory.setValue (msg, "msgContent", echo1); 114 factory.setValue (msg, "msgData", "echo1"); 115 116 factory.sendMessage (facade, msg); 117 118 119 System.out.println ("JtFacade(JtADD_CHILD): adding a subsystem ..."); 120 121 msg = new JtMessage ("JtADD_CHILD"); 122 123 factory.setValue (msg, "msgContent", echo2); 124 factory.setValue (msg, "msgData", "echo2"); 125 126 factory.sendMessage (facade, msg); 127 128 129 factory.sendMessage (facade, new JtMessage ("JtTEST")); 130 131 factory.removeObject ("facade"); 132 133 134 } 135 136 137 } 138 139 140
| Popular Tags
|