KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > ejb > JtBusinessDelegate


1
2 package Jt.ejb;
3
4
5 import javax.ejb.*;
6 import javax.naming.*;
7 import java.rmi.*;
8
9 import java.beans.*;
10 import java.io.*;
11 import java.util.*;
12 import Jt.*;
13 import Jt.xml.*;
14
15
16 /**
17   * Jt implementation of the J2EE Business Delegate pattern.
18   */

19
20 public class JtBusinessDelegate extends JtEJBAdapter {
21
22  
23
24   public JtBusinessDelegate () {
25   }
26
27
28
29   /**
30     * Process object messages.
31     * <ul>
32     * <li> JtTEST - Tests the messages processes by JtBusinessDelegate
33     * </ul>
34     * @param event message
35     */

36
37   public Object JavaDoc processMessage (Object JavaDoc event) {
38
39    String JavaDoc msgid = null;
40    JtMessage e = (JtMessage) event;
41    Object JavaDoc content;
42
43      if (e == null)
44     return null;
45
46      msgid = (String JavaDoc) e.getMsgId ();
47
48      if (msgid == null)
49     return null;
50
51      content = e.getMsgContent();
52
53      if (msgid.equals ("JtTEST")) {
54        return (test ());
55      }
56
57      // Let the superclass (JtEJBAdapter) do most of the work (handle the
58
// EJB related functionality
59

60      return (super.processMessage (event));
61
62   }
63
64
65   private Object JavaDoc test () {
66
67     String JavaDoc tmp;
68     String JavaDoc reply = null;
69     Exception JavaDoc ex;
70
71
72     // Create a remote instance of the HelloWorld class. The JtBusinessDelegate class
73
// can be used to create remote instances of any Jt Framework class.
74
// HelloWorld is used as an example.
75

76     createObject ("Jt.examples.HelloWorld", "helloWorld");
77
78
79
80     // Set the greetingMessage attribute
81

82     setValue ("helloWorld", "greetingMessage", "Hello there...");
83
84
85 /*
86     tmp = (String) getValue ("helloWorld", "greetingMessage");
87
88
89     if (tmp == null || !tmp.equals ("Hello there...")) {
90       handleError ("test: getValue failed");
91     }
92 */

93
94     // Create a remote message (JtHello)
95

96     //createObject ("Jt.JtMessage", "message");
97
//setValue ("message", "msgId", "JtHello");
98

99
100     // Send JtHello to the remote helloWorld object
101

102     //reply = (String) sendMessage ("helloWorld", "message");
103
reply = (String JavaDoc) sendMessage ("helloWorld", new JtMessage ("JtHello"));
104
105
106     // Remove the remote instance of HelloWorld
107

108     removeObject ("helloWorld");
109
110     return (reply);
111
112   }
113
114  /**
115    * Unit tests all the messages processed by JtBusinessDelegate.
116    */

117
118   public static void main(String JavaDoc[] args) {
119
120     JtObject main = new JtObject ();
121     JtBusinessDelegate businessDelegate;
122     String JavaDoc str;
123     String JavaDoc reply = null;
124     Exception JavaDoc ex;
125
126     //main.setObjTrace (1);
127
//main.setLogFile ("log.txt");
128

129
130     // Create the Jt businessDelegate
131

132     businessDelegate = (JtBusinessDelegate) main.createObject ("Jt.ejb.JtBusinessDelegate",
133      "businessDelegate");
134
135
136     // send a test message (JtTEST) to the delegate
137

138
139     reply = (String JavaDoc) main.sendMessage (businessDelegate, new JtMessage ("JtTEST"));
140     
141
142     // ex = (Exception) main.getValue (businessDelegate, "objException");
143

144
145     // Display the reply unless an exception is detected
146

147
148     //if (ex == null)
149
System.out.println (reply);
150     //else
151

152       //System.out.println (ex);
153

154     // Remove the business delegate
155

156     main.removeObject (businessDelegate);
157
158   }
159
160 }
161
162
163
Popular Tags