KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > internal > CosNaming > BootstrapServer


1 /*
2  * @(#)BootstrapServer.java 1.5 04/03/01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.internal.CosNaming;
9
10 import java.util.Enumeration JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import java.io.File JavaDoc;
14 import java.io.FileInputStream JavaDoc;
15
16 import com.sun.corba.se.spi.orb.ORB ;
17
18 import com.sun.corba.se.spi.resolver.Resolver ;
19 import com.sun.corba.se.spi.resolver.LocalResolver ;
20 import com.sun.corba.se.spi.resolver.ResolverDefault ;
21
22 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
23 import com.sun.corba.se.impl.orbutil.ORBConstants;
24
25 /**
26  * Class BootstrapServer is the main entry point for the bootstrap server
27  * implementation. The BootstrapServer makes all object references
28  * defined in a configurable file available using the old
29  * naming bootstrap protocol.
30  */

31 public class BootstrapServer
32 {
33     private ORB orb;
34
35      /**
36      * Main startup routine for the bootstrap server.
37      * It first determines the port on which to listen, checks that the
38      * specified file is available, and then creates the resolver
39      * that will be used to service the requests in the
40      * BootstrapServerRequestDispatcher.
41      * @param args the command-line arguments to the main program.
42      */

43     public static final void main(String JavaDoc[] args)
44     {
45     String JavaDoc propertiesFilename = null;
46     int initialPort = ORBConstants.DEFAULT_INITIAL_PORT;
47
48     // Process arguments
49
for (int i=0;i<args.length;i++) {
50         // Look for the filename
51
if (args[i].equals("-InitialServicesFile") && i < args.length -1) {
52         propertiesFilename = args[i+1];
53         }
54
55         // Was the initial port specified? If so, override
56
// This property normally is applied for the client side
57
// configuration of resolvers. Here we are using it to
58
// define the server port that the with which the resolvers
59
// communicate.
60
if (args[i].equals("-ORBInitialPort") && i < args.length-1) {
61         initialPort = java.lang.Integer.parseInt(args[i+1]);
62         }
63     }
64
65     if (propertiesFilename == null) {
66         System.out.println( CorbaResourceUtil.getText("bootstrap.usage",
67         "BootstrapServer"));
68         return;
69     }
70
71     // Create a file
72
File JavaDoc file = new File JavaDoc(propertiesFilename);
73
74     // Verify that if it exists, it is readable
75
if (file.exists() == true && file.canRead() == false) {
76         System.err.println(CorbaResourceUtil.getText(
77         "bootstrap.filenotreadable", file.getAbsolutePath()));
78         return;
79     }
80
81     // Success: start up
82
System.out.println(CorbaResourceUtil.getText(
83         "bootstrap.success", Integer.toString(initialPort),
84         file.getAbsolutePath()));
85
86     Properties JavaDoc props = new Properties JavaDoc() ;
87
88     // Use the SERVER_PORT to create an Acceptor using the
89
// old legacy code in ORBConfiguratorImpl. When (if?)
90
// the legacy support is removed, this code will need
91
// to create an Acceptor directly.
92
props.put( ORBConstants.SERVER_PORT_PROPERTY,
93         Integer.toString( initialPort ) ) ;
94
95     ORB orb = (ORB) org.omg.CORBA.ORB.init(args,props);
96
97     LocalResolver lres = orb.getLocalResolver() ;
98     Resolver fres = ResolverDefault.makeFileResolver( orb, file ) ;
99     Resolver cres = ResolverDefault.makeCompositeResolver( fres, lres ) ;
100     LocalResolver sres = ResolverDefault.makeSplitLocalResolver( cres, lres ) ;
101
102     orb.setLocalResolver( sres ) ;
103
104     try {
105         // This causes the acceptors to start listening.
106
orb.resolve_initial_references(ORBConstants.ROOT_POA_NAME);
107     } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e) {
108         RuntimeException JavaDoc rte = new RuntimeException JavaDoc("This should not happen");
109         rte.initCause(e);
110         throw rte;
111     }
112
113     orb.run() ;
114     }
115 }
116
Popular Tags