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. package com.sun.corba.se.internal.CosNaming;
  8. import java.util.Enumeration;
  9. import java.util.Properties;
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import com.sun.corba.se.spi.orb.ORB ;
  13. import com.sun.corba.se.spi.resolver.Resolver ;
  14. import com.sun.corba.se.spi.resolver.LocalResolver ;
  15. import com.sun.corba.se.spi.resolver.ResolverDefault ;
  16. import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
  17. import com.sun.corba.se.impl.orbutil.ORBConstants;
  18. /**
  19. * Class BootstrapServer is the main entry point for the bootstrap server
  20. * implementation. The BootstrapServer makes all object references
  21. * defined in a configurable file available using the old
  22. * naming bootstrap protocol.
  23. */
  24. public class BootstrapServer
  25. {
  26. private ORB orb;
  27. /**
  28. * Main startup routine for the bootstrap server.
  29. * It first determines the port on which to listen, checks that the
  30. * specified file is available, and then creates the resolver
  31. * that will be used to service the requests in the
  32. * BootstrapServerRequestDispatcher.
  33. * @param args the command-line arguments to the main program.
  34. */
  35. public static final void main(String[] args)
  36. {
  37. String propertiesFilename = null;
  38. int initialPort = ORBConstants.DEFAULT_INITIAL_PORT;
  39. // Process arguments
  40. for (int i=0;i<args.length;i++) {
  41. // Look for the filename
  42. if (args[i].equals("-InitialServicesFile") && i < args.length -1) {
  43. propertiesFilename = args[i+1];
  44. }
  45. // Was the initial port specified? If so, override
  46. // This property normally is applied for the client side
  47. // configuration of resolvers. Here we are using it to
  48. // define the server port that the with which the resolvers
  49. // communicate.
  50. if (args[i].equals("-ORBInitialPort") && i < args.length-1) {
  51. initialPort = java.lang.Integer.parseInt(args[i+1]);
  52. }
  53. }
  54. if (propertiesFilename == null) {
  55. System.out.println( CorbaResourceUtil.getText("bootstrap.usage",
  56. "BootstrapServer"));
  57. return;
  58. }
  59. // Create a file
  60. File file = new File(propertiesFilename);
  61. // Verify that if it exists, it is readable
  62. if (file.exists() == true && file.canRead() == false) {
  63. System.err.println(CorbaResourceUtil.getText(
  64. "bootstrap.filenotreadable", file.getAbsolutePath()));
  65. return;
  66. }
  67. // Success: start up
  68. System.out.println(CorbaResourceUtil.getText(
  69. "bootstrap.success", Integer.toString(initialPort),
  70. file.getAbsolutePath()));
  71. Properties props = new Properties() ;
  72. // Use the SERVER_PORT to create an Acceptor using the
  73. // old legacy code in ORBConfiguratorImpl. When (if?)
  74. // the legacy support is removed, this code will need
  75. // to create an Acceptor directly.
  76. props.put( ORBConstants.SERVER_PORT_PROPERTY,
  77. Integer.toString( initialPort ) ) ;
  78. ORB orb = (ORB) org.omg.CORBA.ORB.init(args,props);
  79. LocalResolver lres = orb.getLocalResolver() ;
  80. Resolver fres = ResolverDefault.makeFileResolver( orb, file ) ;
  81. Resolver cres = ResolverDefault.makeCompositeResolver( fres, lres ) ;
  82. LocalResolver sres = ResolverDefault.makeSplitLocalResolver( cres, lres ) ;
  83. orb.setLocalResolver( sres ) ;
  84. try {
  85. // This causes the acceptors to start listening.
  86. orb.resolve_initial_references(ORBConstants.ROOT_POA_NAME);
  87. } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
  88. RuntimeException rte = new RuntimeException("This should not happen");
  89. rte.initCause(e);
  90. throw rte;
  91. }
  92. orb.run() ;
  93. }
  94. }