1. /*
  2. * @(#)NamingContextImpl.java 1.17 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * @(#)NamingContextImpl.java 1.4 00/02/07
  9. *
  10. * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
  11. * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
  12. *
  13. * This software is the confidential and proprietary information of Sun
  14. * Microsystems, Inc. ("Confidential Information"). You shall not
  15. * disclose such Confidential Information and shall use it only in
  16. * accordance with the terms of the license agreement you entered into
  17. * with Sun.
  18. *
  19. * CopyrightVersion 1.2
  20. *
  21. */
  22. package com.sun.corba.se.impl.naming.pcosnaming;
  23. import org.omg.CORBA.Object;
  24. import org.omg.CORBA.SystemException;
  25. import org.omg.CORBA.BAD_PARAM;
  26. import org.omg.CORBA.CompletionStatus;
  27. import org.omg.CORBA.Policy;
  28. import org.omg.PortableServer.POA;
  29. import org.omg.PortableServer.LifespanPolicyValue;
  30. import org.omg.PortableServer.RequestProcessingPolicyValue;
  31. import org.omg.PortableServer.IdAssignmentPolicyValue;
  32. import org.omg.PortableServer.ServantRetentionPolicyValue;
  33. import org.omg.CosNaming.*;
  34. import org.omg.CosNaming.NamingContextPackage.*;
  35. import org.omg.CosNaming.NamingContextExtPackage.*;
  36. import com.sun.corba.se.impl.naming.cosnaming.NamingContextDataStore;
  37. import com.sun.corba.se.impl.naming.cosnaming.NamingUtils;
  38. import com.sun.corba.se.impl.naming.namingutil.INSURLHandler;
  39. import com.sun.corba.se.spi.orb.ORB;
  40. import com.sun.corba.se.spi.logging.CORBALogDomains;
  41. import com.sun.corba.se.impl.orbutil.ORBConstants;
  42. import com.sun.corba.se.impl.logging.NamingSystemException;
  43. import java.io.Serializable;
  44. import java.util.Hashtable;
  45. /**
  46. * Class NamingContextImpl implements the org.omg.CosNaming::NamingContext and
  47. * NamingContextExt interface.
  48. * <p>
  49. * The operations bind(), rebind(), bind_context() and rebind_context()
  50. * are all really implemented by doBind(). resolve() is really implemented
  51. * by doResolve(), unbind() by doUnbind(). list(), new_context() and
  52. * destroy() uses the NamingContextDataStore interface directly. All the
  53. * doX() methods are public static.
  54. * They synchronize on the NamingContextDataStore object.
  55. * <p>
  56. * None of the methods here are Synchronized because These methods will be
  57. * invoked from Super class's doBind( ), doResolve( ) which are already
  58. * Synchronized.
  59. */
  60. public class NamingContextImpl
  61. extends NamingContextExtPOA
  62. implements NamingContextDataStore, Serializable
  63. {
  64. // The ORB is required to do string_to_object() operations
  65. // All the references are stored in the files in the form of IOR strings
  66. private transient ORB orb;
  67. // The ObjectKey will be in the format NC<Index> which uniquely identifies
  68. // The NamingContext internaly
  69. private final String objKey;
  70. // Hash table contains all the entries in the NamingContexts. The
  71. // CORBA.Object references will be stored in the form of IOR strings
  72. // and the Child Naming Contexts will have it's key as the entry in the
  73. // table. This table is written into File everytime an update is made
  74. // on this context.
  75. private final Hashtable theHashtable = new Hashtable( );
  76. // The NameServiceHandle is required to get the ObjectId from the
  77. // NamingContext's references. These references are created using
  78. // POA in the NameService.
  79. private transient NameService theNameServiceHandle;
  80. // ServantManager is the single point of contact to Read, Write and
  81. // Update the NamingContextFile
  82. private transient ServantManagerImpl theServantManagerImplHandle;
  83. // All the INS (Interoperable Naming Service) methods are defined in this class
  84. // All the calls to INS will be delegated to this class.
  85. private transient com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl insImpl;
  86. private transient NamingSystemException readWrapper ;
  87. private transient NamingSystemException updateWrapper ;
  88. private static POA biPOA = null;
  89. /**
  90. * Create a naming context servant.
  91. * Runs the super constructor.
  92. * @param orb an ORB object.
  93. * @param objKey as String
  94. * @param TheNameService as NameService
  95. * @param TheServantManagerImpl as ServantManagerImpl
  96. * @exception java.lang.Exception a Java exception.
  97. */
  98. public NamingContextImpl(ORB orb, String objKey,
  99. NameService theNameService, ServantManagerImpl theServantManagerImpl )
  100. throws Exception
  101. {
  102. super();
  103. this.orb = orb;
  104. readWrapper = NamingSystemException.get( orb,
  105. CORBALogDomains.NAMING_READ ) ;
  106. updateWrapper = NamingSystemException.get( orb,
  107. CORBALogDomains.NAMING_UPDATE ) ;
  108. debug = true ; // orb.namingDebugFlag ;
  109. this.objKey = objKey;
  110. theNameServiceHandle = theNameService;
  111. theServantManagerImplHandle = theServantManagerImpl;
  112. insImpl =
  113. new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
  114. }
  115. com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl getINSImpl( )
  116. {
  117. if( insImpl == null )
  118. {
  119. // insImpl will be null if the NamingContext graph is rebuilt from
  120. // the persistence store.
  121. insImpl =
  122. new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
  123. }
  124. return insImpl;
  125. }
  126. public void setRootNameService( NameService theNameService ) {
  127. theNameServiceHandle = theNameService;
  128. }
  129. public void setORB( ORB theOrb ) {
  130. orb = theOrb;
  131. }
  132. public void setServantManagerImpl(
  133. ServantManagerImpl theServantManagerImpl )
  134. {
  135. theServantManagerImplHandle = theServantManagerImpl;
  136. }
  137. public POA getNSPOA( ) {
  138. return theNameServiceHandle.getNSPOA( );
  139. }
  140. /**
  141. * Bind an object under a name in this NamingContext. If the name
  142. * contains multiple (n) components, n-1 will be resolved in this
  143. * NamingContext and the object bound in resulting NamingContext.
  144. * An exception is thrown if a binding with the supplied name already
  145. * exists. If the
  146. * object to be bound is a NamingContext it will not participate in
  147. * a recursive resolve.
  148. * @param n a sequence of NameComponents which is the name under which
  149. * the object will be bound.
  150. * @param obj the object reference to be bound.
  151. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  152. * components was supplied, but the first component could not be
  153. * resolved.
  154. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  155. * in resolving the n-1 components of the supplied name.
  156. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  157. * is invalid (i.e., has length less than 1).
  158. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound The supplied name
  159. * is already bound.
  160. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  161. * @see doBind
  162. */
  163. public void bind(NameComponent[] n, org.omg.CORBA.Object obj)
  164. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  165. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  166. org.omg.CosNaming.NamingContextPackage.InvalidName,
  167. org.omg.CosNaming.NamingContextPackage.AlreadyBound
  168. {
  169. if( obj == null ) {
  170. throw updateWrapper.objectIsNull() ;
  171. }
  172. if (debug)
  173. dprint("bind " + nameToString(n) + " to " + obj);
  174. // doBind implements all four flavors of binding
  175. NamingContextDataStore impl = (NamingContextDataStore)this;
  176. doBind(impl,n,obj,false,BindingType.nobject);
  177. }
  178. /**
  179. * Bind a NamingContext under a name in this NamingContext. If the name
  180. * contains multiple (n) components, n-1 will be resolved in this
  181. * NamingContext and the object bound in resulting NamingContext.
  182. * An exception is thrown if a binding with the supplied name already
  183. * exists. The NamingContext will participate in recursive resolving.
  184. * @param n a sequence of NameComponents which is the name under which
  185. * the object will be bound.
  186. * @param obj the NamingContect object reference to be bound.
  187. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  188. * components was supplied, but the first component could not be
  189. * resolved.
  190. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  191. * in resolving the n-1 components of the supplied name.
  192. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  193. * is invalid (i.e., has length less than 1).
  194. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
  195. * already bound under the supplied name.
  196. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  197. * @see doBind
  198. */
  199. public void bind_context(NameComponent[] n, NamingContext nc)
  200. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  201. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  202. org.omg.CosNaming.NamingContextPackage.InvalidName,
  203. org.omg.CosNaming.NamingContextPackage.AlreadyBound
  204. {
  205. if( nc == null ) {
  206. throw updateWrapper.objectIsNull() ;
  207. }
  208. // doBind implements all four flavors of binding
  209. NamingContextDataStore impl = (NamingContextDataStore)this;
  210. doBind(impl,n,nc,false,BindingType.ncontext);
  211. }
  212. /**
  213. * Bind an object under a name in this NamingContext. If the name
  214. * contains multiple (n) components, n-1 will be resolved in this
  215. * NamingContext and the object bound in resulting NamingContext.
  216. * If a binding under the supplied name already exists it will be
  217. * unbound first. If the
  218. * object to be bound is a NamingContext it will not participate in
  219. * a recursive resolve.
  220. * @param n a sequence of NameComponents which is the name under which
  221. * the object will be bound.
  222. * @param obj the object reference to be bound.
  223. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  224. * components was supplied, but the first component could not be
  225. * resolved.
  226. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  227. * in resolving the n-1 components of the supplied name.
  228. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  229. * is invalid (i.e., has length less than 1).
  230. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  231. * @see doBind
  232. */
  233. public void rebind(NameComponent[] n, org.omg.CORBA.Object obj)
  234. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  235. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  236. org.omg.CosNaming.NamingContextPackage.InvalidName
  237. {
  238. if( obj == null )
  239. {
  240. throw updateWrapper.objectIsNull() ;
  241. }
  242. try {
  243. if (debug)
  244. dprint("rebind " + nameToString(n) + " to " + obj);
  245. // doBind implements all four flavors of binding
  246. NamingContextDataStore impl = (NamingContextDataStore)this;
  247. doBind(impl,n,obj,true,BindingType.nobject);
  248. } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
  249. // This should not happen
  250. throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
  251. }
  252. }
  253. /**
  254. * Bind a NamingContext under a name in this NamingContext. If the name
  255. * contains multiple (n) components, the first n-1 components will be
  256. * resolved in this
  257. * NamingContext and the object bound in resulting NamingContext.
  258. * If a binding under the supplied name already exists it will be
  259. * unbound first. The NamingContext will participate in recursive resolving.
  260. * @param n a sequence of NameComponents which is the name under which
  261. * the object will be bound.
  262. * @param obj the object reference to be bound.
  263. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  264. * components was supplied, but the first component could not be
  265. * resolved.
  266. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  267. * in resolving the n-1 components of the supplied name.
  268. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  269. * is invalid (i.e., has length less than 1).
  270. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  271. * @see doBind
  272. */
  273. public void rebind_context(NameComponent[] n, NamingContext nc)
  274. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  275. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  276. org.omg.CosNaming.NamingContextPackage.InvalidName
  277. {
  278. try {
  279. if (debug)
  280. dprint("rebind_context " + nameToString(n) + " to " + nc);
  281. // doBind implements all four flavors of binding
  282. NamingContextDataStore impl = (NamingContextDataStore)this;
  283. doBind(impl,n,nc,true,BindingType.ncontext);
  284. } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
  285. // This should not happen
  286. throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
  287. }
  288. }
  289. /**
  290. * Resolve a name in this NamingContext and return the object reference
  291. * bound to the name. If the name contains multiple (n) components,
  292. * the first component will be resolved in this NamingContext and the
  293. * remaining components resolved in the resulting NamingContext, provided
  294. * that the NamingContext bound to the first component of the name was
  295. * bound with bind_context().
  296. * @param n a sequence of NameComponents which is the name to be resolved.
  297. * @return the object reference bound under the supplied name.
  298. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  299. * components was supplied, but the first component could not be
  300. * resolved.
  301. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  302. * in resolving the n-1 components of the supplied name.
  303. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  304. * is invalid (i.e., has length less than 1).
  305. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  306. * @see doResolve
  307. */
  308. public org.omg.CORBA.Object resolve(NameComponent[] n)
  309. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  310. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  311. org.omg.CosNaming.NamingContextPackage.InvalidName
  312. {
  313. if (debug)
  314. dprint("resolve " + nameToString(n));
  315. // doResolve actually resolves
  316. NamingContextDataStore impl = (NamingContextDataStore)this;
  317. return doResolve(impl,n);
  318. }
  319. /**
  320. * Remove a binding from this NamingContext. If the name contains
  321. * multiple (n) components, the first n-1 components will be resolved
  322. * from this NamingContext and the final component unbound in
  323. * the resulting NamingContext.
  324. * @param n a sequence of NameComponents which is the name to be unbound.
  325. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  326. * components was supplied, but the first component could not be
  327. * resolved.
  328. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  329. * in resolving the n-1 components of the supplied name.
  330. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  331. * is invalid (i.e., has length less than 1).
  332. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  333. * @see doUnbind
  334. */
  335. public void unbind(NameComponent[] n)
  336. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  337. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  338. org.omg.CosNaming.NamingContextPackage.InvalidName
  339. {
  340. if (debug)
  341. dprint("unbind " + nameToString(n));
  342. // doUnbind actually unbinds
  343. NamingContextDataStore impl = (NamingContextDataStore)this;
  344. doUnbind(impl,n);
  345. }
  346. /**
  347. * List the contents of this NamingContest. A sequence of bindings
  348. * is returned (a BindingList) containing up to the number of requested
  349. * bindings, and a BindingIterator object reference is returned for
  350. * iterating over the remaining bindings.
  351. * @param how_many The number of requested bindings in the BindingList.
  352. * @param bl The BindingList as an out parameter.
  353. * @param bi The BindingIterator as an out parameter.
  354. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  355. * @see BindingListHolder
  356. * @see BindingIteratorImpl
  357. */
  358. public void list(int how_many, BindingListHolder bl, BindingIteratorHolder bi)
  359. {
  360. if (debug)
  361. dprint("list(" + how_many + ")");
  362. // List actually generates the list
  363. NamingContextDataStore impl = (NamingContextDataStore)this;
  364. synchronized (impl) {
  365. impl.List(how_many,bl,bi);
  366. }
  367. if (debug && bl.value != null)
  368. dprint("list(" + how_many + ") -> bindings[" + bl.value.length +
  369. "] + iterator: " + bi.value);
  370. }
  371. /**
  372. * Create a NamingContext object and return its object reference.
  373. * @return an object reference for a new NamingContext object implemented
  374. * by this Name Server.
  375. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  376. */
  377. public synchronized NamingContext new_context()
  378. {
  379. // Create actually creates a new naming context
  380. if (debug)
  381. dprint("new_context()");
  382. NamingContextDataStore impl = (NamingContextDataStore)this;
  383. synchronized (impl) {
  384. return impl.NewContext();
  385. }
  386. }
  387. /**
  388. * Create a new NamingContext, bind it in this Naming Context and return
  389. * its object reference. This is equivalent to using new_context() followed
  390. * by bind_context() with the supplied name and the object reference for
  391. * the newly created NamingContext.
  392. * @param n a sequence of NameComponents which is the name to be unbound.
  393. * @return an object reference for a new NamingContext object implemented
  394. * by this Name Server, bound to the supplied name.
  395. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
  396. * already bound under the supplied name.
  397. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  398. * components was supplied, but the first component could not be
  399. * resolved.
  400. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  401. * in resolving the n-1 components of the supplied name.
  402. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  403. * is invalid (i.e., has length less than 1).
  404. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  405. * @see new_context
  406. * @see bind_context
  407. */
  408. public NamingContext bind_new_context(NameComponent[] n)
  409. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  410. org.omg.CosNaming.NamingContextPackage.AlreadyBound,
  411. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  412. org.omg.CosNaming.NamingContextPackage.InvalidName
  413. {
  414. NamingContext nc = null;
  415. NamingContext rnc = null;
  416. try {
  417. if (debug)
  418. dprint("bind_new_context " + nameToString(n));
  419. // The obvious solution:
  420. nc = this.new_context();
  421. this.bind_context(n,nc);
  422. rnc = nc;
  423. nc = null;
  424. } finally {
  425. try {
  426. if(nc != null)
  427. nc.destroy();
  428. } catch (org.omg.CosNaming.NamingContextPackage.NotEmpty e) {
  429. }
  430. }
  431. return rnc;
  432. }
  433. /**
  434. * Destroy this NamingContext object. If this NamingContext contains
  435. * no bindings, the NamingContext is deleted.
  436. * @exception org.omg.CosNaming.NamingContextPackage.NotEmpty This NamingContext
  437. * is not empty (i.e., contains bindings).
  438. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  439. */
  440. public void destroy()
  441. throws org.omg.CosNaming.NamingContextPackage.NotEmpty
  442. {
  443. if (debug)
  444. dprint("destroy ");
  445. NamingContextDataStore impl = (NamingContextDataStore)this;
  446. synchronized (impl) {
  447. if (impl.IsEmpty() == true)
  448. // The context is empty so it can be destroyed
  449. impl.Destroy();
  450. else
  451. // This context is not empty!
  452. throw new org.omg.CosNaming.NamingContextPackage.NotEmpty();
  453. }
  454. }
  455. /**
  456. * Implements all four flavors of binding. It uses Resolve() to
  457. * check if a binding already exists (for bind and bind_context), and
  458. * unbind() to ensure that a binding does not already exist.
  459. * If the length of the name is 1, then Bind() is called with
  460. * the name and the object to bind. Otherwise, the first component
  461. * of the name is resolved in this NamingContext and the appropriate
  462. * form of bind passed to the resulting NamingContext.
  463. * This method is static for maximal reuse - even for extended naming
  464. * context implementations where the recursive semantics still apply.
  465. * @param impl an implementation of NamingContextDataStore
  466. * @param n a sequence of NameComponents which is the name under which
  467. * the object will be bound.
  468. * @param obj the object reference to be bound.
  469. * @param rebind Replace an existing binding or not.
  470. * @param bt Type of binding (as object or as context).
  471. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  472. * components was supplied, but the first component could not be
  473. * resolved.
  474. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  475. * in resolving the first component of the supplied name.
  476. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  477. * is invalid (i.e., has length less than 1).
  478. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
  479. * already bound under the supplied name.
  480. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  481. * @see resolve
  482. * @see unbind
  483. * @see bind
  484. * @see bind_context
  485. * @see rebind
  486. * @see rebind_context
  487. */
  488. private void doBind(NamingContextDataStore impl,
  489. NameComponent[] n,
  490. org.omg.CORBA.Object obj,
  491. boolean rebind,
  492. org.omg.CosNaming.BindingType bt)
  493. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  494. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  495. org.omg.CosNaming.NamingContextPackage.InvalidName,
  496. org.omg.CosNaming.NamingContextPackage.AlreadyBound
  497. {
  498. // Valid name?
  499. if (n.length < 1)
  500. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  501. // At bottom level?
  502. if (n.length == 1) {
  503. // The identifier must be set
  504. if( (n[0].id.length() == 0) && (n[0].kind.length() == 0) )
  505. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  506. // Ensure synchronization of backend
  507. synchronized (impl) {
  508. // Yes: bind object in this context under the name
  509. BindingTypeHolder bth = new BindingTypeHolder();
  510. if (rebind) {
  511. org.omg.CORBA.Object objRef = impl.Resolve( n[0], bth );
  512. if( objRef != null ) {
  513. // Refer Naming Service Doc:00-11-01 section 2.2.3.4
  514. // If there is an object already bound with the name
  515. // and the binding type is not ncontext a NotFound
  516. // Exception with a reason of not a context has to be
  517. // raised.
  518. // Fix for bug Id: 4384628
  519. if ( bth.value.value() == BindingType.nobject.value() ) {
  520. if ( bt.value() == BindingType.ncontext.value() ) {
  521. throw new NotFound(NotFoundReason.not_context, n);
  522. }
  523. } else {
  524. // Previously a Context was bound and now trying to
  525. // bind Object. It is invalid.
  526. if ( bt.value() == BindingType.nobject.value() ) {
  527. throw new NotFound(NotFoundReason.not_object, n);
  528. }
  529. }
  530. impl.Unbind(n[0]);
  531. }
  532. } else {
  533. if (impl.Resolve(n[0],bth) != null)
  534. throw new org.omg.CosNaming.NamingContextPackage.AlreadyBound();
  535. }
  536. // Now there are no other bindings under this name
  537. impl.Bind(n[0],obj,bt);
  538. }
  539. } else {
  540. // No: bind in a different context
  541. NamingContext context = resolveFirstAsContext(impl,n);
  542. // Compute tail
  543. NameComponent[] tail = new NameComponent[n.length - 1];
  544. System.arraycopy(n,1,tail,0,n.length-1);
  545. // How should we propagate the bind
  546. switch (bt.value()) {
  547. case BindingType._nobject:
  548. {
  549. // Bind as object
  550. if (rebind)
  551. context.rebind(tail,obj);
  552. else
  553. context.bind(tail,obj);
  554. }
  555. break;
  556. case BindingType._ncontext:
  557. {
  558. // Narrow to a naming context using Java casts. It must work.
  559. NamingContext objContext = (NamingContext)obj;
  560. // Bind as context
  561. if (rebind)
  562. context.rebind_context(tail,objContext);
  563. else
  564. context.bind_context(tail,objContext);
  565. }
  566. break;
  567. default:
  568. // This should not happen
  569. throw updateWrapper.namingCtxBadBindingtype() ;
  570. }
  571. }
  572. }
  573. /**
  574. * Implements resolving names in this NamingContext. The first component
  575. * of the supplied name is resolved in this NamingContext by calling
  576. * Resolve(). If there are no more components in the name, the
  577. * resulting object reference is returned. Otherwise, the resulting object
  578. * reference must have been bound as a context and be narrowable to
  579. * a NamingContext. If this is the case, the remaining
  580. * components of the name is resolved in the resulting NamingContext.
  581. * This method is static for maximal reuse - even for extended naming
  582. * context implementations where the recursive semantics still apply.
  583. * @param impl an implementation of NamingContextDataStore
  584. * @param n a sequence of NameComponents which is the name to be resolved.
  585. * @return the object reference bound under the supplied name.
  586. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  587. * components was supplied, but the first component could not be
  588. * resolved.
  589. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  590. * in resolving the first component of the supplied name.
  591. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  592. * is invalid (i.e., has length less than 1).
  593. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  594. * @see resolve
  595. */
  596. public static org.omg.CORBA.Object doResolve(NamingContextDataStore impl,
  597. NameComponent[] n)
  598. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  599. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  600. org.omg.CosNaming.NamingContextPackage.InvalidName
  601. {
  602. org.omg.CORBA.Object obj = null;
  603. BindingTypeHolder bth = new BindingTypeHolder();
  604. // Length must be greater than 0
  605. if (n.length < 1)
  606. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  607. // The identifier must be set
  608. if (n.length == 1) {
  609. synchronized (impl) {
  610. // Resolve first level in this context
  611. obj = impl.Resolve(n[0],bth);
  612. }
  613. if (obj == null) {
  614. // Object was not found
  615. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  616. }
  617. return obj;
  618. } else {
  619. // n.length > 1
  620. if ( (n[1].id.length() == 0) && (n[1].kind.length() == 0 ) )
  621. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  622. NamingContext context = resolveFirstAsContext(impl,n);
  623. // Compute restOfName = name[1..length]
  624. NameComponent[] tail = new NameComponent[n.length -1];
  625. System.arraycopy(n,1,tail,0,n.length-1);
  626. // Resolve rest of name in context
  627. return context.resolve(tail);
  628. }
  629. }
  630. /**
  631. * Implements unbinding bound names in this NamingContext. If the
  632. * name contains only one component, the name is unbound in this
  633. * NamingContext using Unbind(). Otherwise, the first component
  634. * of the name is resolved in this NamingContext and
  635. * unbind passed to the resulting NamingContext.
  636. * This method is static for maximal reuse - even for extended naming
  637. * context implementations where the recursive semantics still apply.
  638. * @param impl an implementation of NamingContextDataStore
  639. * @param n a sequence of NameComponents which is the name to be unbound.
  640. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  641. * components was supplied, but the first component could not be
  642. * resolved.
  643. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  644. * in resolving the n-1 components of the supplied name.
  645. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  646. * is invalid (i.e., has length less than 1).
  647. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  648. * @see resolve
  649. */
  650. public static void doUnbind(NamingContextDataStore impl,
  651. NameComponent[] n)
  652. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  653. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  654. org.omg.CosNaming.NamingContextPackage.InvalidName
  655. {
  656. // Name valid?
  657. if (n.length < 1)
  658. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  659. // Unbind here?
  660. if (n.length == 1) {
  661. // The identifier must be set
  662. if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) )
  663. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  664. org.omg.CORBA.Object objRef = null;
  665. synchronized (impl) {
  666. // Yes: unbind in this context
  667. objRef = impl.Unbind(n[0]);
  668. }
  669. if (objRef == null)
  670. // It was not bound
  671. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  672. // Done
  673. return;
  674. } else {
  675. // No: unbind in a different context
  676. // Resolve first - must be resolveable
  677. NamingContext context = resolveFirstAsContext(impl,n);
  678. // Compute tail
  679. NameComponent[] tail = new NameComponent[n.length - 1];
  680. System.arraycopy(n,1,tail,0,n.length-1);
  681. // Propagate unbind to this context
  682. context.unbind(tail);
  683. }
  684. }
  685. /**
  686. * Implements resolving a NameComponent in this context and
  687. * narrowing it to CosNaming::NamingContext. It will throw appropriate
  688. * exceptions if not found or not narrowable.
  689. * @param impl an implementation of NamingContextDataStore
  690. * @param n a NameComponents which is the name to be found.
  691. * @exception org.omg.CosNaming.NamingContextPackage.NotFound The
  692. * first component could not be resolved.
  693. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  694. * in resolving the first component of the supplied name.
  695. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  696. * @see resolve
  697. */
  698. protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl,
  699. NameComponent[] n)
  700. throws org.omg.CosNaming.NamingContextPackage.NotFound {
  701. org.omg.CORBA.Object topRef = null;
  702. BindingTypeHolder bth = new BindingTypeHolder();
  703. NamingContext context = null;
  704. synchronized (impl) {
  705. // Resolve first - must be resolveable
  706. topRef = impl.Resolve(n[0],bth);
  707. if (topRef == null) {
  708. // It was not bound
  709. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  710. }
  711. }
  712. // Was it bound as a context?
  713. if (bth.value != BindingType.ncontext) {
  714. // It was not a context
  715. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
  716. }
  717. // Narrow to a naming context
  718. try {
  719. context = NamingContextHelper.narrow(topRef);
  720. } catch (org.omg.CORBA.BAD_PARAM ex) {
  721. // It was not a context
  722. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
  723. }
  724. // Hmm. must be ok
  725. return context;
  726. }
  727. public static String nameToString(NameComponent[] name)
  728. {
  729. StringBuffer s = new StringBuffer("{");
  730. if (name != null || name.length > 0) {
  731. for (int i=0;i<name.length;i++) {
  732. if (i>0)
  733. s.append(",");
  734. s.append("[").
  735. append(name[i].id).
  736. append(",").
  737. append(name[i].kind).
  738. append("]");
  739. }
  740. }
  741. s.append("}");
  742. return s.toString();
  743. }
  744. // Debugging aids.
  745. private static boolean debug ;
  746. private static void dprint(String msg) {
  747. NamingUtils.dprint("NamingContextImpl(" +
  748. Thread.currentThread().getName() + " at " +
  749. System.currentTimeMillis() +
  750. " ems): " + msg);
  751. }
  752. /**
  753. * Implements all flavors of binding( bind and bindcontext)
  754. * This method will be called from the superclass's doBind( ) method
  755. * which takes care of all the conditions before calling this method.
  756. * i.e., It checks whether the Name is already Bounded, Then in the
  757. * case of rebind it calls Unbind first.
  758. * This method does one level binding only, To have n-level binding
  759. * with compound names, doBind( ) calls this method recursively.
  760. * @param n a sequence of NameComponents which is the name under which
  761. * the object will be bound.
  762. * @param obj the object reference to be bound.
  763. * @param bt Type of binding (as object or as context).
  764. * @exception org.omg.CosNaming.NamingContextPackage.NotFound raised
  765. * if the NameComoponent list is invalid
  766. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
  767. * Could not proceed in resolving the Name from the given NameComponent
  768. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object
  769. * is already bound under the supplied name.
  770. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  771. * system exceptions
  772. * @see Resolve
  773. * @see Unbind
  774. */
  775. public void Bind(NameComponent n, org.omg.CORBA.Object obj, BindingType bt)
  776. {
  777. if( obj == null ) {
  778. // Raise a Valid Exception and Return
  779. return;
  780. }
  781. InternalBindingKey key = new InternalBindingKey(n);
  782. InternalBindingValue value;
  783. try {
  784. if( bt.value() == BindingType._nobject ) {
  785. // If the BindingType is an ObjectRef then Stringify this ref and
  786. // Store it in InternalBindingValue instance. This is required
  787. // because the Object References has to be stored in file
  788. value = new InternalBindingValue(bt, orb.object_to_string(obj) );
  789. value.setObjectRef( obj );
  790. } else {
  791. // If the BindingType is a NamingContext then get it's object key
  792. // from the NameService and store it in the Internal Binding Value instance
  793. String theNCKey = theNameServiceHandle.getObjectKey( obj );
  794. value = new InternalBindingValue( bt, theNCKey );
  795. value.setObjectRef( obj );
  796. }
  797. InternalBindingValue oldValue =
  798. (InternalBindingValue)this.theHashtable.put(key,value);
  799. if( oldValue != null) {
  800. // There was an entry with this name in the Hashtable and hence throw CTX_ALREADY_BOUND
  801. // exception
  802. throw updateWrapper.namingCtxRebindAlreadyBound() ;
  803. } else {
  804. try {
  805. // Everything went smooth so update the NamingContext file with the
  806. // latest Hashtable image
  807. theServantManagerImplHandle.updateContext( objKey, this );
  808. } catch( Exception e ) {
  809. // Something went wrong while updating the context
  810. // so speak the error
  811. throw updateWrapper.bindUpdateContextFailed( e ) ;
  812. }
  813. }
  814. } catch( Exception e ) {
  815. // Something went wrong while Binding the Object Reference
  816. // Speak the error again.
  817. throw updateWrapper.bindFailure( e ) ;
  818. }
  819. }
  820. /**
  821. * This method resolves the NamingContext or Object Reference for one level
  822. * The doResolve( ) method calls Resolve( ) recursively to resolve n level
  823. * Names.
  824. * @param n a sequence of NameComponents which is the name to be resolved.
  825. * @param bt Type of binding (as object or as context).
  826. * @return the object reference bound under the supplied name.
  827. * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
  828. * or a Corba Object reference not found under this Name
  829. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  830. * in resolving the the supplied name.
  831. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  832. * is invalid (i.e., has length less than 1).
  833. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  834. * @see Bind
  835. */
  836. public Object Resolve(NameComponent n, BindingTypeHolder bth)
  837. throws SystemException
  838. {
  839. if( ( n.id.length() == 0 ) &&( n.kind.length() == 0 ) ) {
  840. // If the NameComponent list has no entry then it means the current
  841. // context was requested
  842. bth.value = BindingType.ncontext;
  843. return theNameServiceHandle.getObjectReferenceFromKey(
  844. this.objKey );
  845. }
  846. InternalBindingKey key = new InternalBindingKey(n);
  847. InternalBindingValue value =
  848. (InternalBindingValue) this.theHashtable.get(key);
  849. if( value == null ) {
  850. // No entry was found for the given name and hence return NULL
  851. // NamingContextDataStore throws appropriate exception if
  852. // required.
  853. return null;
  854. }
  855. Object theObjectFromStringifiedReference = null;
  856. bth.value = value.theBindingType;
  857. try {
  858. // Check whether the entry found in the Hashtable starts with NC
  859. // Which means it's a name context. So get the NamingContext reference
  860. // from ServantManager, which would either return from the cache or
  861. // read it from the File.
  862. if( value.strObjectRef.startsWith( "NC" ) ) {
  863. bth.value = BindingType.ncontext;
  864. return theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
  865. } else {
  866. // Else, It is a Object Reference. Check whether Object Reference
  867. // can be obtained directly, If not then convert the stringified
  868. // reference to object and return.
  869. theObjectFromStringifiedReference = value.getObjectRef( );
  870. if (theObjectFromStringifiedReference == null ) {
  871. try {
  872. theObjectFromStringifiedReference =
  873. orb.string_to_object( value.strObjectRef );
  874. value.setObjectRef( theObjectFromStringifiedReference );
  875. } catch( Exception e ) {
  876. throw readWrapper.resolveConversionFailure(
  877. CompletionStatus.COMPLETED_MAYBE, e );
  878. }
  879. }
  880. }
  881. } catch ( Exception e ) {
  882. throw readWrapper.resolveFailure(
  883. CompletionStatus.COMPLETED_MAYBE, e );
  884. }
  885. return theObjectFromStringifiedReference;
  886. }
  887. /**
  888. * This method Unbinds the NamingContext or Object Reference for one level
  889. * The doUnbind( ) method from superclass calls Unbind() to recursively
  890. * Unbind using compound Names.
  891. * @param n a sequence of NameComponents which is the name to be resolved.
  892. * @return the object reference bound under the supplied name.
  893. * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
  894. * or a Corba Object reference not found under this Name
  895. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  896. * in resolving the the supplied name.
  897. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  898. * is invalid (i.e., has length less than 1).
  899. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  900. * @see Bind
  901. */
  902. public Object Unbind(NameComponent n) throws SystemException
  903. {
  904. try {
  905. InternalBindingKey key = new InternalBindingKey(n);
  906. InternalBindingValue value = null;
  907. try {
  908. value = (InternalBindingValue) this.theHashtable.remove(key);
  909. } catch( Exception e ) {
  910. // Ignore the exception in Hashtable.remove
  911. }
  912. theServantManagerImplHandle.updateContext( objKey, this );
  913. if( value == null ) {
  914. return null;
  915. }
  916. if( value.strObjectRef.startsWith( "NC" ) ) {
  917. theServantManagerImplHandle.readInContext( value.strObjectRef );
  918. Object theObjectFromStringfiedReference =
  919. theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
  920. return theObjectFromStringfiedReference;
  921. } else {
  922. Object theObjectFromStringifiedReference = value.getObjectRef( );
  923. if( theObjectFromStringifiedReference == null ) {
  924. theObjectFromStringifiedReference =
  925. orb.string_to_object( value.strObjectRef );
  926. }
  927. return theObjectFromStringifiedReference;
  928. }
  929. } catch( Exception e ) {
  930. throw updateWrapper.unbindFailure( CompletionStatus.COMPLETED_MAYBE, e );
  931. }
  932. }
  933. /**
  934. * List the contents of this NamingContext. It creates a new
  935. * PersistentBindingIterator object and passes it a clone of the
  936. * hash table and an orb object. It then uses the
  937. * newly created object to return the required number of bindings.
  938. * @param how_many The number of requested bindings in the BindingList.
  939. * @param bl The BindingList as an out parameter.
  940. * @param bi The BindingIterator as an out parameter.
  941. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  942. */
  943. public void List(int how_many, BindingListHolder bl,
  944. BindingIteratorHolder bi) throws SystemException
  945. {
  946. if( biPOA == null ) {
  947. createbiPOA( );
  948. }
  949. try {
  950. PersistentBindingIterator bindingIterator =
  951. new PersistentBindingIterator(this.orb,
  952. (Hashtable)this.theHashtable.clone(), biPOA);
  953. // Have it set the binding list
  954. bindingIterator.list(how_many,bl);
  955. byte[] objectId = biPOA.activate_object( bindingIterator );
  956. org.omg.CORBA.Object obj = biPOA.id_to_reference( objectId );
  957. // Get the object reference for the binding iterator servant
  958. org.omg.CosNaming.BindingIterator bindingRef =
  959. org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
  960. bi.value = bindingRef;
  961. } catch (org.omg.CORBA.SystemException e) {
  962. throw e;
  963. } catch( Exception e ) {
  964. throw readWrapper.transNcListGotExc( e ) ;
  965. }
  966. }
  967. private synchronized void createbiPOA( ) {
  968. if( biPOA != null ) {
  969. return;
  970. }
  971. try {
  972. POA rootPOA = (POA) orb.resolve_initial_references(
  973. ORBConstants.ROOT_POA_NAME );
  974. rootPOA.the_POAManager().activate( );
  975. int i = 0;
  976. Policy[] poaPolicy = new Policy[3];
  977. poaPolicy[i++] = rootPOA.create_lifespan_policy(
  978. LifespanPolicyValue.TRANSIENT);
  979. poaPolicy[i++] = rootPOA.create_id_assignment_policy(
  980. IdAssignmentPolicyValue.SYSTEM_ID);
  981. poaPolicy[i++] = rootPOA.create_servant_retention_policy(
  982. ServantRetentionPolicyValue.RETAIN);
  983. biPOA = rootPOA.create_POA("BindingIteratorPOA", null, poaPolicy );
  984. biPOA.the_POAManager().activate( );
  985. } catch( Exception e ) {
  986. throw readWrapper.namingCtxBindingIteratorCreate( e ) ;
  987. }
  988. }
  989. /**
  990. * Create a NamingContext object and return its object reference.
  991. * @return an object reference for a new NamingContext object implemented
  992. * by this Name Server.
  993. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  994. */
  995. public NamingContext NewContext() throws SystemException
  996. {
  997. try {
  998. return theNameServiceHandle.NewContext( );
  999. } catch( org.omg.CORBA.SystemException e ) {
  1000. throw e;
  1001. } catch( Exception e ) {
  1002. throw updateWrapper.transNcNewctxGotExc( e ) ;
  1003. }
  1004. }
  1005. /**
  1006. * Destroys the NamingContext.
  1007. */
  1008. public void Destroy() throws SystemException
  1009. {
  1010. // XXX note that orb.disconnect is illegal here, since the
  1011. // POA is used. However, there may be some associated state
  1012. // that needs to be cleaned up in ServerManagerImpl which we will
  1013. // look into further at another time.
  1014. /*
  1015. // XXX This needs to be replaced by cleaning up the
  1016. // file that backs up the naming context. No explicit
  1017. // action is necessary at the POA level, since this is
  1018. // created with the non-retain policy.
  1019. /*
  1020. try { orb.disconnect(
  1021. theNameServiceHandle.getObjectReferenceFromKey( this.objKey ) );
  1022. } catch( org.omg.CORBA.SystemException e ) {
  1023. throw e;
  1024. } catch( Exception e ) {
  1025. throw updateWrapper.transNcDestroyGotEx( e ) ;
  1026. }
  1027. */
  1028. }
  1029. /**
  1030. * This operation creates a stringified name from the array of Name
  1031. * components.
  1032. * @param n Name of the object <p>
  1033. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1034. * Indicates the name does not identify a binding.<p>
  1035. *
  1036. */
  1037. public String to_string(org.omg.CosNaming.NameComponent[] n)
  1038. throws org.omg.CosNaming.NamingContextPackage.InvalidName
  1039. {
  1040. // Name valid?
  1041. if ( (n == null ) || (n.length == 0) )
  1042. {
  1043. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1044. }
  1045. String theStringifiedName = getINSImpl().convertToString( n );
  1046. if( theStringifiedName == null )
  1047. {
  1048. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1049. }
  1050. return theStringifiedName;
  1051. }
  1052. /**
  1053. * This operation converts a Stringified Name into an equivalent array
  1054. * of Name Components.
  1055. * @param sn Stringified Name of the object <p>
  1056. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1057. * Indicates the name does not identify a binding.<p>
  1058. *
  1059. */
  1060. public org.omg.CosNaming.NameComponent[] to_name(String sn)
  1061. throws org.omg.CosNaming.NamingContextPackage.InvalidName
  1062. {
  1063. // Name valid?
  1064. if ( (sn == null ) || (sn.length() == 0) )
  1065. {
  1066. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1067. }
  1068. org.omg.CosNaming.NameComponent[] theNameComponents =
  1069. getINSImpl().convertToNameComponent( sn );
  1070. if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
  1071. {
  1072. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1073. }
  1074. for( int i = 0; i < theNameComponents.length; i++ ) {
  1075. // If there is a name component whose id and kind null or
  1076. // zero length string, then an invalid name exception needs to be
  1077. // raised.
  1078. if ( ( ( theNameComponents[i].id == null )
  1079. ||( theNameComponents[i].id.length() == 0 ) )
  1080. &&( ( theNameComponents[i].kind == null )
  1081. ||( theNameComponents[i].kind.length() == 0 ) ) ) {
  1082. throw new InvalidName();
  1083. }
  1084. }
  1085. return theNameComponents;
  1086. }
  1087. /**
  1088. * This operation creates a URL based "iiopname://" format name
  1089. * from the Stringified Name of the object.
  1090. * @param addr internet based address of the host machine where
  1091. * Name Service is running <p>
  1092. * @param sn Stringified Name of the object <p>
  1093. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1094. * Indicates the name does not identify a binding.<p>
  1095. * @exception org.omg.CosNaming.NamingContextPackage.InvalidAddress
  1096. * Indicates the internet based address of the host machine is
  1097. * incorrect <p>
  1098. *
  1099. */
  1100. public String to_url(String addr, String sn)
  1101. throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress,
  1102. org.omg.CosNaming.NamingContextPackage.InvalidName
  1103. {
  1104. // Name valid?
  1105. if ( (sn == null ) || (sn.length() == 0) )
  1106. {
  1107. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1108. }
  1109. if( addr == null )
  1110. {
  1111. throw new org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
  1112. }
  1113. String urlBasedAddress = null;
  1114. try {
  1115. urlBasedAddress = getINSImpl().createURLBasedAddress( addr, sn );
  1116. } catch (Exception e ) {
  1117. urlBasedAddress = null;
  1118. }
  1119. // Extra check to see that corba name url created is valid as per
  1120. // INS spec grammer.
  1121. try {
  1122. INSURLHandler.getINSURLHandler().parseURL( urlBasedAddress );
  1123. } catch( BAD_PARAM e ) {
  1124. throw new
  1125. org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
  1126. }
  1127. return urlBasedAddress;
  1128. }
  1129. /**
  1130. * This operation resolves the Stringified name into the object
  1131. * reference.
  1132. * @param sn Stringified Name of the object <p>
  1133. * @exception org.omg.CosNaming.NamingContextPackage.NotFound
  1134. * Indicates there is no object reference for the given name. <p>
  1135. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
  1136. * Indicates that the given compound name is incorrect <p>
  1137. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1138. * Indicates the name does not identify a binding.<p>
  1139. *
  1140. */
  1141. public org.omg.CORBA.Object resolve_str(String sn)
  1142. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  1143. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  1144. org.omg.CosNaming.NamingContextPackage.InvalidName
  1145. {
  1146. org.omg.CORBA.Object theObject = null;
  1147. // Name valid?
  1148. if ( (sn == null ) || (sn.length() == 0) )
  1149. {
  1150. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1151. }
  1152. org.omg.CosNaming.NameComponent[] theNameComponents =
  1153. getINSImpl().convertToNameComponent( sn );
  1154. if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
  1155. {
  1156. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1157. }
  1158. theObject = resolve( theNameComponents );
  1159. return theObject;
  1160. }
  1161. /**
  1162. * This is a Debugging Method
  1163. */
  1164. public boolean IsEmpty()
  1165. {
  1166. return this.theHashtable.isEmpty();
  1167. }
  1168. /**
  1169. * This is a Debugging Method
  1170. */
  1171. public void printSize( )
  1172. {
  1173. System.out.println( "Hashtable Size = " + theHashtable.size( ) );
  1174. java.util.Enumeration e = theHashtable.keys( );
  1175. for( ; e.hasMoreElements(); )
  1176. {
  1177. InternalBindingValue thevalue =
  1178. (InternalBindingValue) this.theHashtable.get(e.nextElement());
  1179. if( thevalue != null )
  1180. {
  1181. System.out.println( "value = " + thevalue.strObjectRef);
  1182. }
  1183. }
  1184. }
  1185. }