KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > poa_monitor > user_poa > FooFactoryImpl


1 package demo.poa_monitor.user_poa;
2
3 import demo.poa_monitor.foox.*;
4 import org.omg.PortableServer.*;
5
6 public class FooFactoryImpl
7     extends FooFactoryPOA
8 {
9     private static FooImpl single = new FooImpl("0");
10
11     public POA _default_POA()
12     {
13         POA rootPOA = super._default_POA();
14         try
15         {
16             return rootPOA.find_POA(Server.factoryPOAName, false);
17         }
18         catch( org.omg.PortableServer.POAPackage.AdapterNonExistent JavaDoc e )
19         {
20             e.printStackTrace();
21             return rootPOA;
22         }
23     }
24
25     public Foo createFoo(String JavaDoc id)
26     {
27         Foo result = null;
28         try {
29             POA fooPOA = _default_POA().find_POA(Server.fooPOAName, true);
30
31             if (Server.kind == 1 || Server.kind == 2 || Server.kind == 3)
32             {
33                 byte[] oid = id.getBytes();
34                 result = FooHelper.narrow(fooPOA.create_reference_with_id(oid, FooHelper.id()));
35             }
36             else if (Server.kind == 4)
37             {
38                 result = FooHelper.narrow(fooPOA.create_reference(FooHelper.id()));
39             
40             }
41             else if (Server.kind == 5)
42             {
43                 result = FooHelper.narrow(fooPOA.servant_to_reference(single));
44                 /* for testing the colocation optimization */
45                 System.out.println("[ invocation of the coolocated Foo object ... ]");
46                 result.compute(0);
47                 System.out.println("[ ... done ]");
48                 /*******************************************/
49             }
50             else
51             {
52                 result = FooHelper.narrow(fooPOA.servant_to_reference(new FooImpl("0")));
53             }
54         } catch (Exception JavaDoc e) {
55             e.printStackTrace();
56         }
57         System.out.println("[ Foo created with id: "+id+" ]");
58         return result;
59     }
60
61     public String JavaDoc getServerDescription()
62     {
63         String JavaDoc myOid = "unknown";
64         try
65         {
66             org.omg.PortableServer.Current JavaDoc current =
67                 org.omg.PortableServer.CurrentHelper.narrow(_orb().resolve_initial_references("POACurrent"));
68             myOid = new String JavaDoc(current.get_object_id());
69             
70         }
71         catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc in)
72         {
73             System.out.println("POACurrent not available!");
74             
75         }
76         catch (org.omg.PortableServer.CurrentPackage.NoContext JavaDoc nc) {
77             System.out.println("Cannot determine the context oid!");
78         }
79
80         System.out.println("[ "+myOid+": description requested (\""+Server.description+"\") ]");
81         return Server.description;
82     }
83 }
84
Popular Tags