KickJava   Java API By Example, From Geeks To Geeks.

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


1 package test.interceptor.ctx_passing;
2
3 import java.io.*;
4 import org.omg.CORBA.ORB JavaDoc;
5 import org.omg.CORBA.Any JavaDoc;
6 import org.omg.PortableInterceptor.*;
7
8 public class Client
9 {
10     public static void main( String JavaDoc args[] )
11     {
12         if( args.length != 1 )
13     {
14             System.out.println( "Usage: jaco test.interceptor.ctx_passing.Client <ior_file>" );
15             System.exit( 1 );
16         }
17
18         try
19     {
20             File f = new File( args[ 0 ] );
21
22             //check if file exists
23
if( ! f.exists() )
24             {
25                 System.out.println("File " + args[0] +
26                                    " does not exist.");
27                 
28                 System.exit( -1 );
29             }
30             
31             //check if args[0] points to a directory
32
if( f.isDirectory() )
33             {
34                 System.out.println("File " + args[0] +
35                                    " is a directory.");
36                 
37                 System.exit( -1 );
38             }
39
40             System.setProperty( "org.omg.PortableInterceptor.ORBInitializerClass.a",
41                                 "test.interceptor.ctx_passing.ClientInitializer" );
42             
43             // initialize the ORB.
44
ORB JavaDoc orb = ORB.init( args, null );
45
46             BufferedReader br =
47                 new BufferedReader( new FileReader( f ));
48
49             // get object reference from command-line argument file
50
org.omg.CORBA.Object JavaDoc obj =
51                 orb.string_to_object( br.readLine() );
52
53             br.close();
54
55             TestObject to = TestObjectHelper.narrow( obj );
56             
57             Current current =
58                 (Current) orb.resolve_initial_references( "PICurrent" );
59             
60             Any JavaDoc any = orb.create_any();
61             any.insert_string( "This is a test!" );
62             
63             current.set_slot( ClientInitializer.slot_id, any );
64             
65             System.out.println("Client added any to PICurrent");
66             to.foo();
67         }
68         catch( Exception JavaDoc ex )
69     {
70             System.err.println( ex );
71         }
72     }
73 }
74
75
Popular Tags