KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > ejb > examples > ValueObject


1 package Jt.ejb.examples;
2
3 import Jt.*;
4 import java.io.*;
5 import Jt.ejb.*;
6 import java.util.*;
7
8 // This class demonstrates the use of the Jt implementation of
9
// the J2EE ValueObject design pattern. A remote instance of
10
// Member is created. A single request is used to return its Value Object
11

12 public class ValueObject extends JtObject {
13
14
15
16   // Test program
17

18   public static void main(String JavaDoc[] args) {
19
20     JtFactory factory = new JtFactory (); // Jt Factory
21
String JavaDoc reply;
22     JtBusinessDelegate main;
23     JtValueObject valueObject;
24     JtMessage msg;
25
26     
27     // Create an instance of JtBusinessDelegate (Jt implementation of
28
// the J2EE business delegate pattern)
29

30     main = (JtBusinessDelegate) factory.createObject ("Jt.ejb.JtBusinessDelegate",
31      "businessDelegate");
32
33
34     // Create a remote instance of the Member class.
35

36
37     main.createObject ("Jt.examples.Member", "member");
38
39     // Set the attributes of the remote object
40

41     main.setValue ("member", "email", "test@hotmail.com");
42     main.setValue ("member", "tstamp", new Date ());
43     main.setValue ("member", "status", "1");
44     main.setValue ("member", "firstname", "John");
45     main.setValue ("member", "lastname", "Doe");
46
47     // This single request returns the Value Object
48

49     valueObject = (JtValueObject) main.sendMessage ("member", new JtMessage ("JtVALUE_OBJECT"));
50
51     // Print the attribute values using the local instance of the Value Object
52
// This is much faster and efficient.
53

54     
55     msg = new JtMessage ("JtGET");
56     msg.setMsgData ("email");
57     System.out.println (factory.sendMessage (valueObject, msg));
58
59     msg = new JtMessage ("JtGET");
60     msg.setMsgData ("tstamp");
61     System.out.println (factory.sendMessage (valueObject, msg));
62  
63     msg = new JtMessage ("JtGET");
64     msg.setMsgData ("status");
65     System.out.println (factory.sendMessage (valueObject, msg));
66
67     msg = new JtMessage ("JtGET");
68     msg.setMsgData ("firstname");
69     System.out.println (factory.sendMessage (valueObject, msg));
70
71     msg = new JtMessage ("JtGET");
72     msg.setMsgData ("lastname");
73     System.out.println (factory.sendMessage (valueObject, msg));
74     
75     // Remove the remote object instance
76

77     main.removeObject ("member");
78
79         
80   }
81
82 }
83
84
85
86
Popular Tags