KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > value > idl > Client


1 package demo.value.idl;
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: java demo.value.idl.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             br.close();
48
49             ValueServer s = ValueServerHelper.narrow( obj );
50
51             // invoke operations and print the results
52
boxedLong p1 = new boxedLong (774);
53             boxedLong p2 = new boxedLong (774);
54
55             System.out.println ("Passing two integers: "
56                                 + s.receive_long (p1, p2));
57
58             System.out.println ("Passing one integer twice: "
59                                 + s.receive_long (p1, p1));
60
61             System.out.println ("Passing two strings: "
62                                 + s.receive_string ("hello", "hello"));
63             
64             System.out.println ("Passing null: "
65                                 + s.receive_string ("hello", null));
66
67             Node n1 = new NodeImpl (1);
68             Node n2 = new NodeImpl (2);
69             Node n3 = new NodeImpl (3);
70             Node n4 = new NodeImpl (4);
71
72             n1.next = n2;
73             n2.next = n3;
74             n3.next = n4;
75             n4.next = n1;
76
77             System.out.println ("Passing a list structure: "
78                                 + s.receive_list (n1));
79         }
80         catch( Exception JavaDoc ex )
81     {
82             System.err.println( ex );
83         }
84     }
85 }
86
87
Popular Tags