KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > bank > transaction > implicit > Server


1 package demo.bank.transaction.implicit;
2
3 import org.omg.CORBA.*;
4 import org.omg.CORBA.ORBPackage.*;
5 import org.omg.CosTransactions.*;
6 import org.omg.CosNaming.*;
7 import java.io.*;
8
9 public class Server
10 {
11     public static void main( String JavaDoc[] args )
12     {
13         java.util.Properties JavaDoc props = new java.util.Properties JavaDoc();
14         props.put("org.omg.PortableInterceptor.ORBInitializerClass.TSClientInit",
15                   "org.jacorb.transaction.TransactionInitializer");
16
17         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, props);
18         try
19         {
20             org.omg.PortableServer.POA JavaDoc poa =
21                 org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
22
23         poa.the_POAManager().activate();
24             
25             org.omg.CORBA.Object JavaDoc o = poa.servant_to_reference(new BankImpl(orb,poa));
26
27             if( args.length == 1 )
28             {
29                 // write the object reference to args[0]
30

31                 PrintWriter ps = new PrintWriter(new FileOutputStream(new File( args[0] )));
32                 ps.println( orb.object_to_string( o ) );
33                 ps.close();
34             }
35             else
36             {
37                 NamingContextExt nc =
38                     NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
39                 NameComponent [] name = new NameComponent[1];
40                 name[0] = new NameComponent( "DigiBank", "server");
41                 nc.bind(name, o);
42             }
43         }
44         catch ( Exception JavaDoc e )
45         {
46             e.printStackTrace();
47         }
48         orb.run();
49     }
50
51
52 }
53
Popular Tags