KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > interceptor > ctx_passing > Server


1 package test.interceptor.ctx_passing;
2
3 import java.io.*;
4
5 import org.omg.CORBA.*;
6 import org.omg.PortableServer.*;
7
8 class TestObjectImpl
9     extends TestObjectPOA
10 {
11     
12     public void foo()
13     {
14         try
15         {
16             org.omg.PortableInterceptor.Current JavaDoc current =
17                 (org.omg.PortableInterceptor.Current JavaDoc) Server.orb.resolve_initial_references( "PICurrent" );
18         
19             Any any = current.get_slot( ServerInitializer.slot_id );
20         
21             System.out.println("Server extracted from PICurrent: >>" +
22                                any.extract_string() + "<<");
23         }
24         catch( Exception JavaDoc e )
25         {
26             e.printStackTrace();
27         }
28     }
29 }
30
31 public class Server
32 {
33     public static ORB orb = null;
34
35     public static void main(String JavaDoc[] args)
36     {
37         if( args.length != 1 )
38     {
39             System.out.println(
40                 "Usage: jaco test.interceptor.ctx_passing.Server <ior_file>");
41             System.exit( 1 );
42         }
43
44         try
45         {
46             System.setProperty( "org.omg.PortableInterceptor.ORBInitializerClass.a",
47                                 "test.interceptor.ctx_passing.ServerInitializer" );
48             //init ORB
49
orb = ORB.init( args, null );
50
51         //init POA
52
POA poa =
53                 POAHelper.narrow( orb.resolve_initial_references( "RootPOA" ));
54
55         poa.the_POAManager().activate();
56     
57             // create the object reference
58
org.omg.CORBA.Object JavaDoc obj =
59                 poa.servant_to_reference( new TestObjectImpl() );
60
61             PrintWriter pw =
62                 new PrintWriter( new FileWriter( args[ 0 ] ));
63
64             // print stringified object reference to file
65
pw.println( orb.object_to_string( obj ));
66             
67             pw.flush();
68             pw.close();
69     
70             // wait for requests
71
orb.run();
72         }
73         catch( Exception JavaDoc e )
74         {
75             System.out.println( e );
76         }
77     }
78 }
79
Popular Tags