1 4 5 package Jt.examples; 6 import java.util.*; 7 import java.lang.reflect.*; 8 import java.beans.*; 9 import java.io.*; 10 import Jt.*; 11 12 13 public class DateService extends JtObject { 14 15 16 17 public DateService() { 18 } 19 20 21 22 23 24 26 public Object processMessage (Object event) { 27 28 String msgid = null; 29 JtMessage e = (JtMessage) event; 30 Object content; 31 String dt; 32 33 if (e == null) 34 return null; 35 36 msgid = (String ) e.getMsgId (); 37 38 if (msgid == null) 39 return null; 40 41 content = e.getMsgContent(); 42 43 45 if (msgid.equals ("JtGET_DATE")) { 46 47 dt = "" + new Date (); 48 49 return (dt); 50 } 51 52 53 if (msgid.equals ("JtGET_TIME")) { 54 55 return (new Long ((new Date ()).getTime ())); 56 } 57 58 59 handleError ("DateService.processMessage: invalid message id:" + msgid); 60 return (null); 61 62 } 63 64 65 67 public static void main(String [] args) { 68 69 JtObject main = new JtObject (); 70 JtMessage msg1, msg2; 71 Integer count; 72 73 76 msg1 = new JtMessage (); 77 msg2 = new JtMessage (); 78 79 80 msg1.setMsgId ("JtGET_DATE"); 81 83 84 86 main.createObject ("Jt.examples.DateService", "template"); 87 88 89 90 92 System.out.println ((String ) main.sendMessage ("template", msg1)); 93 94 95 97 main.sendMessage ("template", msg2); 98 99 main.removeObject ("template"); 100 101 102 } 103 104 } 105 106 107 | Popular Tags |