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 JtPrototype extends JtObject { 14 15 16 17 18 public JtPrototype () { 19 } 20 21 23 private Object cloneObject () { 24 25 26 JtMessage msg = new JtMessage ("JtENCODE_OBJECT"); 27 JtObject tmp = new JtObject(); 28 Object aux; 29 30 msg.setMsgContent (this); 31 aux = tmp.processMessage (msg); 32 33 if (aux == null) { 34 handleError ("cloneObject: Unable to encode the object (XML format"); 35 return (null); 36 } 37 38 msg = new JtMessage ("JtDECODE_OBJECT"); 39 40 msg.setMsgContent (aux); 41 return (tmp.processMessage (msg)); 42 } 43 44 private Object test () { 45 46 JtObject tmp; 47 48 49 tmp = (JtObject) processMessage (new JtMessage ("JtCLONE")); 50 51 if (tmp == null) 52 return (null); 53 54 return (tmp.processMessage (new JtMessage ("JtPRINT_OBJECT"))); 55 } 56 57 63 64 public Object processMessage (Object event) { 65 66 String msgid = null; 67 JtMessage e = (JtMessage) event; 68 Object content; 69 Object data; 70 71 72 if (e == null) 73 return null; 74 75 msgid = (String ) e.getMsgId (); 76 77 if (msgid == null) 78 return null; 79 80 content = e.getMsgContent(); 81 83 85 if (msgid.equals ("JtCLONE")) { 86 return (cloneObject ()); 87 } 88 89 90 if (msgid.equals ("JtPRINT_OBJECT")) { 91 return (super.processMessage (event)); 92 } 93 94 95 if (msgid.equals ("JtTEST")) { 96 return (test ()); 97 } 98 99 100 if (msgid.equals ("JtREMOVE")) { 101 return (null); 102 } 103 104 105 handleError ("JtPrototype.processMessage: invalid message id:" + msgid); 106 return (null); 107 108 109 } 110 111 112 115 116 public static void main(String [] args) { 117 118 JtFactory factory = new JtFactory (); 119 JtPrototype proto; 120 121 122 124 proto = (JtPrototype) factory.createObject ("Jt.JtPrototype", "proto"); 125 126 127 factory.sendMessage (proto, new JtMessage ("JtTEST")); 128 129 131 factory.removeObject (proto); 132 133 134 } 135 136 } 137 138 139 | Popular Tags |