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 JtFlyweight extends JtComposite { 14 15 private Object factory = null; 16 17 18 public JtFlyweight () { 19 } 20 21 22 23 28 29 public void setFactory (Object factory) { 30 this.factory = factory; 31 32 } 33 34 37 38 public Object getFactory () { 39 return (factory); 40 } 41 42 43 44 45 53 54 55 public Object processMessage (Object message) { 56 57 String msgid = null; 58 JtMessage e = (JtMessage) message; 59 Object content; 60 Object data; 61 JtMessage tmp; 62 JtInterface aux, aux1; 63 64 65 66 if (e == null) 67 return null; 68 69 msgid = (String ) e.getMsgId (); 70 71 if (msgid == null) 72 return null; 73 74 content = e.getMsgContent(); 75 data = e.getMsgData (); 76 77 if (msgid.equals ("JtREMOVE")) { 79 return (this); 80 } 81 82 83 if (msgid.equals ("JtGET_FLYWEIGHT")) { 84 tmp = new JtMessage ("JtGET_CHILD"); 85 tmp.setMsgData (e.getMsgData ()); 86 aux = (JtInterface) super.processMessage (tmp); 87 88 if (aux != null) 89 return (aux); 90 91 92 if (factory == null) { 93 handleError ("processMessage: factory attribute needs to be set"); 94 return (null); 95 } 96 97 99 tmp = new JtMessage ("JtCREATE_FLYWEIGHT"); 100 tmp.setMsgData (e.getMsgData ()); 101 102 aux1 = (JtInterface) sendMessage (factory, tmp); 103 104 tmp = new JtMessage ("JtADD_CHILD"); 105 tmp.setMsgContent (aux1); 106 tmp.setMsgData (e.getMsgData ()); 107 super.processMessage (tmp); 108 return (aux1); 109 110 111 } 112 113 114 return (super.processMessage (message)); 115 116 117 120 } 121 122 123 126 127 public static void main(String [] args) { 128 129 JtObject main = new JtFactory (); 130 131 JtFlyweight flyweightp; 132 133 135 flyweightp = (JtFlyweight) main.createObject ("Jt.JtFlyweight", "flyweight"); 136 137 139 140 main.removeObject ("flyweight"); 141 142 143 } 144 145 } 146 147 148
| Popular Tags
|