KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > grid > Client


1 package demo.grid;
2
3 import org.omg.CosNaming.*;
4 import java.io.*;
5 public class Client
6 {
7     public static void main(String JavaDoc args[])
8     {
9     try
10     {
11         MyServer grid;
12
13         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
14
15         if( args.length == 1 )
16         {
17         // args[0] is an IOR-string
18
grid = MyServerHelper.narrow(orb.string_to_object(args[0]));
19         }
20         else
21         {
22         NamingContextExt nc =
23                     NamingContextExtHelper.narrow(
24                     orb.resolve_initial_references( "NameService" ));
25
26                 nc.to_name("grid.example");
27
28                 org.omg.CORBA.Object JavaDoc o =
29                     nc.resolve(nc.to_name("grid.example"));
30
31         grid = MyServerHelper.narrow(o);
32         }
33
34         short x = grid.height();
35         System.out.println("Height = " + x);
36
37         short y = grid.width();
38         System.out.println("Width = " + y);
39
40         x -= 1;
41         y -= 1;
42
43         System.out.println("Old value at (" + x + "," + y +"): " +
44                                grid.get( x,y));
45
46         System.out.println("Setting (" + x + "," + y +") to 470.11");
47         
48         grid.set( x, y, new java.math.BigDecimal JavaDoc("470.11"));
49
50         System.out.println("New value at (" + x + "," + y +"): " +
51                                grid.get( x,y));
52
53         try
54         {
55         grid.opWithException();
56         }
57         catch (demo.grid.MyServerPackage.MyException ex)
58         {
59         System.out.println("MyException, reason: " + ex.why);
60         }
61
62
63             orb.shutdown(true);
64             System.out.println("done. ");
65        
66     }
67     catch (Exception JavaDoc e)
68     {
69         e.printStackTrace();
70     }
71     }
72 }
73
74
75
Popular Tags