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 JtStrategy extends JtObject { 14 15 16 private Object concreteStrategy = null; 18 19 public JtStrategy () { 20 } 21 22 23 24 27 28 29 public void setConcreteStrategy (Object concreteStrategy) { 30 this.concreteStrategy = concreteStrategy; 31 } 32 33 34 37 38 public Object getConcreteStrategy () { 39 return (concreteStrategy); 40 } 41 42 43 44 45 46 47 54 55 public Object processMessage (Object event) { 56 57 String msgid = null; 58 JtMessage e = (JtMessage) event; 59 Object content; 60 Object data; 61 62 63 if (e == null) 64 return null; 65 66 msgid = (String ) e.getMsgId (); 67 68 if (msgid == null) 69 return null; 70 71 content = e.getMsgContent(); 72 74 75 if (msgid.equals ("JtREMOVE")) { 76 return (null); 77 } 78 79 81 if (concreteStrategy == null) { 82 handleError ("processMessage: concreteStrategy attribute must be set"); 83 return (null); 84 } 85 86 return (((JtObject) concreteStrategy).processMessage (event)); 87 88 89 } 90 91 92 95 96 public static void main(String [] args) { 97 98 JtFactory factory = new JtFactory (); 99 JtStrategy strategy; 100 JtObject concreteStrategy; 101 102 104 strategy = (JtStrategy) factory.createObject ("Jt.JtStrategy", "strategy"); 105 106 108 concreteStrategy = (JtObject) factory.createObject ("Jt.JtEcho", "concreteStrategy"); 109 factory.setValue (strategy, "concreteStrategy", concreteStrategy); 110 111 112 factory.sendMessage (strategy, new JtMessage ("JtEXECUTE_STRATEGY")); 113 114 factory.removeObject ("strategy"); 115 116 117 } 118 119 } 120 121 122 | Popular Tags |