1 package Jt.examples.patterns; 2 import java.util.*; 3 import java.lang.reflect.*; 4 import java.beans.*; 5 import java.io.*; 6 import Jt.*; 7 8 9 12 13 14 public class SwitchFactory extends JtAbstractFactory { 15 16 17 18 public SwitchFactory() { 19 } 20 21 22 23 24 28 29 public Object processMessage (Object event) { 30 31 String msgid = null; 32 JtMessage e = (JtMessage) event; 33 Object content; 34 String data; 35 Object output; 36 37 38 if (e == null) 39 return null; 40 41 msgid = (String ) e.getMsgId (); 42 43 if (msgid == null) 44 return null; 45 46 content = e.getMsgContent(); 47 48 49 if (msgid.equals ("JtREMOVE")) { 51 return (this); 52 } 53 54 if (msgid.equals ("JtCREATE_FLYWEIGHT")) { 55 data = (String ) e.getMsgData (); 56 if (data == null) { 57 handleError ("JtCREATE_FLYWEIGHT: invalid key"); 58 return (null); 59 } 60 61 if (data.equals ("On")) 62 output = new OnSwitch (); 63 else 64 output = new OffSwitch (); 65 66 return (output); 67 } 68 69 handleError ("processMessage: invalid message id:" + msgid); 70 return (null); 71 72 73 } 74 75 76 77 } 78 79 | Popular Tags |