KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > hello > Client


1 package demo.hello;
2
3 import java.io.*;
4 import org.omg.CORBA.*;
5
6 public class Client
7 {
8     public static void main( String JavaDoc args[] )
9     {
10         if( args.length != 1 )
11     {
12             System.out.println( "Usage: jaco demo.hello.Client <ior_file>" );
13             System.exit( 1 );
14         }
15
16         try
17     {
18             File f = new File( args[ 0 ] );
19
20             //check if file exists
21
if( ! f.exists() )
22             {
23                 System.out.println("File " + args[0] +
24                                    " does not exist.");
25                 
26                 System.exit( -1 );
27             }
28             
29             //check if args[0] points to a directory
30
if( f.isDirectory() )
31             {
32                 System.out.println("File " + args[0] +
33                                    " is a directory.");
34                 
35                 System.exit( -1 );
36             }
37
38             // initialize the ORB.
39
ORB orb = ORB.init( args, null );
40
41             BufferedReader br =
42                 new BufferedReader( new FileReader( f ));
43
44             // get object reference from command-line argument file
45
org.omg.CORBA.Object JavaDoc obj =
46                 orb.string_to_object( br.readLine() );
47
48             br.close();
49
50             // and narrow it to HelloWorld.GoodDay
51
// if this fails, a BAD_PARAM will be thrown
52
GoodDay goodDay = GoodDayHelper.narrow( obj );
53
54
55             // invoke the operation and print the result
56
System.out.println( goodDay.hello_simple() );
57
58             // invoke the operation again and print the wide string result
59
System.out.println( "wide string: " +
60                                 goodDay.hello_wide( "Hello Wörld, from ß ö 1 2 3 0 *&^%$#@!@"));
61
62         }
63         catch( Exception JavaDoc ex )
64     {
65             ex.printStackTrace();
66         }
67     }
68 }
69
70
Popular Tags