1 package Jt.examples; 2 3 import Jt.*; 4 import java.io.*; 5 6 7 public class HelloWorld extends JtObject { 8 9 private String greetingMessage; 10 11 public HelloWorld() { 12 } 13 14 16 17 public void setGreetingMessage (String message) { 18 this.greetingMessage = message; 20 } 21 22 public String getGreetingMessage () { 23 return (greetingMessage); 24 } 25 26 27 29 public Object processMessage (Object message) { 30 31 String msgid = null; 32 JtMessage msg = (JtMessage) message; 33 Object content; 34 35 if (msg == null) 36 return null; 37 38 msgid = (String ) msg.getMsgId (); 39 40 if (msgid == null) 41 return null; 42 43 content = msg.getMsgContent(); 44 45 47 if (msgid.equals ("JtHello")) { 48 49 handleTrace ("HelloWorld returning a greeting message: " + greetingMessage); 50 51 return (greetingMessage); 52 } 53 54 if (msgid.equals ("JtREMOVE")) { 55 return (null); 56 } 57 58 handleError ("HelloWorld.processMessage: invalid message id:" + msgid); 59 return (null); 60 61 } 62 63 64 66 public static void main(String [] args) { 67 68 JtFactory main = new JtFactory (); JtMessage msg; 70 String greeting; 71 String reply; 72 73 74 76 main.createObject ("Jt.examples.HelloWorld", "helloWorld"); 77 78 79 83 greeting = (String ) main.getValue ("helloWorld", "greetingMessage"); 84 85 if (greeting == null || greeting.equals ("")) 86 main.setValue ("helloWorld", "greetingMessage", "Hello World ..."); 87 88 89 91 msg = new JtMessage ("JtHello"); 92 93 94 95 97 main.handleTrace ("main:sending a message (JtHello) to the helloWorld object ..."); 98 reply = (String ) main.sendMessage ("helloWorld", msg); 99 100 System.out.println (reply); 102 103 105 main.removeObject ("helloWorld"); 106 107 108 109 } 110 111 } 112 113 114 115 | Popular Tags |