1. /*
  2. * @(#)ORB.java 1.264 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.corba;
  16. // Import JDK stuff
  17. import java.net.*;
  18. import java.util.*;
  19. import java.applet.Applet;
  20. import java.lang.reflect.Constructor;
  21. import java.lang.reflect.Field ;
  22. import java.lang.reflect.Modifier ;
  23. import java.lang.ThreadLocal;
  24. import java.io.File ;
  25. import java.io.IOException ;
  26. import java.io.FileInputStream ;
  27. import java.io.FileNotFoundException ;
  28. // Import our stuff
  29. import org.omg.CORBA.COMM_FAILURE;
  30. import org.omg.CORBA.DATA_CONVERSION;
  31. import org.omg.CORBA.INITIALIZE;
  32. import org.omg.CORBA.NO_IMPLEMENT;
  33. import org.omg.CORBA.INTERNAL;
  34. import org.omg.CORBA.Context;
  35. import org.omg.CORBA.ContextList;
  36. import org.omg.CORBA.Environment;
  37. import org.omg.CORBA.ExceptionList;
  38. import org.omg.CORBA.ORBPackage.InvalidName;
  39. import org.omg.CORBA.NVList;
  40. import org.omg.CORBA.TCKind;
  41. import org.omg.CORBA.NamedValue;
  42. import org.omg.CORBA.Object;
  43. import org.omg.CORBA.Request;
  44. import org.omg.CORBA.OBJ_ADAPTER;
  45. import org.omg.CORBA.OBJECT_NOT_EXIST;
  46. import org.omg.CORBA.INV_OBJREF;
  47. import org.omg.CORBA.MARSHAL;
  48. import org.omg.CORBA.SystemException;
  49. import org.omg.CORBA.CompletionStatus;
  50. import org.omg.CORBA.TypeCode;
  51. import org.omg.CORBA.Any;
  52. import org.omg.CORBA.StructMember;
  53. import org.omg.CORBA.UnionMember;
  54. import org.omg.CORBA.ValueMember;
  55. import org.omg.CORBA.BAD_PARAM;
  56. import org.omg.CORBA.BAD_INV_ORDER;
  57. import org.omg.CORBA.portable.*;
  58. import org.omg.CORBA.portable.RemarshalException;
  59. import org.omg.CORBA.portable.ValueFactory;
  60. import org.omg.PortableServer.Servant;
  61. import com.sun.corba.se.connection.ORBSocketFactory;
  62. import com.sun.corba.se.internal.core.CodeSetComponentInfo;
  63. import com.sun.corba.se.internal.core.ClientSubcontract;
  64. import com.sun.corba.se.internal.core.ClientResponse;
  65. import com.sun.corba.se.internal.core.ClientRequest;
  66. import com.sun.corba.se.internal.iiop.Connection;
  67. import com.sun.corba.se.internal.ior.IIOPProfile;
  68. import com.sun.corba.se.internal.core.ServerSubcontract;
  69. import com.sun.corba.se.internal.core.ServiceContexts;
  70. import com.sun.corba.se.internal.core.SubcontractRegistry;
  71. import com.sun.corba.se.internal.core.ClientGIOP;
  72. import com.sun.corba.se.internal.core.ServerGIOP;
  73. import com.sun.corba.se.internal.core.ServerRequest;
  74. import com.sun.corba.se.internal.core.MarshalInputStream;
  75. import com.sun.corba.se.internal.core.MarshalOutputStream;
  76. import com.sun.corba.se.internal.core.InternalRuntimeForwardRequest;
  77. import com.sun.corba.se.internal.core.IOR;
  78. import com.sun.corba.se.internal.core.Future;
  79. import com.sun.corba.se.internal.core.Closure;
  80. import com.sun.corba.se.internal.core.Constant;
  81. import com.sun.corba.se.internal.core.GIOPVersion;
  82. import com.sun.corba.se.internal.core.ORBVersion;
  83. import com.sun.corba.se.internal.core.ORBVersionFactory;
  84. import com.sun.corba.se.internal.core.INSObjectKeyMap;
  85. import com.sun.corba.se.internal.core.INSObjectKeyEntry;
  86. import com.sun.corba.se.internal.core.StandardIIOPProfileTemplate;
  87. import com.sun.corba.se.internal.util.Utility;
  88. import com.sun.corba.se.internal.orbutil.ORBUtility;
  89. import com.sun.corba.se.internal.orbutil.ORBClassLoader;
  90. import com.sun.corba.se.internal.orbutil.ORBConstants;
  91. import com.sun.corba.se.internal.orbutil.ORBUtility;
  92. import com.sun.corba.se.internal.orbutil.MinorCodes;
  93. import com.sun.corba.se.internal.orbutil.SubcontractList;
  94. import com.sun.corba.se.internal.iiop.DefaultSocketFactory;
  95. import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
  96. import com.sun.corba.se.internal.iiop.messages.KeyAddr;
  97. import com.sun.corba.se.internal.iiop.messages.ProfileAddr;
  98. import com.sun.corba.se.internal.iiop.messages.ReferenceAddr;
  99. import com.sun.corba.se.internal.ior.IIOPProfileTemplate;
  100. import com.sun.corba.se.internal.ior.IIOPAddress ;
  101. import com.sun.corba.se.internal.ior.IIOPAddressImpl ;
  102. import com.sun.corba.se.internal.ior.ObjectKey ;
  103. import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
  104. import com.sun.corba.se.internal.ior.ObjectId;
  105. import com.sun.corba.se.internal.DynamicAny.DynAnyFactoryImpl;
  106. import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;
  107. import java.security.AccessController;
  108. import java.security.PrivilegedAction;
  109. import sun.security.action.GetPropertyAction;
  110. import javax.rmi.CORBA.Util;
  111. import javax.rmi.CORBA.ValueHandler;
  112. import com.sun.org.omg.SendingContext.CodeBase;
  113. import com.sun.org.omg.SendingContext.CodeBaseHelper;
  114. /**
  115. * The JavaIDL ORB implementation.
  116. */
  117. public abstract class ORB extends com.sun.corba.se.internal.core.ORB
  118. implements TypeCodeFactory
  119. {
  120. //d11638; pure java orb, caching the servant IOR per ORB
  121. private static IOR ior = null;
  122. protected void dprint( String msg )
  123. {
  124. ORBUtility.dprint( this, msg ) ;
  125. }
  126. // Flag set at compile time to debug flag processing: this can't
  127. // be one of the xxxDebugFlags because it is used to debug the mechanism
  128. // that sets the xxxDebugFlags!
  129. public static boolean ORBInitDebug = false;
  130. // Currently defined debug flags. Any additions must be called xxxDebugFlag.
  131. // All debug flags must be public boolean types.
  132. // These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
  133. // Note that x,y,z must not contain spaces.
  134. public boolean transportDebugFlag = false ;
  135. public boolean subcontractDebugFlag = false ;
  136. public boolean poaDebugFlag = false ;
  137. public boolean orbdDebugFlag = false ;
  138. public boolean namingDebugFlag = false ;
  139. public boolean serviceContextDebugFlag = false ;
  140. public boolean transientObjectManagerDebugFlag = false ;
  141. public boolean giopVersionDebugFlag = false;
  142. // public boolean iiopConnectionDebugFlag = false;
  143. public boolean shutdownDebugFlag = false;
  144. public boolean giopDebugFlag = false;
  145. private static final String[] JavaIDLPropertyNames = {
  146. ORBConstants.INITIAL_HOST_PROPERTY,
  147. ORBConstants.INITIAL_PORT_PROPERTY,
  148. ORBConstants.INITIAL_SERVICES_PROPERTY,
  149. ORBConstants.DEFAULT_INIT_REF_PROPERTY,
  150. ORBConstants.ORB_INIT_REF_PROPERTY,
  151. ORBConstants.SERVER_PORT_PROPERTY,
  152. ORBConstants.SERVER_HOST_PROPERTY,
  153. ORBConstants.ORB_ID_PROPERTY,
  154. ORBConstants.DEBUG_PROPERTY,
  155. ORBConstants.HIGH_WATER_MARK_PROPERTY,
  156. ORBConstants.LOW_WATER_MARK_PROPERTY,
  157. ORBConstants.NUMBER_TO_RECLAIM_PROPERTY,
  158. ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY,
  159. ORBConstants.LISTEN_SOCKET_PROPERTY,
  160. //Temporary way of installing a version of GIOP on an ORB.
  161. //Can be beautified later.
  162. ORBConstants.GIOP_VERSION,
  163. ORBConstants.GIOP_FRAGMENT_SIZE,
  164. ORBConstants.GIOP_BUFFER_SIZE,
  165. ORBConstants.GIOP_11_BUFFMGR,
  166. ORBConstants.GIOP_12_BUFFMGR,
  167. ORBConstants.GIOP_TARGET_ADDRESSING,
  168. ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY,
  169. ORBConstants.USE_BOMS,
  170. ORBConstants.USE_BOMS_IN_ENCAPS,
  171. ORBConstants.CHAR_CODESETS,
  172. ORBConstants.WCHAR_CODESETS,
  173. ORBConstants.ALLOW_LOCAL_OPTIMIZATION
  174. };
  175. private static final String[] JavaIDLPropertyNamePrefixes = {
  176. // Intentionally blank;
  177. };
  178. private static final String[] JavaIDLURLPropertyNames = {
  179. ORBConstants.INITIAL_SERVICES_PROPERTY
  180. };
  181. //
  182. // The following fields form our special little collection of global state.
  183. // We keep it bottled up here in the ORB class and attach a reference to
  184. // ourselves to every object reference that we create and handle.
  185. //
  186. // Vector holding deferred Requests
  187. private Vector _dynamicRequests;
  188. protected SynchVariable _svResponseReceived;
  189. // Applet/command-line parameters
  190. protected String ORBInitialHost = "";
  191. protected int ORBInitialPort;
  192. protected String ORBServerHost = "";
  193. protected int ORBServerPort = 0;
  194. protected String appletHost = "";
  195. protected URL appletCodeBase = null;
  196. protected ORBSocketFactory socketFactory;
  197. protected String orbId = "";
  198. public boolean allowLocalOptimization = false ;
  199. private Collection userSpecifiedListenPorts = new Vector();
  200. //Connection management parameters
  201. protected int highWaterMark = 240;
  202. protected int lowWaterMark = 100;
  203. protected int numberToReclaim = 5;
  204. // GIOP Related Constants
  205. // Default is 1.0. We will change it to 1.2 later.
  206. protected GIOPVersion giopVersion = GIOPVersion.DEFAULT_VERSION;
  207. protected int giopFragmentSize = ORBConstants.GIOP_DEFAULT_FRAGMENT_SIZE;
  208. protected int giopBufferSize = ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
  209. protected int giop11BuffMgr = ORBConstants.DEFAULT_GIOP_11_BUFFMGR;
  210. protected int giop12BuffMgr = ORBConstants.DEFAULT_GIOP_12_BUFFMGR;
  211. protected short giopTargetAddressPreference = ORBConstants.ADDR_DISP_HANDLE_ALL;
  212. protected short giopAddressDisposition = KeyAddr.value;
  213. // Synchronization variable for shutdown
  214. private java.lang.Object runObj = new java.lang.Object();
  215. private java.lang.Object shutdownObj = new java.lang.Object();
  216. private java.lang.Object waitForCompletionObj = new java.lang.Object();
  217. private java.lang.Object invocationObj = new java.lang.Object();
  218. private int numInvocations = 0;
  219. protected static final byte STATUS_OPERATING = 1;
  220. protected static final byte STATUS_SHUTTING_DOWN = 2;
  221. protected static final byte STATUS_SHUTDOWN = 3;
  222. protected static final byte STATUS_DESTROYED = 4;
  223. byte status = STATUS_OPERATING;
  224. // thread local variable to store a boolean to detect deadlock in ORB.shutdown(true).
  225. protected ThreadLocal isProcessingInvocation = new ThreadLocal () {
  226. protected java.lang.Object initialValue() {
  227. return Boolean.FALSE;
  228. }
  229. };
  230. // Code set related
  231. protected boolean useByteOrderMarkers = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS;
  232. protected boolean useByteOrderMarkersInEncaps
  233. = ORBConstants.DEFAULT_USE_BYTE_ORDER_MARKERS_IN_ENCAPS;
  234. // Preferred native and conversion code sets for use with connections. Can
  235. // override or change with appropriate properties.
  236. protected CodeSetComponentInfo codesets
  237. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS;
  238. protected boolean alwaysSendCodeSetCtx
  239. = ORBConstants.DEFAULT_ALWAYS_SEND_CODESET_CTX;
  240. InitialNamingClient initialNamingClient;
  241. DynAnyFactoryImpl dynAnyFactory = null;
  242. // This map is needed for resolving recursive type code placeholders
  243. // based on the unique repository id.
  244. private Map typeCodeMap = null;
  245. // This map is caching TypeCodes created for a certain class (key)
  246. // and is used in Util.writeAny()
  247. private Map typeCodeForClassMap = null;
  248. private String savedId = null;
  249. private TypeCodeImpl savedCode = null;
  250. // Cache to hold ValueFactories (Helper classes) keyed on repository ids
  251. protected Hashtable valueFactoryCache = new Hashtable();
  252. // thread local variable to store the current ORB version
  253. private ThreadLocal orbVersionThreadLocal ;
  254. // Table used for all locally registered services.
  255. // This is used for register/resolve/list initial methods.
  256. // This table maps Strings to Closures. The evaluate method
  257. // of the Closure must return a CORBA.Object.
  258. private HashMap initialReferenceTable ;
  259. /**
  260. * Create a new ORB. Should only be invoked from the
  261. * CORBA ORB superclass. Should be followed by the appropriate
  262. * set_parameters() call.
  263. */
  264. public ORB()
  265. {
  266. _dynamicRequests = new Vector();
  267. _svResponseReceived = new SynchVariable();
  268. initialNamingClient = new InitialNamingClient(this);
  269. initialReferenceTable = new HashMap() ;
  270. // default ORB version is the version of ORB with correct Rep-id
  271. // changes
  272. orbVersionThreadLocal = new ThreadLocal () {
  273. protected java.lang.Object initialValue() {
  274. // set default to version of the ORB with correct Rep-ids
  275. return ORBVersionFactory.getORBVersion() ;
  276. }
  277. };
  278. // Register the Dynamic Any factory
  279. Closure closure = new Closure() {
  280. public java.lang.Object evaluate() {
  281. return new DynAnyFactoryImpl( ORB.this ) ;
  282. }
  283. } ;
  284. Future future = new Future( closure ) ;
  285. registerInitialReference( ORBConstants.DYN_ANY_FACTORY_NAME, future ) ;
  286. }
  287. public InitialNamingClient getInitialNamingClient( ) {
  288. return initialNamingClient;
  289. }
  290. public ORBVersion getORBVersion()
  291. {
  292. // return the thread local data
  293. return (ORBVersion)(orbVersionThreadLocal.get()) ;
  294. }
  295. public void setORBVersion(ORBVersion verObj)
  296. {
  297. // set the thread local data
  298. orbVersionThreadLocal.set(verObj);
  299. }
  300. /**
  301. * Should the client send the code set service context on every
  302. * request?
  303. */
  304. public boolean alwaysSendCodeSetServiceContext() {
  305. return alwaysSendCodeSetCtx;
  306. }
  307. /**
  308. * Use byte order markers when applicable during character conversion?
  309. */
  310. public boolean useByteOrderMarkers() {
  311. return useByteOrderMarkers;
  312. }
  313. /**
  314. * Use byte order markers even in encapsulations?
  315. */
  316. public boolean useByteOrderMarkersInEncapsulations() {
  317. return useByteOrderMarkersInEncaps;
  318. }
  319. /**
  320. * Get the prefered code sets for connections.
  321. */
  322. public CodeSetComponentInfo getCodeSetComponentInfo() {
  323. return codesets;
  324. }
  325. /****************************************************************************
  326. * The following methods deal with parsing parameters and doing appropriate
  327. * initialization.
  328. ****************************************************************************/
  329. /**
  330. * Initialize any necessary ORB state; get attributes if possible.
  331. * Called from org.omg.CORBA.ORB.init().
  332. * @param app the applet
  333. * @param props the applet properties
  334. */
  335. protected void set_parameters(Applet app, Properties props)
  336. {
  337. // Note: In some applet-development frameworks
  338. // the applet object may not be directly available and so it's
  339. // possible for the Applet instance to be null.
  340. // Get the full list of property names that we are interested in
  341. String[] propertyNames = getPropertyNames();
  342. String[] propertyNamePrefixes = getPropertyNamePrefixes();
  343. if (app != null) {
  344. appletCodeBase = app.getCodeBase();
  345. if (appletCodeBase != null)
  346. appletHost = appletCodeBase.getHost( );
  347. }
  348. // Build up the full list of configuration properties
  349. // from the applet-params and props-argument.
  350. // Make Properties Vector to handle multiple -ORBInitDef s
  351. Properties propList = new Properties();
  352. // Until we decide it's ok for getSystemProperty() to
  353. // use AccessController.beginPrivileged(), I've commented
  354. // out the use of System properties for applets since
  355. // this will result in confusing SecurityExceptions in
  356. // most situations.
  357. //
  358. /*
  359. findORBPropertiesFromSystem(propList,
  360. propertyNames, propertyNamePrefixes);
  361. */
  362. findPropertiesFromProperties(propList, props,
  363. propertyNames, propertyNamePrefixes);
  364. findPropertiesFromApplet(propList, app,
  365. propertyNames, propertyNamePrefixes);
  366. checkAppletPropertyDefaults(propList);
  367. // Use the full props list to set ORB state.
  368. parseProperties(propList);
  369. }
  370. /**
  371. * Initialize any necessary ORB state; get attributes if possible.
  372. * Called from org.omg.CORBA.ORB.init().
  373. * @param params An array of parameters in the form of alternating <br>
  374. * "-param-name" and "param-value" strings.
  375. * @param props the application properties
  376. */
  377. protected void set_parameters (String[] params, Properties props)
  378. {
  379. // Get the full list of property names that we are interested in
  380. String[] propertyNames = getPropertyNames();
  381. String[] propertyNamePrefixes = getPropertyNamePrefixes();
  382. // Build up the full list of configuration properties
  383. // from the command-line-params, props-argument, System properties.
  384. Properties propList = new Properties();
  385. Vector orbInitRefList = new Vector();
  386. findORBPropertiesFromSystem(propList,
  387. propertyNames, propertyNamePrefixes);
  388. findPropertiesFromProperties(propList, props,
  389. propertyNames, propertyNamePrefixes);
  390. findPropertiesFromFile(propList, propertyNames, propertyNamePrefixes);
  391. findPropertiesFromArgs(propList, orbInitRefList,
  392. params, propertyNames, propertyNamePrefixes);
  393. checkApplicationPropertyDefaults(propList);
  394. // Use the full props list to set ORB state.
  395. parseProperties(propList);
  396. boolean result = initialNamingClient.setORBInitRefList(
  397. orbInitRefList );
  398. // If we are unsuccessful in setting the ORBInitDef list then it means
  399. // there are some malformed URLs presesnt
  400. if( result == false )
  401. {
  402. // Make sure to add the right minor codes here, for now it is
  403. // reusing one of the old Minorcode.
  404. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR,
  405. CompletionStatus.COMPLETED_NO);
  406. }
  407. }
  408. /** Return a list of property names that this ORB is interested in.
  409. * This may be overridden by subclasses, but subclasses must call
  410. * super.getPropertyNames() to get all names.
  411. */
  412. protected String[] getPropertyNames()
  413. {
  414. String[] names = new String[JavaIDLPropertyNames.length];
  415. for ( int i=0; i<JavaIDLPropertyNames.length; i++ )
  416. names[i] = JavaIDLPropertyNames[i];
  417. if (ORBInitDebug)
  418. dprint( "getPropertyNames returns " +
  419. ORBUtility.objectToString( names ) ) ;
  420. return names;
  421. }
  422. /** Return a list of property name prefixes that this ORB is interested in.
  423. * This may be overridden by subclasses, but subclasses must call
  424. * super.getPropertyNames() to get all names.
  425. */
  426. protected String[] getPropertyNamePrefixes()
  427. {
  428. String[] names = new String[JavaIDLPropertyNamePrefixes.length];
  429. for ( int i=0; i<JavaIDLPropertyNamePrefixes.length; i++ ) {
  430. names[i] = JavaIDLPropertyNamePrefixes[i];
  431. }
  432. if (ORBInitDebug) {
  433. dprint( "getPropertyNamePrefixes returns " + ORBUtility.objectToString( names ) ) ;
  434. }
  435. return names;
  436. }
  437. /*
  438. * A callback is used since sometimes we cannot actually get our
  439. * hands on the properties object (e.g., System.properties).
  440. */
  441. private void findPropertiesWithPrefix(String[] propertyNamePrefixes,
  442. Enumeration namesToSearch,
  443. GetPropertyCallback getProperty,
  444. String source,
  445. Properties resultProperties)
  446. {
  447. while (namesToSearch.hasMoreElements()) {
  448. String pn = (String) namesToSearch.nextElement();
  449. for (int j = 0; j < propertyNamePrefixes.length; j++) {
  450. if (pn.startsWith(propertyNamePrefixes[j])) {
  451. String value = getProperty.get(pn);
  452. // Note: do a put even if value is null since just
  453. // the presence of the property may be significant.
  454. resultProperties.put(pn, value);
  455. if (ORBInitDebug) {
  456. dprint( "Found prefixed property " + pn + "=" +
  457. value + " in " + source);
  458. }
  459. }
  460. }
  461. }
  462. }
  463. protected boolean singleParam(String param)
  464. {
  465. // Return true if this param does not have a data field after it
  466. // (e.g. for on/off flags).
  467. return false;
  468. }
  469. protected String findMatchingPropertyName( String[] propertyNames,
  470. String suffix )
  471. {
  472. for (int ctr=0; ctr<propertyNames.length; ctr++) {
  473. if (propertyNames[ctr].endsWith( suffix )) {
  474. return propertyNames[ctr] ;
  475. }
  476. }
  477. return null ;
  478. }
  479. //
  480. // Map command-line arguments to ORB properties.
  481. //
  482. protected void findPropertiesFromArgs(Properties props,
  483. Vector orbInitRefList,
  484. String[] params,
  485. String[] propertyNames,
  486. String[] propertyNamePrefixes)
  487. {
  488. // REVISIT: Parameter propertyNamePrefixes is ignored at this time.
  489. // No OMG specs have -ORB<prefix> at this time.
  490. if (ORBInitDebug)
  491. dprint( "findPropertiesFromArgs called with params=" +
  492. ORBUtility.objectToString( params ) + " propertyNames = " +
  493. ORBUtility.objectToString( propertyNames ) ) ;
  494. if (params == null)
  495. return;
  496. // All command-line args are of the form "-ORBkey value".
  497. // The key is mapped to org.omg.CORBA.key.
  498. String name ;
  499. String value ;
  500. for ( int i=0; i<params.length; i++ ) {
  501. value = null ;
  502. name = null ;
  503. if ( params[i] != null && params[i].startsWith("-ORB") ) {
  504. String argName = params[i].substring( 1 ) ;
  505. name = findMatchingPropertyName( propertyNames, argName ) ;
  506. if (name != null)
  507. if (singleParam(params[i])) {
  508. value = params[i] ;
  509. } else if ( i+1 < params.length && params[i+1] != null ) {
  510. value = params[++i];
  511. }
  512. }
  513. if (value != null) {
  514. if (ORBInitDebug)
  515. dprint( "Found property " + name + "=" + value +
  516. " in args" ) ;
  517. if( name.equals( "org.omg.CORBA.ORBInitRef" ) )
  518. {
  519. orbInitRefList.add( value );
  520. }
  521. else
  522. {
  523. props.put( name, value ) ;
  524. }
  525. }
  526. }
  527. }
  528. //
  529. // Map applet parameters to ORB properties.
  530. //
  531. protected void findPropertiesFromApplet(Properties props,
  532. Applet app,
  533. String[] propertyNames,
  534. String[] propertyNamePrefixes)
  535. {
  536. // REVISIT: propertyNamePrefixes is ignored at this time.
  537. // There is no Java API to get a applet parameter
  538. // by specifying its prefix.
  539. if (app == null)
  540. return;
  541. for (int i=0; i < propertyNames.length; i++) {
  542. String value = app.getParameter(propertyNames[i]);
  543. if (value == null)
  544. continue;
  545. props.put(propertyNames[i], value);
  546. }
  547. //
  548. // Special Case:
  549. //
  550. // Convert any applet parameter relative URLs to an
  551. // absolute URL based on the Document Root. This is so HTML URLs can be
  552. // kept relative which is sometimes useful for managing the
  553. // Document Root layout.
  554. //
  555. for (int i=0; i < JavaIDLURLPropertyNames.length; i++) {
  556. String value;
  557. value = props.getProperty(JavaIDLURLPropertyNames[i]);
  558. if (value == null)
  559. continue;
  560. try {
  561. URL url;
  562. url = new URL(app.getDocumentBase(), value);
  563. props.put(JavaIDLURLPropertyNames[i], url.toExternalForm());
  564. } catch (java.net.MalformedURLException ex) {
  565. //
  566. // This will be caught again later if this property is used.
  567. // Don't worry about reporting exceptions now.
  568. //
  569. }
  570. }
  571. }
  572. private static Class thisClass = ORB.class;
  573. private static String getSystemProperty(final String name)
  574. {
  575. return (String)AccessController.doPrivileged(new GetPropertyAction(name));
  576. }
  577. private static Enumeration getSystemPropertyNames()
  578. {
  579. // This will not throw a SecurityException because this
  580. // class was loaded from rt.jar using the bootstrap classloader.
  581. return (Enumeration)
  582. AccessController.doPrivileged(
  583. new PrivilegedAction() {
  584. public java.lang.Object run() {
  585. return System.getProperties().propertyNames();
  586. }
  587. }
  588. );
  589. }
  590. private void getPropertiesFromFile( Properties props, String fileName )
  591. {
  592. try {
  593. File file = new File( fileName ) ;
  594. if (!file.exists())
  595. return ;
  596. FileInputStream in = new FileInputStream( file ) ;
  597. try {
  598. props.load( in ) ;
  599. } finally {
  600. in.close() ;
  601. }
  602. } catch (Exception exc) {
  603. if (ORBInitDebug)
  604. dprint( "ORB properties file " + fileName + " not found: " +
  605. exc) ;
  606. }
  607. }
  608. Properties getFileProperties()
  609. {
  610. Properties defaults = new Properties() ;
  611. String javaHome = getSystemProperty( "java.home" ) ;
  612. String fileName = javaHome + File.separator + "lib" + File.separator +
  613. "orb.properties" ;
  614. getPropertiesFromFile( defaults, fileName ) ;
  615. Properties results = new Properties( defaults ) ;
  616. String userHome = getSystemProperty( "user.home" ) ;
  617. fileName = userHome + File.separator + "orb.properties" ;
  618. getPropertiesFromFile( results, fileName ) ;
  619. return results ;
  620. }
  621. protected void findPropertiesFromFile(Properties props,
  622. String[] propertyNames,
  623. String[] propertyNamePrefixes)
  624. {
  625. final Properties fileProps = getFileProperties() ;
  626. if (fileProps==null)
  627. return ;
  628. for (int i=0; i < propertyNames.length; i++) {
  629. String value;
  630. value = (String)fileProps.getProperty(propertyNames[i]);
  631. if (value == null)
  632. continue;
  633. props.put(propertyNames[i], value);
  634. if (ORBInitDebug)
  635. dprint( "Found property " + propertyNames[i] + "=" +
  636. value + " in file properties" ) ;
  637. }
  638. findPropertiesWithPrefix(
  639. propertyNamePrefixes, fileProps.propertyNames(),
  640. new GetPropertyCallback() {
  641. public String get(String name) {
  642. return fileProps.getProperty(name);
  643. }
  644. },
  645. "file properties", props
  646. );
  647. }
  648. //
  649. // Map System properties to ORB properties.
  650. // Security bug fix 4278205:
  651. // Allow only reading of system properties with ORB prefixes.
  652. // Previously a malicious subclass was able to read ANY system property.
  653. //
  654. private void findORBPropertiesFromSystem(Properties props,
  655. String[] propertyNames,
  656. String[] propertyNamePrefixes)
  657. {
  658. for (int i=0; i < propertyNames.length; i++) {
  659. if (propertyNames[i].startsWith( ORBConstants.OMG_PREFIX ) ||
  660. propertyNames[i].startsWith( ORBConstants.SUN_PREFIX ) ||
  661. propertyNames[i].startsWith( ORBConstants.SUN_LC_PREFIX ) ||
  662. propertyNames[i].startsWith( ORBConstants.SUN_LC_VERSION_PREFIX ))
  663. {
  664. String value = getSystemProperty(propertyNames[i]);
  665. if (value != null) {
  666. props.put(propertyNames[i], value);
  667. if (ORBInitDebug)
  668. dprint( "Found property " + propertyNames[i] + "=" +
  669. value + " in system properties" ) ;
  670. }
  671. }
  672. }
  673. // Any bad apples spoil the whole bunch.
  674. for (int i = 0; i < propertyNamePrefixes.length; i++) {
  675. if (! propertyNamePrefixes[i].startsWith(
  676. ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX ) )
  677. {
  678. throw
  679. new INTERNAL("findORBPropertiesFromSystem: illegal prefix: "
  680. + propertyNamePrefixes[i]);
  681. }
  682. }
  683. Enumeration systemPropertyNames = getSystemPropertyNames();
  684. findPropertiesWithPrefix(
  685. propertyNamePrefixes,
  686. systemPropertyNames,
  687. new GetPropertyCallback() {
  688. public String get(String name) {
  689. return getSystemProperty(name);
  690. }
  691. },
  692. "system properties",
  693. props);
  694. }
  695. //
  696. // Map/copy the properties argument from set_properties() into our
  697. // ORB properties object.
  698. //
  699. protected void findPropertiesFromProperties(Properties props,
  700. Properties arg,
  701. String[] propertyNames,
  702. String[] propertyNamePrefixes)
  703. {
  704. if (ORBInitDebug)
  705. dprint( "FindPropertiesFromProperties called with args = " +
  706. ORBUtility.objectToString( arg ) + "propertytNames = " +
  707. ORBUtility.objectToString( propertyNames ) ) ;
  708. if (arg == null)
  709. return;
  710. for (int i=0; i < propertyNames.length; i++) {
  711. String value;
  712. value = arg.getProperty(propertyNames[i]);
  713. if (value == null)
  714. continue;
  715. props.put(propertyNames[i], value);
  716. if (ORBInitDebug)
  717. dprint( "Found property " + propertyNames[i] + "=" +
  718. value + " in properties argument" ) ;
  719. }
  720. final Properties finalArg = arg;
  721. findPropertiesWithPrefix(
  722. propertyNamePrefixes,
  723. arg.propertyNames(),
  724. new GetPropertyCallback() {
  725. public String get(String name) {
  726. return finalArg.getProperty(name);
  727. }
  728. },
  729. "properties argument",
  730. props);
  731. }
  732. // Set appropriate defaults for an applet ORB.
  733. private void checkAppletPropertyDefaults(Properties props)
  734. {
  735. String host =
  736. props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  737. if ((host == null) || (host.equals(""))) {
  738. props.put( ORBConstants.INITIAL_HOST_PROPERTY, appletHost);
  739. }
  740. String serverHost =
  741. props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  742. if ((serverHost == null) || (serverHost.equals(""))) {
  743. props.put( ORBConstants.SERVER_HOST_PROPERTY,
  744. getLocalHostName());
  745. }
  746. }
  747. // Set appropriate defaults for an application ORB.
  748. private void checkApplicationPropertyDefaults(Properties props)
  749. {
  750. String host = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  751. if ((host == null) || (host.equals(""))) {
  752. props.put( ORBConstants.INITIAL_HOST_PROPERTY,
  753. getLocalHostName());
  754. }
  755. String serverHost =
  756. props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  757. if ((serverHost == null) || (serverHost.equals(""))) {
  758. props.put( ORBConstants.SERVER_HOST_PROPERTY,
  759. getLocalHostName());
  760. }
  761. }
  762. /* keeping a copy of the getLocalHostName so that it can only be called
  763. * internally and the unauthorized clients cannot have access to the
  764. * localHost information, originally, the above code was calling getLocalHostName
  765. * from Connection.java. If the hostname is cached in Connection.java, then
  766. * it is a security hole, since any unauthorized client has access to
  767. * the host information. With this change it is used internally so the
  768. * security problem is resolved. Also in Connection.java, the getLocalHost()
  769. * implementation has changed to always call the
  770. * InetAddress.getLocalHost().getHostAddress()
  771. */
  772. /*
  773. * getLocalHostName is private in this class.
  774. * Eventually, it should be protected, similar methods
  775. * in the subclasses removed and security check made here.
  776. *
  777. */
  778. private static String localHostString = null;
  779. private String getLocalHostName() {
  780. if (localHostString != null) {
  781. return localHostString;
  782. } else {
  783. try {
  784. synchronized (com.sun.corba.se.internal.corba.ORB.class){
  785. if ( localHostString == null )
  786. localHostString = InetAddress.getLocalHost().getHostAddress();
  787. return localHostString;
  788. }
  789. } catch (Exception ex) {
  790. throw new INTERNAL( MinorCodes.GET_LOCAL_HOST_FAILED,
  791. CompletionStatus.COMPLETED_NO );
  792. }
  793. }
  794. }
  795. protected void setDebugFlags( String args )
  796. {
  797. StringTokenizer st = new StringTokenizer( args, "," ) ;
  798. while (st.hasMoreTokens()) {
  799. String token = st.nextToken() ;
  800. // If there is a public boolean data member in this class
  801. // named token + "DebugFlag", set it to true.
  802. try {
  803. Field fld = this.getClass().getField( token + "DebugFlag" ) ;
  804. int mod = fld.getModifiers() ;
  805. if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
  806. if (fld.getType() == boolean.class)
  807. fld.setBoolean( this, true ) ;
  808. } catch (Exception exc) {
  809. // ignore it
  810. }
  811. }
  812. }
  813. /** Use the properties object to configure ORB state.
  814. * This may be overridden by subclasses, but they must call
  815. * super.parseProperties() to allow this class to set its state.
  816. */
  817. protected void parseProperties(Properties props)
  818. {
  819. // get server debug flags
  820. String debugFlags = props.getProperty( ORBConstants.DEBUG_PROPERTY ) ;
  821. if (debugFlags != null) {
  822. if (ORBInitDebug)
  823. dprint( "Setting debug flags to " + debugFlags ) ;
  824. setDebugFlags(debugFlags) ;
  825. }
  826. String param = props.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;
  827. if (param != null) {
  828. if (ORBInitDebug)
  829. dprint( "setting initial host to " + param ) ;
  830. ORBInitialHost = param;
  831. }
  832. param = props.getProperty( ORBConstants.INITIAL_PORT_PROPERTY ) ;
  833. if (param != null) {
  834. try {
  835. ORBInitialPort = Integer.parseInt(param);
  836. if (ORBInitDebug)
  837. dprint( "setting initial services port to " + ORBInitialPort ) ;
  838. initialNamingClient.setInitialServicesPort(ORBInitialPort);
  839. } catch (java.lang.NumberFormatException e) {}
  840. }
  841. param = props.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;
  842. if (param != null) {
  843. if (ORBInitDebug)
  844. dprint( "setting ORB server host to " + param ) ;
  845. ORBServerHost = param;
  846. }
  847. param = props.getProperty( ORBConstants.SERVER_PORT_PROPERTY ) ;
  848. if (param != null) {
  849. try {
  850. ORBServerPort = Integer.parseInt(param);
  851. if (ORBInitDebug)
  852. dprint( "setting ORB server port to " + ORBServerPort ) ;
  853. } catch (java.lang.NumberFormatException e) { }
  854. }
  855. param = props.getProperty( ORBConstants.ORB_ID_PROPERTY ) ;
  856. if (param != null) {
  857. if (ORBInitDebug)
  858. dprint( "setting ORB Id to " + param ) ;
  859. orbId = param;
  860. }
  861. param = props.getProperty( ORBConstants.INITIAL_SERVICES_PROPERTY ) ;
  862. if (param != null) {
  863. try {
  864. if (ORBInitDebug)
  865. dprint( "setting initial services URL to " + param ) ;
  866. initialNamingClient.setServicesURL(new URL(param));
  867. } catch (java.io.IOException ex) {
  868. // Fallthrough
  869. }
  870. }
  871. param = props.getProperty( ORBConstants.ORB_INIT_REF_PROPERTY );
  872. if (param != null) {
  873. try {
  874. if (ORBInitDebug)
  875. dprint( "setting ORBInitRef to " + param ) ;
  876. initialNamingClient.addORBInitRef(param);
  877. } catch (Exception ex) {
  878. // Fallthrough
  879. }
  880. }
  881. param = props.getProperty( ORBConstants.DEFAULT_INIT_REF_PROPERTY ) ;
  882. if (param != null) {
  883. try {
  884. if (ORBInitDebug)
  885. dprint( "setting ORBDefaultInitRef to " + param ) ;
  886. initialNamingClient.setORBDefaultInitRef(param);
  887. } catch (Exception ex) {
  888. // Fallthrough
  889. }
  890. }
  891. //...//The following 3 parameters are there for connection management.
  892. param = props.getProperty( ORBConstants.HIGH_WATER_MARK_PROPERTY ) ;
  893. if (param != null) {
  894. try {
  895. highWaterMark = Integer.parseInt(param);
  896. if (ORBInitDebug)
  897. dprint( "setting high water mark for connections " + highWaterMark ) ;
  898. } catch (java.lang.NumberFormatException e) {}
  899. }
  900. param = props.getProperty( ORBConstants.LOW_WATER_MARK_PROPERTY ) ;
  901. if (param != null) {
  902. try {
  903. lowWaterMark = Integer.parseInt(param);
  904. if (ORBInitDebug)
  905. dprint( "setting low water mark for connections " + lowWaterMark ) ;
  906. } catch (java.lang.NumberFormatException e) {}
  907. }
  908. param = props.getProperty( ORBConstants.NUMBER_TO_RECLAIM_PROPERTY ) ;
  909. if (param != null) {
  910. try {
  911. numberToReclaim = Integer.parseInt(param);
  912. if (ORBInitDebug)
  913. dprint( "setting number of connections to reclaim during cleanup " +
  914. numberToReclaim ) ;
  915. } catch (java.lang.NumberFormatException e) {}
  916. }
  917. //GIOP Related Constants.
  918. param = props.getProperty( ORBConstants.GIOP_VERSION ) ;
  919. if (param != null) {
  920. try {
  921. giopVersion = GIOPVersion.parseVersion(param);
  922. if (ORBInitDebug)
  923. dprint( "setting default GIOP version to " + giopVersion);
  924. } catch (java.lang.NumberFormatException e) {
  925. if (ORBInitDebug)
  926. dprint( "Error: " + e);
  927. }
  928. }
  929. param = props.getProperty( ORBConstants.GIOP_FRAGMENT_SIZE ) ;
  930. if (param != null) {
  931. try {
  932. giopFragmentSize = Integer.parseInt(param);
  933. if(giopFragmentSize < ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE){
  934. throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
  935. + " Illegal value: " + giopFragmentSize
  936. + " (must be at least "
  937. + ORBConstants.GIOP_FRAGMENT_MINIMUM_SIZE
  938. + ")");
  939. }
  940. if (giopFragmentSize % ORBConstants.GIOP_FRAGMENT_DIVISOR != 0)
  941. throw new INITIALIZE(ORBConstants.GIOP_FRAGMENT_SIZE
  942. + " Illegal value: " + giopFragmentSize
  943. + " (not divisible by "
  944. + ORBConstants.GIOP_FRAGMENT_DIVISOR
  945. + ")");
  946. if (ORBInitDebug)
  947. dprint( "setting GIOP fragment size to " + giopFragmentSize ) ;
  948. } catch (java.lang.NumberFormatException e) {}
  949. }
  950. param = props.getProperty( ORBConstants.GIOP_BUFFER_SIZE ) ;
  951. if (param != null) {
  952. try {
  953. giopBufferSize = Integer.parseInt(param);
  954. if (ORBInitDebug)
  955. dprint( "setting GIOP buffer size to " + giopFragmentSize ) ;
  956. } catch (java.lang.NumberFormatException e) {}
  957. }
  958. param = props.getProperty( ORBConstants.GIOP_11_BUFFMGR ) ;
  959. if (param != null) {
  960. try {
  961. giop11BuffMgr = Integer.parseInt(param);
  962. if (ORBInitDebug)
  963. dprint( "setting default GIOP11 BuffMgr to " + giop11BuffMgr);
  964. } catch (java.lang.NumberFormatException e) {
  965. if (ORBInitDebug)
  966. dprint( "Error: " + e);
  967. }
  968. }
  969. param = props.getProperty( ORBConstants.GIOP_12_BUFFMGR ) ;
  970. if (param != null) {
  971. try {
  972. giop12BuffMgr = Integer.parseInt(param);
  973. if (ORBInitDebug)
  974. dprint( "setting default GIOP12 BuffMgr to " + giop12BuffMgr);
  975. } catch (java.lang.NumberFormatException e) {
  976. if (ORBInitDebug)
  977. dprint( "Error: " + e);
  978. }
  979. }
  980. param = props.getProperty(ORBConstants.GIOP_TARGET_ADDRESSING);
  981. if (param != null) {
  982. try {
  983. short targetAddressing = Short.parseShort(param);
  984. switch (targetAddressing) {
  985. case ORBConstants.ADDR_DISP_OBJKEY :
  986. giopAddressDisposition = KeyAddr.value;
  987. giopTargetAddressPreference = targetAddressing;
  988. break;
  989. case ORBConstants.ADDR_DISP_PROFILE :
  990. giopAddressDisposition = ProfileAddr.value;
  991. giopTargetAddressPreference = targetAddressing;
  992. break;
  993. case ORBConstants.ADDR_DISP_IOR :
  994. giopAddressDisposition = ReferenceAddr.value;
  995. giopTargetAddressPreference = targetAddressing;
  996. break;
  997. case ORBConstants.ADDR_DISP_HANDLE_ALL :
  998. giopAddressDisposition = KeyAddr.value;
  999. giopTargetAddressPreference = targetAddressing;
  1000. break;
  1001. default:
  1002. throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
  1003. " Illegal value : " + param);
  1004. }
  1005. if (ORBInitDebug) {
  1006. dprint("setting GIOP TargetAddressing to " +
  1007. giopTargetAddressPreference);
  1008. }
  1009. } catch (java.lang.NumberFormatException e) {
  1010. if (ORBInitDebug)
  1011. dprint( "Error: " + e);
  1012. throw new INITIALIZE(ORBConstants.GIOP_TARGET_ADDRESSING +
  1013. " Illegal value : " + param);
  1014. }
  1015. }
  1016. // Code set related
  1017. param = props.getProperty(ORBConstants.ALWAYS_SEND_CODESET_CTX_PROPERTY);
  1018. if (param != null) {
  1019. alwaysSendCodeSetCtx = Boolean.valueOf(param).booleanValue();
  1020. if (ORBInitDebug)
  1021. dprint("Setting alwaysSendCodeSetCtx to " + alwaysSendCodeSetCtx);
  1022. }
  1023. param = props.getProperty(ORBConstants.USE_BOMS);
  1024. if (param != null) {
  1025. useByteOrderMarkers = Boolean.valueOf(param).booleanValue();
  1026. if (ORBInitDebug)
  1027. dprint("Setting useByteOrderMarkers to " + useByteOrderMarkers);
  1028. }
  1029. param = props.getProperty(ORBConstants.USE_BOMS_IN_ENCAPS);
  1030. if (param != null) {
  1031. useByteOrderMarkersInEncaps = Boolean.valueOf(param).booleanValue();
  1032. if (ORBInitDebug)
  1033. dprint("Setting useByteOrderMarkersInEncaps to " + useByteOrderMarkersInEncaps);
  1034. }
  1035. CodeSetComponentInfo.CodeSetComponent charData
  1036. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getCharComponent();
  1037. param = props.getProperty(ORBConstants.CHAR_CODESETS);
  1038. if (param != null) {
  1039. charData = CodeSetComponentInfo.createFromString(param);
  1040. if (ORBInitDebug)
  1041. dprint("charData: " + charData);
  1042. }
  1043. CodeSetComponentInfo.CodeSetComponent wcharData
  1044. = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.getWCharComponent();
  1045. param = props.getProperty(ORBConstants.WCHAR_CODESETS);
  1046. if (param != null) {
  1047. wcharData = CodeSetComponentInfo.createFromString(param);
  1048. if (ORBInitDebug)
  1049. dprint("wcharData: " + wcharData);
  1050. }
  1051. codesets = new CodeSetComponentInfo(charData, wcharData);
  1052. param = props.getProperty( ORBConstants.ALLOW_LOCAL_OPTIMIZATION ) ;
  1053. if (param != null) {
  1054. allowLocalOptimization = true ;
  1055. }
  1056. //...//
  1057. param = props.getProperty( ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY ) ;
  1058. if (param != null) {
  1059. try {
  1060. Class socketFactoryClass = ORBClassLoader.loadClass(param);
  1061. // For security reasons avoid creating an instance if
  1062. // this socket factory class is not one that would fail
  1063. // the class cast anyway.
  1064. if (ORBSocketFactory.class.isAssignableFrom(socketFactoryClass)) {
  1065. socketFactory = (ORBSocketFactory)socketFactoryClass.newInstance();
  1066. if (ORBInitDebug) {
  1067. dprint("setting socketFactory to: " + socketFactory);
  1068. }
  1069. } else {
  1070. // throw some exception just to get into the outer catch clause
  1071. throw new ClassCastException();
  1072. }
  1073. } catch (Exception ex) {
  1074. // ClassNotFoundException, IllegalAccessException, InstantiationException,
  1075. // SecurityException or ClassCastException
  1076. throw new INITIALIZE(
  1077. "can't instantiate custom socket factory: " + param);
  1078. }
  1079. } else {
  1080. socketFactory = new DefaultSocketFactory();
  1081. }
  1082. //
  1083. // ORBListenSocket
  1084. //
  1085. param = props.getProperty(ORBConstants.LISTEN_SOCKET_PROPERTY);
  1086. if (param != null) {
  1087. StringTokenizer pairs =
  1088. new StringTokenizer(param, ",");
  1089. while (pairs.hasMoreTokens()) {
  1090. String current = pairs.nextToken();
  1091. StringTokenizer pair = new StringTokenizer(current, ":");
  1092. String type = null;
  1093. int port = -1;
  1094. if (pair.hasMoreTokens()) {
  1095. type = pair.nextToken();
  1096. if (pair.hasMoreTokens()) {
  1097. try {
  1098. port = Integer.parseInt(pair.nextToken());
  1099. } catch (NumberFormatException e) {
  1100. ;
  1101. }
  1102. }
  1103. }
  1104. if (type == null || port == -1) {
  1105. throw new INITIALIZE("Improper ORBListenSocket format: "
  1106. + param);
  1107. }
  1108. userSpecifiedListenPorts.add(new UserSpecifiedListenPort(type, port));
  1109. }
  1110. if (ORBInitDebug) {
  1111. dprint("setting listen sockets: " + param);
  1112. }
  1113. }
  1114. }
  1115. /****************************************************************************
  1116. * The following methods are getters and setters for ORB variables.
  1117. ****************************************************************************/
  1118. /**
  1119. * Get the name of the host running the initial services nameserver.
  1120. * @return The name of the ORBInitialHost.
  1121. */
  1122. public String getORBInitialHost()
  1123. {
  1124. return ORBInitialHost;
  1125. }
  1126. /**
  1127. * Get the port of the initial services nameserver.
  1128. */
  1129. public int getORBInitialPort()
  1130. {
  1131. return ORBInitialPort;
  1132. }
  1133. public String getORBServerHost() {
  1134. return ORBServerHost;
  1135. }
  1136. public int getORBServerPort() {
  1137. return ORBServerPort;
  1138. }
  1139. /**
  1140. * Get the name of the host from which this applet was downloaded.
  1141. * @return The name of the AppletHost.
  1142. */
  1143. public String getAppletHost()
  1144. {
  1145. return appletHost;
  1146. }
  1147. /**
  1148. * Get the codebase from which this applet was downloaded.
  1149. */
  1150. public URL getAppletCodeBase()
  1151. {
  1152. return appletCodeBase;
  1153. }
  1154. public class UserSpecifiedListenPort
  1155. {
  1156. private String type;
  1157. private int port;
  1158. UserSpecifiedListenPort (String type, int port)
  1159. {
  1160. this.type = type;
  1161. this.port = port;
  1162. }
  1163. public String getType () { return type; }
  1164. public int getPort () { return port; }
  1165. public String toString () { return type + ":" + port; }
  1166. }
  1167. /**
  1168. * Get the user-defined listen port types.
  1169. */
  1170. public Collection getUserSpecifiedListenPorts ()
  1171. {
  1172. return userSpecifiedListenPorts;
  1173. }
  1174. /**
  1175. * Get the socket factory for this ORB.
  1176. */
  1177. public ORBSocketFactory getSocketFactory ()
  1178. {
  1179. return socketFactory;
  1180. }
  1181. /**
  1182. * Get high water mark number beyond which
  1183. * ORB will not create any more new connections.
  1184. */
  1185. public int getHighWaterMark(){
  1186. return highWaterMark;
  1187. }
  1188. /**
  1189. * Get low water mark number above which
  1190. * ORB will start connection cleanup.
  1191. */
  1192. public int getLowWaterMark(){
  1193. return lowWaterMark;
  1194. }
  1195. /**
  1196. * Get number to reclaim which the
  1197. * ORB uses to determine how many connections to
  1198. * try to clean up.
  1199. */
  1200. public int getNumberToReclaim(){
  1201. return numberToReclaim;
  1202. }
  1203. /**
  1204. * GIOP Related Constants.
  1205. */
  1206. public GIOPVersion getGIOPVersion() {
  1207. return giopVersion;
  1208. }
  1209. public int getGIOPFragmentSize() {
  1210. return giopFragmentSize;
  1211. }
  1212. public int getGIOPBufferSize() {
  1213. return giopBufferSize;
  1214. }
  1215. public int getGIOPBuffMgrStrategy(GIOPVersion gv) {
  1216. if(gv!=null){
  1217. if (gv.equals(GIOPVersion.V1_0)) return 0; //Always grow for 1.0
  1218. if (gv.equals(GIOPVersion.V1_1)) return giop11BuffMgr;
  1219. if (gv.equals(GIOPVersion.V1_2)) return giop12BuffMgr;
  1220. }
  1221. //If a "faulty" GIOPVersion is passed, it's going to return 0;
  1222. return 0;
  1223. }
  1224. /**
  1225. * @return the GIOP Target Addressing preference of the ORB.
  1226. * This ORB by default supports all addressing dispositions unless specified
  1227. * otherwise via a java system property ORBConstants.GIOP_TARGET_ADDRESSING
  1228. */
  1229. public short getGIOPTargetAddressPreference() {
  1230. return giopTargetAddressPreference;
  1231. }
  1232. /**
  1233. * The default addressing disposition is KeyAddr.value
  1234. */
  1235. public short getGIOPAddressDisposition() {
  1236. return giopAddressDisposition;
  1237. }
  1238. public org.omg.CORBA.portable.OutputStream create_output_stream()
  1239. {
  1240. checkShutdownState();
  1241. return new EncapsOutputStream(this);
  1242. }
  1243. /**
  1244. * Get a Current pseudo-object.
  1245. * The Current interface is used to manage thread-specific
  1246. * information for use by the transactions, security and other
  1247. * services. This method is deprecated,
  1248. * and replaced by ORB.resolve_initial_references("NameOfCurrentObject");
  1249. *
  1250. * @return a Current pseudo-object.
  1251. * @deprecated
  1252. */
  1253. public org.omg.CORBA.Current get_current()
  1254. {
  1255. checkShutdownState();
  1256. /* _REVISIT_
  1257. The implementation of get_current is not clear. How would
  1258. ORB know whether the caller wants a Current for transactions
  1259. or security ?? Or is it assumed that there is just one
  1260. implementation for both ? If Current is thread-specific,
  1261. then it should not be instantiated; so where does the
  1262. ORB get a Current ? */
  1263. throw new NO_IMPLEMENT();
  1264. }
  1265. /*
  1266. **************************************************************************
  1267. * The following methods are hooks for Portable Interceptors.
  1268. * They have empty method bodies so that we may ship with or without
  1269. * PI support. The actual implementations can be found in
  1270. * Interceptors.PIORB. Note that not all of these are used in this
  1271. * package, but this ORB class serves as a common place for javadoc
  1272. * comments and to enumerate all hooks.
  1273. *************************************************************************/
  1274. /*
  1275. *****************
  1276. * Client PI hooks
  1277. *****************/
  1278. /**
  1279. * Called for pseudo-ops to temporarily disable portable interceptor
  1280. * hooks for calls on this thread. Keeps track of the number of
  1281. * times this is called and increments the disabledCount.
  1282. */
  1283. protected void disableInterceptorsThisThread() {
  1284. // Intentionally left empty. See above note.
  1285. }
  1286. /**
  1287. * Called for pseudo-ops to re-enable portable interceptor
  1288. * hooks for calls on this thread. Decrements the disabledCount.
  1289. * If disabledCount is 0, interceptors are re-enabled.
  1290. */
  1291. protected void enableInterceptorsThisThread() {
  1292. // Intentionally left empty. See above note.
  1293. }
  1294. /**
  1295. * Called when the send_request or send_poll portable interception point
  1296. * is to be invoked for all appropriate client-side request interceptors.
  1297. *
  1298. * @exception RemarhsalException - Thrown when this request needs to
  1299. * be retried.
  1300. */
  1301. protected void invokeClientPIStartingPoint()
  1302. throws RemarshalException
  1303. {
  1304. // Intentionally left empty. See above note.
  1305. }
  1306. /**
  1307. * Called when the appropriate client ending interception point is
  1308. * to be invoked for all apporpriate client-side request interceptors.
  1309. *
  1310. * @param replyStatus One of the constants in iiop.messages.ReplyMessage
  1311. * indicating which reply status to set.
  1312. * @param exception The exception before ending interception points have
  1313. * been invoked, or null if no exception at the moment.
  1314. * @return The exception to be thrown, after having gone through
  1315. * all ending points, or null if there is no exception to be
  1316. * thrown. Note that this exception can be either the same or
  1317. * different from the exception set using setClientPIException.
  1318. * There are four possible return types: null (no exception),
  1319. * SystemException, UserException, or RemarshalException.
  1320. */
  1321. protected Exception invokeClientPIEndingPoint(
  1322. int replyStatus, Exception exception )
  1323. {
  1324. // Defualt implementation is just a simple pass-through of the
  1325. // given exception.
  1326. return exception;
  1327. }
  1328. /**
  1329. * Invoked when a request is about to be created. Must be called before
  1330. * any of the setClientPI* methods so that a new info object can be
  1331. * prepared for information collection.
  1332. *
  1333. * @param diiRequest True if this is to be a DII request, or false if it
  1334. * is a "normal" request. In the DII case, initiateClientPIRequest
  1335. * is called twice and we need to ignore the second one.
  1336. */
  1337. protected void initiateClientPIRequest( boolean diiRequest ) {
  1338. // Intentionally left empty. See above note.
  1339. }
  1340. /**
  1341. * Invoked when a request is about to be cleaned up. Must be called
  1342. * after ending points are called so that the info object on the stack
  1343. * can be deinitialized and popped from the stack at the appropriate
  1344. * time.
  1345. */
  1346. protected void cleanupClientPIRequest() {
  1347. // Intentionally left empty. See above note.
  1348. }
  1349. /**
  1350. * Notifies PI of the information for client-side interceptors.
  1351. * PI will use this information as a source of information for the
  1352. * ClientRequestInfo object.
  1353. */
  1354. protected void setClientPIInfo( Connection connection,
  1355. ClientDelegate delegate,
  1356. IOR effectiveTarget,
  1357. IIOPProfile profile,
  1358. int requestId,
  1359. String opName,
  1360. boolean isOneWay,
  1361. ServiceContexts svc )
  1362. {
  1363. // Intentionally left empty. See above note.
  1364. }
  1365. /**
  1366. * Notifies PI of additional information for client-side interceptors.
  1367. * PI will use this information as a source of information for the
  1368. * ClientRequestInfo object.
  1369. */
  1370. protected void setClientPIInfo( ClientResponse response ) {
  1371. // Intentionally left empty. See above note.
  1372. }
  1373. /**
  1374. * Notifies PI of additional information for client-side interceptors.
  1375. * PI will use this information as a source of information for the
  1376. * ClientRequestInfo object.
  1377. */
  1378. protected void setClientPIInfo( RequestImpl requestImpl ) {
  1379. // Intentionally left empty. See above note.
  1380. }
  1381. /**
  1382. * Overridden from corba.ORB.
  1383. * See description in corba.ORB.
  1384. */
  1385. protected void sendCancelRequestIfFinalFragmentNotSent() {
  1386. // Intentionally left empty. See above note.
  1387. }
  1388. /*
  1389. *****************
  1390. * Server PI hooks
  1391. *****************/
  1392. /**
  1393. * Called when the appropriate server starting interception point is
  1394. * to be invoked for all appropriate server-side request interceptors.
  1395. *
  1396. * @throws InternalRuntimeForwardRequest Thrown if an interceptor raises
  1397. * ForwardRequest. This is an unchecked exception so that we need
  1398. * not modify the entire execution path to declare throwing
  1399. * ForwardRequest.
  1400. */
  1401. protected void invokeServerPIStartingPoint()
  1402. throws InternalRuntimeForwardRequest
  1403. {
  1404. // Intentionally left empty. See above note.
  1405. }
  1406. /**
  1407. * Called when the appropriate server intermediate interception point is
  1408. * to be invoked for all appropriate server-side request interceptors.
  1409. *
  1410. * @throws InternalRuntimeForwardRequest Thrown if an interceptor raises
  1411. * ForwardRequest. This is an unchecked exception so that we need
  1412. * not modify the entire execution path to declare throwing
  1413. * ForwardRequest.
  1414. */
  1415. protected void invokeServerPIIntermediatePoint()
  1416. throws InternalRuntimeForwardRequest
  1417. {
  1418. // Intentionally left empty. See above note.
  1419. }
  1420. /**
  1421. * Called when the appropriate server ending interception point is
  1422. * to be invoked for all appropriate server-side request interceptors.
  1423. *
  1424. * @param replyMessage The iiop.messages.ReplyMessage containing the
  1425. * reply status. The ior in this object may be modified by the PIORB.
  1426. * @throws InternalRuntimeForwardRequest Thrown if an interceptor raises
  1427. * ForwardRequest. This is an unchecked exception so that we need
  1428. * not modify the entire execution path to declare throwing
  1429. * ForwardRequest.
  1430. */
  1431. protected void invokeServerPIEndingPoint( ReplyMessage replyMessage )
  1432. throws InternalRuntimeForwardRequest
  1433. {
  1434. // Intentionally left empty. See above note.
  1435. }
  1436. /**
  1437. * Notifies PI to start a new server request and set initial
  1438. * information for server-side interceptors.
  1439. * PI will use this information as a source of information for the
  1440. * ServerRequestInfo object. poaimpl is declared as an Object so that
  1441. * we need not introduce a dependency on the POA package.
  1442. */
  1443. protected void initializeServerPIInfo( ServerRequest request,
  1444. java.lang.Object poaimpl, byte[] objectId, byte[] adapterId )
  1445. {
  1446. // Intentionally left empty. See above note.
  1447. }
  1448. /**
  1449. * Notifies PI of additional information reqired for ServerRequestInfo.
  1450. *
  1451. * @param servant The servant. This is java.lang.Object because in the
  1452. * POA case, this will be a org.omg.PortableServer.Servant whereas
  1453. * in the ServerDelegate case this will be an ObjectImpl.
  1454. * @param targetMostDerivedInterface. The most derived interface. This
  1455. * is passed in instead of calculated when needed because it requires
  1456. * extra information in the POA case that we didn't want to bother
  1457. * creating extra methods for to pass in.
  1458. */
  1459. protected void setServerPIInfo( java.lang.Object servant,
  1460. String targetMostDerivedInterface )
  1461. {
  1462. // Intentionally left empty. See above note.
  1463. }
  1464. /**
  1465. * Notifies PI of additional information required for ServerRequestInfo.
  1466. */
  1467. protected void setServerPIInfo( Exception exception ) {
  1468. // Intentionally left empty. See above note.
  1469. }
  1470. /**
  1471. * Notifies PI of additional information for server-side interceptors.
  1472. * PI will use this information as a source of information for the
  1473. * ServerRequestInfo object. These are the arguments for a DSI request.
  1474. */
  1475. protected void setServerPIInfo( NVList arguments ) {
  1476. // Intentionally left empty. See above note.
  1477. }
  1478. /**
  1479. * Notifies PI of additional information for server-side interceptors.
  1480. * PI will use this information as a source of information for the
  1481. * ServerRequestInfo object. This is the exception of a DSI request.
  1482. */
  1483. protected void setServerPIExceptionInfo( Any exception ) {
  1484. // Intentionally left empty. See above note.
  1485. }
  1486. /**
  1487. * Notifies PI of additional information for server-side interceptors.
  1488. * PI will use this information as a source of information for the
  1489. * ServerRequestInfo object. This is the result of a DSI request.
  1490. */
  1491. protected void setServerPIInfo( Any result ) {
  1492. // Intentionally left empty. See above note.
  1493. }
  1494. /**
  1495. * Invoked when a request is about to be cleaned up. Must be called
  1496. * after ending points are called so that the info object on the stack
  1497. * can be deinitialized and popped from the stack at the appropriate
  1498. * time.
  1499. */
  1500. protected void cleanupServerPIRequest() {
  1501. // Intentionally left empty. See above note.
  1502. }
  1503. /*************************************************************************
  1504. * The following methods deal with creation of various types of lists.
  1505. *************************************************************************/
  1506. /**
  1507. * Create an NVList
  1508. *
  1509. * @param count size of list to create
  1510. * @result NVList created
  1511. *
  1512. * @see NVList
  1513. */
  1514. public NVList create_list(int count)
  1515. {
  1516. checkShutdownState();
  1517. return new NVListImpl(this, count);
  1518. }
  1519. /**
  1520. * Create an NVList corresponding to an OperationDef
  1521. *
  1522. * @param oper operation def to use to create list
  1523. * @result NVList created
  1524. *
  1525. * @see NVList
  1526. */
  1527. public NVList create_operation_list(org.omg.CORBA.Object oper)
  1528. {
  1529. checkShutdownState();
  1530. throw new NO_IMPLEMENT();
  1531. }
  1532. /**
  1533. * Create a NamedValue
  1534. *
  1535. * @result NamedValue created
  1536. */
  1537. public NamedValue create_named_value(String s, Any any, int flags)
  1538. {
  1539. checkShutdownState();
  1540. return new NamedValueImpl(this, s, any, flags);
  1541. }
  1542. /**
  1543. * Create an ExceptionList
  1544. *
  1545. * @result ExceptionList created
  1546. */
  1547. public org.omg.CORBA.ExceptionList create_exception_list()
  1548. {
  1549. checkShutdownState();
  1550. return new ExceptionListImpl();
  1551. }
  1552. /**
  1553. * Create a ContextList
  1554. *
  1555. * @result ContextList created
  1556. */
  1557. public org.omg.CORBA.ContextList create_context_list()
  1558. {
  1559. checkShutdownState();
  1560. return new ContextListImpl(this);
  1561. }
  1562. /**
  1563. * Get the default Context object
  1564. *
  1565. * @result the default Context object
  1566. */
  1567. public org.omg.CORBA.Context get_default_context()
  1568. {
  1569. checkShutdownState();
  1570. throw new NO_IMPLEMENT();
  1571. }
  1572. /**
  1573. * Create an Environment
  1574. *
  1575. * @result Environment created
  1576. */
  1577. public org.omg.CORBA.Environment create_environment()
  1578. {
  1579. checkShutdownState();
  1580. return new EnvironmentImpl();
  1581. }
  1582. /****************************************************************************
  1583. * The following methods deal with multiple/deferred DII invocations.
  1584. ****************************************************************************/
  1585. public void send_multiple_requests_oneway(Request[] req)
  1586. {
  1587. checkShutdownState();
  1588. // Invoke the send_oneway on each new Request
  1589. for (int i = 0; i < req.length; i++) {
  1590. req[i].send_oneway();
  1591. }
  1592. }
  1593. /**
  1594. * Send multiple dynamic requests asynchronously.
  1595. *
  1596. * @param req an array of request objects.
  1597. */
  1598. public void send_multiple_requests_deferred(Request[] req)
  1599. {
  1600. checkShutdownState();
  1601. // add the new Requests to pending dynamic Requests
  1602. for (int i = 0; i < req.length; i++) {
  1603. _dynamicRequests.addElement(req[i]);
  1604. }
  1605. // Invoke the send_deferred on each new Request
  1606. for (int i = 0; i < req.length; i++) {
  1607. AsynchInvoke invokeObject = new AsynchInvoke(
  1608. this, (com.sun.corba.se.internal.corba.RequestImpl)req[i], true);
  1609. new Thread(invokeObject).start();
  1610. }
  1611. }
  1612. /**
  1613. * Find out if any of the deferred invocations have a response yet.
  1614. */
  1615. public boolean poll_next_response()
  1616. {
  1617. checkShutdownState();
  1618. Request currRequest;
  1619. // poll on each pending request
  1620. Enumeration ve = _dynamicRequests.elements();
  1621. while (ve.hasMoreElements() == true) {
  1622. currRequest = (Request)ve.nextElement();
  1623. if (currRequest.poll_response() == true) {
  1624. return true;
  1625. }
  1626. }
  1627. return false;
  1628. }
  1629. /**
  1630. * Get the next request that has gotten a response.
  1631. *
  1632. * @result the next request ready with a response.
  1633. */
  1634. public org.omg.CORBA.Request get_next_response()
  1635. throws org.omg.CORBA.WrongTransaction
  1636. {
  1637. checkShutdownState();
  1638. while (true) {
  1639. // check if there already is a response
  1640. synchronized ( _dynamicRequests ) {
  1641. Enumeration elems = _dynamicRequests.elements();
  1642. while ( elems.hasMoreElements() ) {
  1643. Request currRequest = (Request)elems.nextElement();
  1644. if ( currRequest.poll_response() ) {
  1645. // get the response for this successfully polled Request
  1646. currRequest.get_response();
  1647. _dynamicRequests.removeElement(currRequest);
  1648. return currRequest;
  1649. }
  1650. }
  1651. }
  1652. // wait for a response
  1653. synchronized(this._svResponseReceived) {
  1654. this._svResponseReceived.reset();
  1655. while (this._svResponseReceived.value() == false) {
  1656. try {
  1657. this._svResponseReceived.wait();
  1658. } catch(java.lang.InterruptedException ex) {}
  1659. }
  1660. // reinitialize the response flag
  1661. this._svResponseReceived.reset();
  1662. }
  1663. }
  1664. }
  1665. /**
  1666. * Notify response to ORB for get_next_response
  1667. */
  1668. synchronized void notifyResponse() {
  1669. this._svResponseReceived.set();
  1670. this._svResponseReceived.notify();
  1671. }
  1672. /****************************************************************************
  1673. * The following methods deal with stringifying/destringifying
  1674. * and connecting/disconnecting object references.
  1675. ****************************************************************************/
  1676. /**
  1677. * Convert an object ref to a string.
  1678. * @param obj The object to stringify.
  1679. * @return A stringified object reference.
  1680. */
  1681. public String object_to_string(org.omg.CORBA.Object obj)
  1682. {
  1683. checkShutdownState();
  1684. // Handle the null objref case
  1685. if (obj == null)
  1686. return IOR.NULL.stringify(this);
  1687. if (! (obj instanceof ObjectImpl)) {
  1688. throw new MARSHAL("Argument is not an ObjectImpl.",
  1689. MinorCodes.NOT_AN_OBJECT_IMPL,
  1690. CompletionStatus.COMPLETED_NO);
  1691. }
  1692. // Try and get the objref's delegate if it exists
  1693. ClientSubcontract rep=null;
  1694. ObjectImpl oi = (ObjectImpl)obj;
  1695. try {
  1696. // throws BAD_OPERATION if no delegate
  1697. rep = (ClientSubcontract)oi._get_delegate();
  1698. } catch ( Exception ex ) {}
  1699. if ( rep == null ) {
  1700. // No delegate: servant was not connected to ORB
  1701. // This connect only occurs in non-POA cases.
  1702. connect(obj);
  1703. rep = (ClientSubcontract)oi._get_delegate();
  1704. }
  1705. return rep.marshal().stringify();
  1706. }
  1707. /**
  1708. * Convert a stringified object reference to the object it represents.
  1709. * @param str The stringified object reference.
  1710. * @return The unstringified object reference.
  1711. */
  1712. public org.omg.CORBA.Object string_to_object(String str)
  1713. {
  1714. checkShutdownState();
  1715. if ( str == null )
  1716. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.NULL_PARAM,
  1717. CompletionStatus.COMPLETED_NO);
  1718. // If the String starts with corbaloc: resolve it using the
  1719. // URL resolution technique
  1720. if( str.startsWith( "corbaloc:" ) ) {
  1721. String sresult = null;
  1722. CorbaLoc theCorbaLocObject = null;
  1723. theCorbaLocObject = initialNamingClient.checkcorbalocGrammer( str );
  1724. if( theCorbaLocObject == null )
  1725. // This is thrown because the corbaloc: URL is not correct
  1726. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR,
  1727. CompletionStatus.COMPLETED_NO);
  1728. // If the choosen protocol option is not rir: then just create the
  1729. // IOR with the given corbaloc: info
  1730. if( theCorbaLocObject.getRIRFlag() == false ) {
  1731. // HostInfo will never be null if CORBALOC object is not null
  1732. // and RIRFlag is false. Hence no need to do an extra check for
  1733. // hostInfo == null.
  1734. java.util.Vector hostInfoList = theCorbaLocObject.getHostInfo();
  1735. if( ( hostInfoList != null ) && (hostInfoList.size() > 0 ) ) {
  1736. com.sun.corba.se.internal.ior.IOR ior =
  1737. new com.sun.corba.se.internal.ior.IOR( );
  1738. ObjectKey okey = ObjectKeyFactory.get().create( this,
  1739. theCorbaLocObject.getKeyString().getBytes() );
  1740. ObjectId id = okey.getId();
  1741. for( Enumeration e = hostInfoList.elements( );
  1742. e.hasMoreElements(); )
  1743. {
  1744. HostInfo hostInfo = (HostInfo) e.nextElement();
  1745. IIOPAddress addr = new IIOPAddressImpl(
  1746. hostInfo.getHostName(), hostInfo.getPortNumber());
  1747. IIOPProfileTemplate iiopt =
  1748. new StandardIIOPProfileTemplate( addr,
  1749. hostInfo.getMajorNumber(),
  1750. hostInfo.getMinorNumber(),
  1751. okey.getTemplate(), null, this );
  1752. com.sun.corba.se.internal.ior.IIOPProfile profile =
  1753. new com.sun.corba.se.internal.ior.IIOPProfile( id,
  1754. iiopt );
  1755. ior.add( profile );
  1756. }
  1757. ior.makeImmutable();
  1758. String iorstr = ior.stringify( this );
  1759. return IOR.getIORFromString( this, iorstr ) ;
  1760. }
  1761. }
  1762. sresult = initialNamingClient.resolveCorbaloc( theCorbaLocObject );
  1763. if( sresult == null )
  1764. throw new INV_OBJREF( MinorCodes.BAD_CORBALOC_STRING,
  1765. CompletionStatus.COMPLETED_NO ) ;
  1766. return IOR.getIORFromString( this, sresult ) ;
  1767. } else if( str.startsWith( "corbaname:" ) ) {
  1768. // If it String starts with corbaname: resolve it using the
  1769. // URL resolution technique
  1770. CorbaName theCorbaNameObject = null;
  1771. theCorbaNameObject = initialNamingClient.checkcorbanameGrammer( str );
  1772. if( theCorbaNameObject == null )
  1773. // This is thrown because the corbaname: URL is not correct
  1774. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR,
  1775. CompletionStatus.COMPLETED_NO);
  1776. return initialNamingClient.resolveCorbaname( theCorbaNameObject );
  1777. } else if (str.startsWith( IOR.STRINGIFY_PREFIX ) ) {
  1778. // else it starts with IOR, So we need to do the regular IOR:
  1779. // resolution.
  1780. return IOR.getIORFromString( this, str ) ;
  1781. } else {
  1782. // Not a legal string: raise an exception
  1783. throw new org.omg.CORBA.DATA_CONVERSION(
  1784. MinorCodes.BAD_STRINGIFIED_IOR, CompletionStatus.COMPLETED_NO );
  1785. }
  1786. }
  1787. /** This is the implementation of the public API used to connect
  1788. * a servant-skeleton to the ORB.
  1789. */
  1790. public void connect(org.omg.CORBA.Object servant)
  1791. {
  1792. checkShutdownState();
  1793. int subContractIndex = SubcontractList.defaultSubcontract;
  1794. try {
  1795. ServerSubcontract s
  1796. = getSubcontractRegistry().getServerSubcontract(subContractIndex);
  1797. s.createObjref((byte[]) null, servant);
  1798. }
  1799. catch ( Exception ex ) {
  1800. if (subcontractDebugFlag) {
  1801. dprint( "Error in createObjref: " + ex ) ;
  1802. ex.printStackTrace() ;
  1803. }
  1804. throw new OBJ_ADAPTER(MinorCodes.ORB_CONNECT_ERROR,
  1805. CompletionStatus.COMPLETED_NO);
  1806. }
  1807. }
  1808. public void disconnect(org.omg.CORBA.Object obj)
  1809. {
  1810. checkShutdownState();
  1811. try {
  1812. // Get the delegate, then ior, then server-subcontract,
  1813. // then tell it to delete the servant from its "servant manager".
  1814. ObjectImpl oi = (ObjectImpl)obj;
  1815. ClientSubcontract rep = (ClientSubcontract)oi._get_delegate();
  1816. IOR ior = rep.marshal();
  1817. ObjectKeyTemplate temp = ior.getProfile().getTemplate().getObjectKeyTemplate();
  1818. int scid = temp.getSubcontractId() ;
  1819. ServerSubcontract sc = getSubcontractRegistry().getServerSubcontract(scid);
  1820. sc.destroyObjref(obj);
  1821. }
  1822. catch ( Exception ex ) {
  1823. throw new OBJ_ADAPTER(MinorCodes.ORB_CONNECT_ERROR,
  1824. CompletionStatus.COMPLETED_MAYBE);
  1825. }
  1826. }
  1827. //d11638: pure java orb support, moved this method from FVDCodeBaseImpl
  1828. // Note that we connect this if we have not already done so.
  1829. public IOR getServantIOR(){
  1830. if (ior != null) // i.e. We are already connected to it
  1831. return ior;
  1832. // backward compatability 4365188
  1833. CodeBase cb;
  1834. ValueHandler vh = ORBUtility.createValueHandler(this);
  1835. cb = (CodeBase)vh.getRunTimeCodeBase();
  1836. connect(cb);
  1837. ClientSubcontract rep=null;
  1838. ObjectImpl oi = (ObjectImpl)cb;
  1839. rep = (ClientSubcontract)oi._get_delegate();
  1840. ior = rep.marshal();
  1841. return ior;
  1842. }
  1843. /****************************************************************************
  1844. * The following methods deal with creation of TypeCodes and Any, etc.
  1845. ****************************************************************************/
  1846. /**
  1847. * Get the TypeCode for a primitive type.
  1848. *
  1849. * @param tcKind the integer kind for the primitive type
  1850. * @return the requested TypeCode
  1851. */
  1852. public TypeCode get_primitive_tc(TCKind tcKind)
  1853. {
  1854. checkShutdownState();
  1855. // _REVISIT_ if this returns a null, throw an exception perhaps?
  1856. return TypeCodeImpl.get_primitive_tc(tcKind);
  1857. }
  1858. /**
  1859. * Create a TypeCode for a structure.
  1860. *
  1861. * @param id the logical id for the typecode.
  1862. * @param name the name for the typecode.
  1863. * @param members an array describing the members of the TypeCode.
  1864. * @return the requested TypeCode.
  1865. */
  1866. public TypeCode create_struct_tc(String id,
  1867. String name,
  1868. StructMember[] members)
  1869. {
  1870. checkShutdownState();
  1871. return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members);
  1872. }
  1873. /**
  1874. * Create a TypeCode for a union.
  1875. *
  1876. * @param id the logical id for the typecode.
  1877. * @param name the name for the typecode.
  1878. * @param discriminator_type
  1879. * the type of the union discriminator.
  1880. * @param members an array describing the members of the TypeCode.
  1881. * @return the requested TypeCode.
  1882. */
  1883. public TypeCode create_union_tc(String id,
  1884. String name,
  1885. TypeCode discriminator_type,
  1886. UnionMember[] members)
  1887. {
  1888. checkShutdownState();
  1889. return new TypeCodeImpl(this,
  1890. TCKind._tk_union,
  1891. id,
  1892. name,
  1893. discriminator_type,
  1894. members);
  1895. }
  1896. /**
  1897. * Create a TypeCode for an enum.
  1898. *
  1899. * @param id the logical id for the typecode.
  1900. * @param name the name for the typecode.
  1901. * @param members an array describing the members of the TypeCode.
  1902. * @return the requested TypeCode.
  1903. */
  1904. public TypeCode create_enum_tc(String id,
  1905. String name,
  1906. String[] members)
  1907. {
  1908. checkShutdownState();
  1909. return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members);
  1910. }
  1911. /**
  1912. * Create a TypeCode for an alias.
  1913. *
  1914. * @param id the logical id for the typecode.
  1915. * @param name the name for the typecode.
  1916. * @param original_type
  1917. * the type this is an alias for.
  1918. * @return the requested TypeCode.
  1919. */
  1920. public TypeCode create_alias_tc(String id,
  1921. String name,
  1922. TypeCode original_type)
  1923. {
  1924. checkShutdownState();
  1925. return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type);
  1926. }
  1927. /**
  1928. * Create a TypeCode for an exception.
  1929. *
  1930. * @param id the logical id for the typecode.
  1931. * @param name the name for the typecode.
  1932. * @param members an array describing the members of the TypeCode.
  1933. * @return the requested TypeCode.
  1934. */
  1935. public TypeCode create_exception_tc(String id,
  1936. String name,
  1937. StructMember[] members)
  1938. {
  1939. checkShutdownState();
  1940. return new TypeCodeImpl(this, TCKind._tk_except, id, name, members);
  1941. }
  1942. /**
  1943. * Create a TypeCode for an interface.
  1944. *
  1945. * @param id the logical id for the typecode.
  1946. * @param name the name for the typecode.
  1947. * @return the requested TypeCode.
  1948. */
  1949. public TypeCode create_interface_tc(String id,
  1950. String name)
  1951. {
  1952. checkShutdownState();
  1953. return new TypeCodeImpl(this, TCKind._tk_objref, id, name);
  1954. }
  1955. /**
  1956. * Create a TypeCode for a string.
  1957. *
  1958. * @param bound the bound for the string.
  1959. * @return the requested TypeCode.
  1960. */
  1961. public TypeCode create_string_tc(int bound)
  1962. {
  1963. checkShutdownState();
  1964. return new TypeCodeImpl(this, TCKind._tk_string, bound);
  1965. }
  1966. /**
  1967. * Create a TypeCode for a wide string.
  1968. *
  1969. * @param bound the bound for the string.
  1970. * @return the requested TypeCode.
  1971. */
  1972. public TypeCode create_wstring_tc(int bound)
  1973. {
  1974. checkShutdownState();
  1975. return new TypeCodeImpl(this, TCKind._tk_wstring, bound);
  1976. }
  1977. /**
  1978. * Create a TypeCode for a sequence.
  1979. *
  1980. * @param bound the bound for the sequence.
  1981. * @param element_type
  1982. * the type of elements of the sequence.
  1983. * @return the requested TypeCode.
  1984. */
  1985. public TypeCode create_sequence_tc(int bound,
  1986. TypeCode element_type)
  1987. {
  1988. checkShutdownState();
  1989. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type);
  1990. }
  1991. /**
  1992. * Create a recursive TypeCode in a sequence.
  1993. *
  1994. * @param bound the bound for the sequence.
  1995. * @param offset the index to the enclosing TypeCode that is
  1996. * being referenced.
  1997. * @return the requested TypeCode.
  1998. */
  1999. public TypeCode create_recursive_sequence_tc(int bound,
  2000. int offset)
  2001. {
  2002. checkShutdownState();
  2003. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset);
  2004. }
  2005. /**
  2006. * Create a TypeCode for an array.
  2007. *
  2008. * @param length the length of the array.
  2009. * @param element_type
  2010. * the type of elements of the array.
  2011. * @return the requested TypeCode.
  2012. */
  2013. public TypeCode create_array_tc(int length,
  2014. TypeCode element_type)
  2015. {
  2016. checkShutdownState();
  2017. return new TypeCodeImpl(this, TCKind._tk_array, length, element_type);
  2018. }
  2019. public org.omg.CORBA.TypeCode create_native_tc(String id,
  2020. String name)
  2021. {
  2022. checkShutdownState();
  2023. return new TypeCodeImpl(this, TCKind._tk_native, id, name);
  2024. }
  2025. public org.omg.CORBA.TypeCode create_abstract_interface_tc(
  2026. String id,
  2027. String name)
  2028. {
  2029. checkShutdownState();
  2030. return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
  2031. }
  2032. public org.omg.CORBA.TypeCode create_fixed_tc(short digits, short scale)
  2033. {
  2034. checkShutdownState();
  2035. return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale);
  2036. }
  2037. public org.omg.CORBA.TypeCode create_value_tc(String id,
  2038. String name,
  2039. short type_modifier,
  2040. TypeCode concrete_base,
  2041. ValueMember[] members)
  2042. {
  2043. checkShutdownState();
  2044. return new TypeCodeImpl(this, TCKind._tk_value, id, name,
  2045. type_modifier, concrete_base, members);
  2046. }
  2047. public org.omg.CORBA.TypeCode create_recursive_tc(String id) {
  2048. checkShutdownState();
  2049. return new TypeCodeImpl(this, id);
  2050. }
  2051. public org.omg.CORBA.TypeCode create_value_box_tc(String id,
  2052. String name,
  2053. TypeCode boxed_type)
  2054. {
  2055. checkShutdownState();
  2056. return new TypeCodeImpl(this, TCKind._tk_value_box, id, name, boxed_type);
  2057. }
  2058. /**
  2059. * Create a new Any
  2060. *
  2061. * @return the new Any created.
  2062. */
  2063. public Any create_any()
  2064. {
  2065. checkShutdownState();
  2066. return new AnyImpl(this);
  2067. }
  2068. // TypeCodeFactory interface methods.
  2069. // Keeping track of type codes by repository id.
  2070. public void setTypeCode(String id, TypeCodeImpl tci) {
  2071. if (typeCodeMap == null)
  2072. typeCodeMap = Collections.synchronizedMap(new WeakHashMap(64));
  2073. // Store only meaningfull ids and store only one TypeCode per id.
  2074. // There can be many TypeCodes created programmatically by the user with the same id.
  2075. if (id != null && id.length() != 0 && ! typeCodeMap.containsKey(id))
  2076. typeCodeMap.put(id, tci);
  2077. }
  2078. public TypeCodeImpl getTypeCode(String id) {
  2079. if (typeCodeMap == null)
  2080. return null;
  2081. return (TypeCodeImpl)typeCodeMap.get(id);
  2082. }
  2083. // Keeping a cache of TypeCodes associated with the class
  2084. // they got created from in Util.writeAny().
  2085. void setTypeCodeForClass(Class c, TypeCodeImpl tci) {
  2086. if (typeCodeForClassMap == null)
  2087. typeCodeForClassMap = Collections.synchronizedMap(new WeakHashMap(64));
  2088. // Store only one TypeCode per class.
  2089. if ( ! typeCodeForClassMap.containsKey(c))
  2090. typeCodeForClassMap.put(c, tci);
  2091. }
  2092. TypeCodeImpl getTypeCodeForClass(Class c) {
  2093. if (typeCodeForClassMap == null)
  2094. return null;
  2095. return (TypeCodeImpl)typeCodeForClassMap.get(c);
  2096. }
  2097. /****************************************************************************
  2098. * The following methods deal with listing and resolving the initial
  2099. * (bootstrap) object references such as "NameService".
  2100. ****************************************************************************/
  2101. /**
  2102. * Get a list of the initially available CORBA services.
  2103. * This does not work unless an ORBInitialHost is specified during initialization
  2104. * (or unless there is an ORB running on the AppletHost) since the localhostname
  2105. * is inaccessible to applets. If a service properties URL was specified,
  2106. * then it is used, otherwise the bootstrapping protocol is used.
  2107. * @return A list of the initial services available.
  2108. */
  2109. public String[] list_initial_services()
  2110. {
  2111. checkShutdownState();
  2112. String[] res1 = initialNamingClient.list_initial_services();
  2113. String[] res2 = listInitialReferences() ;
  2114. return ORBUtility.concatenateStringArrays( res1, res2 ) ;
  2115. }
  2116. /**
  2117. * Resolve the stringified reference of one of the initially
  2118. * available CORBA services.
  2119. * @param identifier The stringified object reference of the
  2120. * desired service.
  2121. * @return An object reference for the desired service.
  2122. * @exception InvalidName The supplied identifier is not associated
  2123. * with a known service.
  2124. * @exception SystemException One of a fixed set of Corba system exceptions.
  2125. */
  2126. public org.omg.CORBA.Object resolve_initial_references(
  2127. String identifier) throws InvalidName
  2128. {
  2129. checkShutdownState();
  2130. org.omg.CORBA.Object result = resolveInitialReference( identifier ) ;
  2131. if (result == null)
  2132. result = initialNamingClient.resolve_initial_references(
  2133. identifier ) ;
  2134. return result ;
  2135. }
  2136. /**
  2137. * If this operation is called with an id, <code>"Y"</code>, and an
  2138. * object, <code>YY</code>, then a subsequent call to
  2139. * <code>ORB.resolve_initial_references( "Y" )</code> will
  2140. * return object <code>YY</code>.
  2141. *
  2142. * @param id The ID by which the initial reference will be known.
  2143. * @param obj The initial reference itself.
  2144. * @throws InvalidName if this operation is called with an empty string id
  2145. * or this operation is called with an id that is already registered,
  2146. * including the default names defined by OMG.
  2147. * @throws BAD_PARAM if the obj parameter is null.
  2148. */
  2149. public void register_initial_reference(
  2150. String id, org.omg.CORBA.Object obj ) throws InvalidName
  2151. {
  2152. if ((id == null) || (id.length() == 0))
  2153. throw new InvalidName() ;
  2154. java.lang.Object obj2 = initialReferenceTable.get( id ) ;
  2155. if (obj2 != null)
  2156. throw new InvalidName(id + " already registered") ;
  2157. registerInitialReference( id, new Constant( obj )) ;
  2158. // This extra step of registering the ServerSubcontract is to make the
  2159. // this object (Service) available to INS clients.
  2160. // Note: LocalObjects will not be available through INS URL's.
  2161. if( obj instanceof ObjectImpl ) {
  2162. ObjectImpl oi = (ObjectImpl)obj;
  2163. ClientSubcontract rep = (ClientSubcontract)oi._get_delegate();
  2164. IOR ior = rep.marshal();
  2165. ObjectKeyTemplate temp =
  2166. ior.getProfile().getTemplate().getObjectKeyTemplate();
  2167. int scid = temp.getSubcontractId() ;
  2168. ServerSubcontract sc =
  2169. getSubcontractRegistry().getServerSubcontract(scid);
  2170. INSObjectKeyEntry entry = new INSObjectKeyEntry( ior, sc );
  2171. INSObjectKeyMap.getInstance().setEntry( id, entry );
  2172. }
  2173. }
  2174. /***************************************************
  2175. * Methods used to support local initial references
  2176. ***************************************************/
  2177. protected void registerInitialReference( String id, Closure closure )
  2178. {
  2179. initialReferenceTable.put( id, closure ) ;
  2180. }
  2181. protected org.omg.CORBA.Object resolveInitialReference( String id )
  2182. {
  2183. java.lang.Object obj = initialReferenceTable.get( id ) ;
  2184. if (obj == null)
  2185. return null ;
  2186. Closure closure = (Closure)obj ;
  2187. java.lang.Object result = closure.evaluate() ;
  2188. return (org.omg.CORBA.Object)result ;
  2189. }
  2190. protected String[] listInitialReferences()
  2191. {
  2192. java.lang.Object[] arr = initialReferenceTable.keySet().toArray() ;
  2193. String[] result = new String[arr.length] ;
  2194. for (int ctr=0; ctr< result.length; ctr++)
  2195. result[ctr] = (String)(arr[ctr]) ;
  2196. return result ;
  2197. }
  2198. /****************************************************************************
  2199. * The following methods (introduced in POA / CORBA2.1) deal with
  2200. * shutdown / single threading.
  2201. ****************************************************************************/
  2202. public void run() {
  2203. checkShutdownState();
  2204. synchronized (runObj) {
  2205. try {
  2206. runObj.wait();
  2207. } catch ( InterruptedException ex ) {}
  2208. }
  2209. }
  2210. public void shutdown(boolean wait_for_completion) {
  2211. // Avoid more than one thread performing shutdown at a time.
  2212. synchronized (shutdownObj) {
  2213. checkShutdownState();
  2214. // This is to avoid deadlock
  2215. if (wait_for_completion && isProcessingInvocation.get() == Boolean.TRUE) {
  2216. throw new BAD_INV_ORDER(
  2217. "Request to shutdown ORB with waiting for completion while servicing a request",
  2218. MinorCodes.SHUTDOWN_WAIT_FOR_COMPLETION_DEADLOCK,
  2219. CompletionStatus.COMPLETED_NO);
  2220. }
  2221. status = STATUS_SHUTTING_DOWN;
  2222. shutdownServants(wait_for_completion);
  2223. if (wait_for_completion) {
  2224. synchronized ( waitForCompletionObj ) {
  2225. while (numInvocations > 0) {
  2226. try {
  2227. waitForCompletionObj.wait();
  2228. } catch (InterruptedException ex) {}
  2229. }
  2230. }
  2231. }
  2232. synchronized ( runObj ) {
  2233. runObj.notifyAll();
  2234. }
  2235. status = STATUS_SHUTDOWN;
  2236. }
  2237. }
  2238. // specific shutdown work for each subclass goes here
  2239. protected abstract void shutdownServants(boolean wait_for_completion);
  2240. protected abstract void destroyConnections();
  2241. protected void checkShutdownState() {
  2242. if (status == STATUS_DESTROYED) {
  2243. throw new OBJECT_NOT_EXIST("ORB has been destroyed");
  2244. }
  2245. if (status == STATUS_SHUTDOWN) {
  2246. throw new BAD_INV_ORDER("ORB has been shut down",
  2247. MinorCodes.BAD_OPERATION_AFTER_SHUTDOWN,
  2248. CompletionStatus.COMPLETED_NO);
  2249. }
  2250. }
  2251. protected void startingDispatch() {
  2252. synchronized (invocationObj) {
  2253. isProcessingInvocation.set(Boolean.TRUE);
  2254. numInvocations++;
  2255. }
  2256. }
  2257. protected void finishedDispatch() {
  2258. synchronized (invocationObj) {
  2259. numInvocations--;
  2260. isProcessingInvocation.set(Boolean.FALSE);
  2261. if (numInvocations == 0) {
  2262. synchronized (waitForCompletionObj) {
  2263. waitForCompletionObj.notifyAll();
  2264. }
  2265. } else if (numInvocations < 0) {
  2266. throw new INTERNAL("Invocation tracking information out of sync.", 0, CompletionStatus.COMPLETED_YES );
  2267. }
  2268. }
  2269. }
  2270. /**
  2271. * formal/99-10-07 p 159: "If destroy is called on an ORB that has
  2272. * not been shut down, it will start the shutdown process and block until
  2273. * the ORB has shut down before it destroys the ORB."
  2274. */
  2275. public void destroy() {
  2276. if (status == STATUS_OPERATING) {
  2277. shutdown(true);
  2278. }
  2279. destroyConnections();
  2280. status = STATUS_DESTROYED;
  2281. }
  2282. public boolean work_pending()
  2283. {
  2284. checkShutdownState();
  2285. throw new NO_IMPLEMENT();
  2286. }
  2287. public void perform_work()
  2288. {
  2289. checkShutdownState();
  2290. throw new NO_IMPLEMENT();
  2291. }
  2292. /**
  2293. * Registers a value factory for a particular repository ID.
  2294. *
  2295. * @param repositoryID the repository ID.
  2296. * @param factory the factory.
  2297. * @return the previously registered factory for the given repository ID, or null
  2298. * if no such factory was previously registered.
  2299. * @exception org.omg.CORBA.BAD_PARAM if the registration fails.
  2300. **/
  2301. public ValueFactory register_value_factory(String repositoryID, ValueFactory factory) {
  2302. checkShutdownState();
  2303. if ((repositoryID == null) || (factory == null))
  2304. throw new BAD_PARAM(MinorCodes.UNABLE_REGISTER_VALUE_FACTORY,
  2305. CompletionStatus.COMPLETED_NO);
  2306. return (ValueFactory)valueFactoryCache.put(repositoryID, factory);
  2307. }
  2308. /**
  2309. * Unregisters a value factory for a particular repository ID.
  2310. *
  2311. * @param repositoryID the repository ID.
  2312. **/
  2313. public void unregister_value_factory(String repositoryID) {
  2314. checkShutdownState();
  2315. if (valueFactoryCache.remove(repositoryID) == null)
  2316. throw new BAD_PARAM(MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_NO);
  2317. }
  2318. /**
  2319. * Finds and returns a value factory for the given repository ID.
  2320. * The value factory returned was previously registered by a call to
  2321. * {@link #register_value_factory} or is the default factory.
  2322. *
  2323. * @param repositoryID the repository ID.
  2324. * @return the value factory.
  2325. * @exception org.omg.CORBA.BAD_PARAM if unable to locate a factory.
  2326. **/
  2327. public ValueFactory lookup_value_factory(String repositoryID) {
  2328. checkShutdownState();
  2329. ValueFactory factory = (ValueFactory)valueFactoryCache.get(repositoryID);
  2330. if (factory != null) {
  2331. return factory;
  2332. } else {
  2333. try {
  2334. return Utility.getFactory(null, null, null, repositoryID);
  2335. } catch(org.omg.CORBA.MARSHAL ex) {
  2336. throw new org.omg.CORBA.BAD_PARAM(ex.getMessage(),
  2337. MinorCodes. UNABLE_FIND_VALUE_FACTORY,
  2338. CompletionStatus.COMPLETED_NO);
  2339. }
  2340. }
  2341. }
  2342. } // Class ORB
  2343. ////////////////////////////////////////////////////////////////////////
  2344. /// Helper class for a Synchronization Variable
  2345. class SynchVariable {
  2346. // Synchronization Variable
  2347. public boolean _flag;
  2348. // Constructor
  2349. SynchVariable() {
  2350. _flag = false;
  2351. }
  2352. // set Flag to true
  2353. public synchronized void set() {
  2354. _flag = true;
  2355. }
  2356. // get value
  2357. public synchronized boolean value() {
  2358. return _flag;
  2359. }
  2360. // reset Flag to true
  2361. public synchronized void reset() {
  2362. _flag = false;
  2363. }
  2364. }
  2365. // Used to collect properties from various sources.
  2366. abstract class GetPropertyCallback
  2367. {
  2368. abstract public String get(String name);
  2369. }