1 /*
2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.corba.se.internal.CosNaming;
27 
28 import java.util.Enumeration;
29 import java.util.Properties;
30 
31 import java.io.File;
32 import java.io.FileInputStream;
33 
34 import com.sun.corba.se.spi.orb.ORB ;
35 
36 import com.sun.corba.se.spi.resolver.Resolver ;
37 import com.sun.corba.se.spi.resolver.LocalResolver ;
38 import com.sun.corba.se.spi.resolver.ResolverDefault ;
39 
40 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
41 import com.sun.corba.se.impl.orbutil.ORBConstants;
42 
43 /**
44  * Class BootstrapServer is the main entry point for the bootstrap server
45  * implementation.  The BootstrapServer makes all object references
46  * defined in a configurable file available using the old
47  * naming bootstrap protocol.
48  */
49 public class BootstrapServer
50 {
51     private ORB orb;
52 
53      /**
54      * Main startup routine for the bootstrap server.
55      * It first determines the port on which to listen, checks that the
56      * specified file is available, and then creates the resolver
57      * that will be used to service the requests in the
58      * BootstrapServerRequestDispatcher.
59      * @param args the command-line arguments to the main program.
60      */
main(String[] args)61     public static final void main(String[] args)
62     {
63         String propertiesFilename = null;
64         int initialPort = ORBConstants.DEFAULT_INITIAL_PORT;
65 
66         // Process arguments
67         for (int i=0;i<args.length;i++) {
68             // Look for the filename
69             if (args[i].equals("-InitialServicesFile") && i < args.length -1) {
70                 propertiesFilename = args[i+1];
71             }
72 
73             // Was the initial port specified? If so, override
74             // This property normally is applied for the client side
75             // configuration of resolvers.  Here we are using it to
76             // define the server port that the with which the resolvers
77             // communicate.
78             if (args[i].equals("-ORBInitialPort") && i < args.length-1) {
79                 initialPort = java.lang.Integer.parseInt(args[i+1]);
80             }
81         }
82 
83         if (propertiesFilename == null) {
84             System.out.println( CorbaResourceUtil.getText("bootstrap.usage",
85                 "BootstrapServer"));
86             return;
87         }
88 
89         // Create a file
90         File file = new File(propertiesFilename);
91 
92         // Verify that if it exists, it is readable
93         if (file.exists() == true && file.canRead() == false) {
94             System.err.println(CorbaResourceUtil.getText(
95                 "bootstrap.filenotreadable", file.getAbsolutePath()));
96             return;
97         }
98 
99         // Success: start up
100         System.out.println(CorbaResourceUtil.getText(
101             "bootstrap.success", Integer.toString(initialPort),
102             file.getAbsolutePath()));
103 
104         Properties props = new Properties() ;
105 
106         // Use the SERVER_PORT to create an Acceptor using the
107         // old legacy code in ORBConfiguratorImpl.  When (if?)
108         // the legacy support is removed, this code will need
109         // to create an Acceptor directly.
110         props.put( ORBConstants.SERVER_PORT_PROPERTY,
111             Integer.toString( initialPort ) ) ;
112 
113         ORB orb = (ORB) org.omg.CORBA.ORB.init(args,props);
114 
115         LocalResolver lres = orb.getLocalResolver() ;
116         Resolver fres = ResolverDefault.makeFileResolver( orb, file ) ;
117         Resolver cres = ResolverDefault.makeCompositeResolver( fres, lres ) ;
118         LocalResolver sres = ResolverDefault.makeSplitLocalResolver( cres, lres ) ;
119 
120         orb.setLocalResolver( sres ) ;
121 
122         try {
123             // This causes the acceptors to start listening.
124             orb.resolve_initial_references(ORBConstants.ROOT_POA_NAME);
125         } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
126             RuntimeException rte = new RuntimeException("This should not happen");
127             rte.initCause(e);
128             throw rte;
129         }
130 
131         orb.run() ;
132     }
133 }
134