1 7 8 package com.sun.corba.se.impl.naming.cosnaming; 9 10 import java.util.Properties ; 11 import java.net.InetAddress ; 12 13 import org.omg.CORBA.ORB ; 14 15 import org.omg.CosNaming.NamingContext ; 16 17 import com.sun.corba.se.spi.logging.CORBALogDomains; 18 19 import com.sun.corba.se.impl.naming.cosnaming.TransientNameService; 20 21 import com.sun.corba.se.impl.orbutil.ORBConstants; 22 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil; 23 import com.sun.corba.se.impl.logging.NamingSystemException; 24 25 42 public class TransientNameServer 43 { 44 static private boolean debug = false ; 45 static NamingSystemException wrapper = NamingSystemException.get( 46 CORBALogDomains.NAMING ) ; 47 48 static public void trace( String msg ) { 49 if (debug) 50 System.out.println( msg ) ; 51 } 52 53 static public void initDebug( String [] args ) { 54 if (debug) 57 return ; 58 59 for (int ctr=0; ctr<args.length; ctr++) 60 if (args[ctr].equalsIgnoreCase( "-debug" )) { 61 debug = true ; 62 return ; 63 } 64 debug = false ; 65 } 66 67 private static org.omg.CORBA.Object initializeRootNamingContext( ORB orb ) { 68 org.omg.CORBA.Object rootContext = null; 69 try { 70 com.sun.corba.se.spi.orb.ORB coreORB = 71 (com.sun.corba.se.spi.orb.ORB)orb ; 72 73 TransientNameService tns = new TransientNameService(coreORB ); 74 return tns.initialNamingContext(); 75 } catch (org.omg.CORBA.SystemException e) { 76 throw wrapper.transNsCannotCreateInitialNcSys( e ) ; 77 } catch (Exception e) { 78 throw wrapper.transNsCannotCreateInitialNc( e ) ; 79 } 80 } 81 82 88 public static void main(String args[]) { 89 initDebug( args ) ; 90 91 boolean invalidHostOption = false; 92 boolean orbInitialPort0 = false; 93 94 int initialPort = 0; 96 try { 97 trace( "Transient name server started with args " + args ) ; 98 99 Properties props = System.getProperties() ; 101 102 props.put( ORBConstants.SERVER_ID_PROPERTY, ORBConstants.NAME_SERVICE_SERVER_ID ) ; 103 props.put( "org.omg.CORBA.ORBClass", 104 "com.sun.corba.se.impl.orb.ORBImpl" ); 105 106 try { 107 String ips = System.getProperty( ORBConstants.INITIAL_PORT_PROPERTY ) ; 109 if (ips != null && ips.length() > 0 ) { 110 initialPort = java.lang.Integer.parseInt(ips); 111 if( initialPort == 0 ) { 113 orbInitialPort0 = true; 114 throw wrapper.transientNameServerBadPort() ; 115 } 116 } 117 String hostName = 118 System.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ; 119 if( hostName != null ) { 120 invalidHostOption = true; 121 throw wrapper.transientNameServerBadHost() ; 122 } 123 } catch (java.lang.NumberFormatException e) { 124 } 126 127 for (int i=0;i<args.length;i++) { 129 if (args[i].equals("-ORBInitialPort") && 131 i < args.length-1) { 132 initialPort = java.lang.Integer.parseInt(args[i+1]); 133 if( initialPort == 0 ) { 135 orbInitialPort0 = true; 136 throw wrapper.transientNameServerBadPort() ; 137 } 138 } 139 if (args[i].equals("-ORBInitialHost" ) ) { 140 invalidHostOption = true; 141 throw wrapper.transientNameServerBadHost() ; 142 } 143 } 144 145 if( initialPort == 0 ) { 148 initialPort = ORBConstants.DEFAULT_INITIAL_PORT; 149 props.put( ORBConstants.INITIAL_PORT_PROPERTY, 150 java.lang.Integer.toString(initialPort) ); 151 } 152 153 props.put( ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY, 156 java.lang.Integer.toString(initialPort) ); 157 158 org.omg.CORBA.ORB corb = ORB.init( args, props ) ; 159 trace( "ORB object returned from init: " + corb ) ; 160 161 org.omg.CORBA.Object ns = initializeRootNamingContext( corb ) ; 162 ((com.sun.corba.se.org.omg.CORBA.ORB)corb).register_initial_reference( 163 "NamingService", ns ) ; 164 165 String stringifiedIOR = null; 166 167 if( ns != null ) { 168 stringifiedIOR = corb.object_to_string(ns) ; 169 } else { 170 NamingUtils.errprint(CorbaResourceUtil.getText( 171 "tnameserv.exception", initialPort)); 172 NamingUtils.errprint(CorbaResourceUtil.getText( 173 "tnameserv.usage")); 174 System.exit( 1 ); 175 } 176 177 trace( "name service created" ) ; 178 179 183 System.out.println(CorbaResourceUtil.getText( 184 "tnameserv.hs1", stringifiedIOR)); 185 System.out.println(CorbaResourceUtil.getText( 186 "tnameserv.hs2", initialPort)); 187 System.out.println(CorbaResourceUtil.getText("tnameserv.hs3")); 188 189 java.lang.Object sync = new java.lang.Object (); 191 synchronized (sync) {sync.wait();} 192 } catch (Exception e) { 193 if( invalidHostOption ) { 194 NamingUtils.errprint( CorbaResourceUtil.getText( 197 "tnameserv.invalidhostoption" ) ); 198 } else if( orbInitialPort0 ) { 199 NamingUtils.errprint( CorbaResourceUtil.getText( 202 "tnameserv.orbinitialport0" )); 203 } else { 204 NamingUtils.errprint(CorbaResourceUtil.getText( 205 "tnameserv.exception", initialPort)); 206 NamingUtils.errprint(CorbaResourceUtil.getText( 207 "tnameserv.usage")); 208 } 209 210 e.printStackTrace() ; 211 } 212 } 213 214 217 private TransientNameServer() {} 218 } 219 | Popular Tags |