1. /*
  2. * @(#)NamingContextImpl.java 1.15 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. * @(#)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.internal.PCosNaming;
  23. import org.omg.CORBA.Object;
  24. import org.omg.CORBA.SystemException;
  25. import org.omg.CORBA.INTERNAL;
  26. import org.omg.CORBA.BAD_PARAM;
  27. import org.omg.CORBA.UNKNOWN;
  28. import org.omg.CORBA.CompletionStatus;
  29. import org.omg.CORBA.Policy;
  30. import org.omg.PortableServer.POA;
  31. import org.omg.PortableServer.LifespanPolicyValue;
  32. import org.omg.PortableServer.RequestProcessingPolicyValue;
  33. import org.omg.PortableServer.IdAssignmentPolicyValue;
  34. import org.omg.PortableServer.ServantRetentionPolicyValue;
  35. import org.omg.CosNaming.*;
  36. import org.omg.CosNaming.NamingContextPackage.*;
  37. import org.omg.CosNaming.NamingContextExtPackage.*;
  38. import com.sun.corba.se.internal.CosNaming.NamingContextDataStore;
  39. import com.sun.corba.se.internal.CosNaming.MinorCodes;
  40. import com.sun.corba.se.internal.CosNaming.NamingUtils;
  41. import com.sun.corba.se.internal.POA.POAORB;
  42. import com.sun.corba.se.internal.corba.CorbaName;
  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 POAORB 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.internal.CosNaming.InterOperableNamingImpl insImpl;
  86. private static POA biPOA = null;
  87. /**
  88. * Create a naming context servant.
  89. * Runs the super constructor.
  90. * @param orb an ORB object.
  91. * @param objKey as String
  92. * @param TheNameService as NameService
  93. * @param TheServantManagerImpl as ServantManagerImpl
  94. * @exception java.lang.Exception a Java exception.
  95. */
  96. public NamingContextImpl(POAORB orb, String objKey,
  97. NameService theNameService, ServantManagerImpl theServantManagerImpl )
  98. throws Exception
  99. {
  100. super();
  101. this.orb = orb;
  102. this.objKey = objKey;
  103. theNameServiceHandle = theNameService;
  104. theServantManagerImplHandle = theServantManagerImpl;
  105. insImpl =
  106. new com.sun.corba.se.internal.CosNaming.InterOperableNamingImpl();
  107. }
  108. com.sun.corba.se.internal.CosNaming.InterOperableNamingImpl getINSImpl( )
  109. {
  110. if( insImpl == null )
  111. {
  112. // insImpl will be null if the NamingContext graph is rebuilt from
  113. // the persistence store.
  114. insImpl =
  115. new com.sun.corba.se.internal.CosNaming.InterOperableNamingImpl();
  116. }
  117. return insImpl;
  118. }
  119. public void setRootNameService( NameService theNameService ) {
  120. theNameServiceHandle = theNameService;
  121. }
  122. public void setORB( POAORB theOrb ) {
  123. orb = theOrb;
  124. }
  125. public void setServantManagerImpl(
  126. ServantManagerImpl theServantManagerImpl )
  127. {
  128. theServantManagerImplHandle = theServantManagerImpl;
  129. }
  130. public POA getNSPOA( ) {
  131. return theNameServiceHandle.getNSPOA( );
  132. }
  133. /**
  134. * Bind an object under a name in this NamingContext. If the name
  135. * contains multiple (n) components, n-1 will be resolved in this
  136. * NamingContext and the object bound in resulting NamingContext.
  137. * An exception is thrown if a binding with the supplied name already
  138. * exists. If the
  139. * object to be bound is a NamingContext it will not participate in
  140. * a recursive resolve.
  141. * @param n a sequence of NameComponents which is the name under which
  142. * the object will be bound.
  143. * @param obj the object reference to be bound.
  144. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  145. * components was supplied, but the first component could not be
  146. * resolved.
  147. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  148. * in resolving the n-1 components of the supplied name.
  149. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  150. * is invalid (i.e., has length less than 1).
  151. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound The supplied name
  152. * is already bound.
  153. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  154. * @see doBind
  155. */
  156. public void bind(NameComponent[] n, org.omg.CORBA.Object obj)
  157. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  158. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  159. org.omg.CosNaming.NamingContextPackage.InvalidName,
  160. org.omg.CosNaming.NamingContextPackage.AlreadyBound
  161. {
  162. if( obj == null )
  163. {
  164. throw new org.omg.CORBA.INTERNAL(MinorCodes.OBJECT_IS_NULL,
  165. CompletionStatus.COMPLETED_NO);
  166. }
  167. if (debug)
  168. dprint("bind " + nameToString(n) + " to " + obj);
  169. // doBind implements all four flavors of binding
  170. NamingContextDataStore impl = (NamingContextDataStore)this;
  171. doBind(impl,n,obj,false,BindingType.nobject);
  172. }
  173. /**
  174. * Bind a NamingContext under a name in this NamingContext. If the name
  175. * contains multiple (n) components, n-1 will be resolved in this
  176. * NamingContext and the object bound in resulting NamingContext.
  177. * An exception is thrown if a binding with the supplied name already
  178. * exists. The NamingContext will participate in recursive resolving.
  179. * @param n a sequence of NameComponents which is the name under which
  180. * the object will be bound.
  181. * @param obj the NamingContect object reference to be bound.
  182. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  183. * components was supplied, but the first component could not be
  184. * resolved.
  185. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  186. * in resolving the n-1 components of the supplied name.
  187. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  188. * is invalid (i.e., has length less than 1).
  189. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
  190. * already bound under the supplied name.
  191. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  192. * @see doBind
  193. */
  194. public void bind_context(NameComponent[] n, NamingContext nc)
  195. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  196. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  197. org.omg.CosNaming.NamingContextPackage.InvalidName,
  198. org.omg.CosNaming.NamingContextPackage.AlreadyBound
  199. {
  200. if( nc == null ) {
  201. throw new BAD_PARAM( "Naming Context should not be null " );
  202. }
  203. // doBind implements all four flavors of binding
  204. NamingContextDataStore impl = (NamingContextDataStore)this;
  205. doBind(impl,n,nc,false,BindingType.ncontext);
  206. }
  207. /**
  208. * Bind an object under a name in this NamingContext. If the name
  209. * contains multiple (n) components, n-1 will be resolved in this
  210. * NamingContext and the object bound in resulting NamingContext.
  211. * If a binding under the supplied name already exists it will be
  212. * unbound first. If the
  213. * object to be bound is a NamingContext it will not participate in
  214. * a recursive resolve.
  215. * @param n a sequence of NameComponents which is the name under which
  216. * the object will be bound.
  217. * @param obj the object reference to be bound.
  218. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  219. * components was supplied, but the first component could not be
  220. * resolved.
  221. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  222. * in resolving the n-1 components of the supplied name.
  223. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  224. * is invalid (i.e., has length less than 1).
  225. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  226. * @see doBind
  227. */
  228. public void rebind(NameComponent[] n, org.omg.CORBA.Object obj)
  229. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  230. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  231. org.omg.CosNaming.NamingContextPackage.InvalidName
  232. {
  233. if( obj == null )
  234. {
  235. throw new org.omg.CORBA.INTERNAL(MinorCodes.OBJECT_IS_NULL,
  236. CompletionStatus.COMPLETED_NO);
  237. }
  238. try {
  239. if (debug)
  240. dprint("rebind " + nameToString(n) + " to " + obj);
  241. // doBind implements all four flavors of binding
  242. NamingContextDataStore impl = (NamingContextDataStore)this;
  243. doBind(impl,n,obj,true,BindingType.nobject);
  244. } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
  245. // This should not happen
  246. throw new org.omg.CORBA.INTERNAL(
  247. MinorCodes.NAMING_CTX_REBIND_ALREADY_BOUND,
  248. CompletionStatus.COMPLETED_NO);
  249. }
  250. }
  251. /**
  252. * Bind a NamingContext under a name in this NamingContext. If the name
  253. * contains multiple (n) components, the first n-1 components will be
  254. * resolved in this
  255. * NamingContext and the object bound in resulting NamingContext.
  256. * If a binding under the supplied name already exists it will be
  257. * unbound first. The NamingContext will participate in recursive resolving.
  258. * @param n a sequence of NameComponents which is the name under which
  259. * the object will be bound.
  260. * @param obj the object reference to be bound.
  261. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  262. * components was supplied, but the first component could not be
  263. * resolved.
  264. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  265. * in resolving the n-1 components of the supplied name.
  266. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  267. * is invalid (i.e., has length less than 1).
  268. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  269. * @see doBind
  270. */
  271. public void rebind_context(NameComponent[] n, NamingContext nc)
  272. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  273. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  274. org.omg.CosNaming.NamingContextPackage.InvalidName
  275. {
  276. try {
  277. if (debug)
  278. dprint("rebind_context " + nameToString(n) + " to " + nc);
  279. // doBind implements all four flavors of binding
  280. NamingContextDataStore impl = (NamingContextDataStore)this;
  281. doBind(impl,n,nc,true,BindingType.ncontext);
  282. } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
  283. // This should not happen
  284. throw new org.omg.CORBA.INTERNAL(
  285. MinorCodes.NAMING_CTX_REBINDCTX_ALREADY_BOUND,
  286. CompletionStatus.COMPLETED_NO);
  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. public static 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. // "Resistence is futile." [Borg pickup line]
  535. throw new org.omg.CosNaming.NamingContextPackage.AlreadyBound();
  536. }
  537. // Now there are no other bindings under this name
  538. impl.Bind(n[0],obj,bt);
  539. }
  540. } else {
  541. // No: bind in a different context
  542. NamingContext context = resolveFirstAsContext(impl,n);
  543. // Compute tail
  544. NameComponent[] tail = new NameComponent[n.length - 1];
  545. System.arraycopy(n,1,tail,0,n.length-1);
  546. // How should we propagate the bind
  547. switch (bt.value()) {
  548. case BindingType._nobject:
  549. {
  550. // Bind as object
  551. if (rebind)
  552. context.rebind(tail,obj);
  553. else
  554. context.bind(tail,obj);
  555. }
  556. break;
  557. case BindingType._ncontext:
  558. {
  559. // Narrow to a naming context using Java casts. It must work.
  560. NamingContext objContext = (NamingContext)obj;
  561. // Bind as context
  562. if (rebind)
  563. context.rebind_context(tail,objContext);
  564. else
  565. context.bind_context(tail,objContext);
  566. }
  567. break;
  568. default:
  569. // This should not happen
  570. throw new org.omg.CORBA.INTERNAL(MinorCodes.NAMING_CTX_BAD_BINDINGTYPE,
  571. CompletionStatus.COMPLETED_NO);
  572. }
  573. }
  574. }
  575. /**
  576. * Implements resolving names in this NamingContext. The first component
  577. * of the supplied name is resolved in this NamingContext by calling
  578. * Resolve(). If there are no more components in the name, the
  579. * resulting object reference is returned. Otherwise, the resulting object
  580. * reference must have been bound as a context and be narrowable to
  581. * a NamingContext. If this is the case, the remaining
  582. * components of the name is resolved in the resulting NamingContext.
  583. * This method is static for maximal reuse - even for extended naming
  584. * context implementations where the recursive semantics still apply.
  585. * @param impl an implementation of NamingContextDataStore
  586. * @param n a sequence of NameComponents which is the name to be resolved.
  587. * @return the object reference bound under the supplied name.
  588. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  589. * components was supplied, but the first component could not be
  590. * resolved.
  591. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  592. * in resolving the first component of the supplied name.
  593. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  594. * is invalid (i.e., has length less than 1).
  595. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  596. * @see resolve
  597. */
  598. public static org.omg.CORBA.Object doResolve(NamingContextDataStore impl,
  599. NameComponent[] n)
  600. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  601. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  602. org.omg.CosNaming.NamingContextPackage.InvalidName
  603. {
  604. org.omg.CORBA.Object obj = null;
  605. BindingTypeHolder bth = new BindingTypeHolder();
  606. // Length must be greater than 0
  607. if (n.length < 1)
  608. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  609. // The identifier must be set
  610. if (n.length == 1) {
  611. synchronized (impl) {
  612. // Resolve first level in this context
  613. obj = impl.Resolve(n[0],bth);
  614. }
  615. if (obj == null) {
  616. // Object was not found
  617. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  618. }
  619. return obj;
  620. } else {
  621. // n.length > 1
  622. if ( (n[1].id.length() == 0) && (n[1].kind.length() == 0 ) )
  623. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  624. NamingContext context = resolveFirstAsContext(impl,n);
  625. // Compute restOfName = name[1..length]
  626. NameComponent[] tail = new NameComponent[n.length -1];
  627. System.arraycopy(n,1,tail,0,n.length-1);
  628. // Resolve rest of name in context
  629. return context.resolve(tail);
  630. }
  631. }
  632. /**
  633. * Implements unbinding bound names in this NamingContext. If the
  634. * name contains only one component, the name is unbound in this
  635. * NamingContext using Unbind(). Otherwise, the first component
  636. * of the name is resolved in this NamingContext and
  637. * unbind passed to the resulting NamingContext.
  638. * This method is static for maximal reuse - even for extended naming
  639. * context implementations where the recursive semantics still apply.
  640. * @param impl an implementation of NamingContextDataStore
  641. * @param n a sequence of NameComponents which is the name to be unbound.
  642. * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
  643. * components was supplied, but the first component could not be
  644. * resolved.
  645. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  646. * in resolving the n-1 components of the supplied name.
  647. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  648. * is invalid (i.e., has length less than 1).
  649. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  650. * @see resolve
  651. */
  652. public static void doUnbind(NamingContextDataStore impl,
  653. NameComponent[] n)
  654. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  655. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  656. org.omg.CosNaming.NamingContextPackage.InvalidName
  657. {
  658. // Name valid?
  659. if (n.length < 1)
  660. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  661. // Unbind here?
  662. if (n.length == 1) {
  663. // The identifier must be set
  664. if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) )
  665. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  666. org.omg.CORBA.Object objRef = null;
  667. synchronized (impl) {
  668. // Yes: unbind in this context
  669. objRef = impl.Unbind(n[0]);
  670. }
  671. if (objRef == null)
  672. // It was not bound
  673. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  674. // Done
  675. return;
  676. } else {
  677. // No: unbind in a different context
  678. // Resolve first - must be resolveable
  679. NamingContext context = resolveFirstAsContext(impl,n);
  680. // Compute tail
  681. NameComponent[] tail = new NameComponent[n.length - 1];
  682. System.arraycopy(n,1,tail,0,n.length-1);
  683. // Propagate unbind to this context
  684. context.unbind(tail);
  685. }
  686. }
  687. /**
  688. * Implements resolving a NameComponent in this context and
  689. * narrowing it to CosNaming::NamingContext. It will throw appropriate
  690. * exceptions if not found or not narrowable.
  691. * @param impl an implementation of NamingContextDataStore
  692. * @param n a NameComponents which is the name to be found.
  693. * @exception org.omg.CosNaming.NamingContextPackage.NotFound The
  694. * first component could not be resolved.
  695. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  696. * in resolving the first component of the supplied name.
  697. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  698. * @see resolve
  699. */
  700. protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl,
  701. NameComponent[] n)
  702. throws org.omg.CosNaming.NamingContextPackage.NotFound {
  703. org.omg.CORBA.Object topRef = null;
  704. BindingTypeHolder bth = new BindingTypeHolder();
  705. NamingContext context = null;
  706. synchronized (impl) {
  707. // Resolve first - must be resolveable
  708. topRef = impl.Resolve(n[0],bth);
  709. if (topRef == null) {
  710. // It was not bound
  711. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
  712. }
  713. }
  714. // Was it bound as a context?
  715. if (bth.value != BindingType.ncontext) {
  716. // It was not a context
  717. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
  718. }
  719. // Narrow to a naming context
  720. try {
  721. context = NamingContextHelper.narrow(topRef);
  722. } catch (org.omg.CORBA.BAD_PARAM ex) {
  723. // It was not a context
  724. throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
  725. }
  726. // Hmm. must be ok
  727. return context;
  728. }
  729. public static String nameToString(NameComponent[] name)
  730. {
  731. StringBuffer s = new StringBuffer("{");
  732. if (name != null || name.length > 0) {
  733. for (int i=0;i<name.length;i++) {
  734. if (i>0)
  735. s.append(",");
  736. s.append("[").
  737. append(name[i].id).
  738. append(",").
  739. append(name[i].kind).
  740. append("]");
  741. }
  742. }
  743. s.append("}");
  744. return s.toString();
  745. }
  746. // Debugging aids.
  747. public static final boolean debug = false;
  748. private static void dprint(String msg) {
  749. NamingUtils.dprint("NamingContextImpl(" +
  750. Thread.currentThread().getName() + " at " +
  751. System.currentTimeMillis() +
  752. " ems): " + msg);
  753. }
  754. /**
  755. * Implements all flavors of binding( bind and bindcontext)
  756. * This method will be called from the superclass's doBind( ) method
  757. * which takes care of all the conditions before calling this method.
  758. * i.e., It checks whether the Name is already Bounded, Then in the
  759. * case of rebind it calls Unbind first.
  760. * This method does one level binding only, To have n-level binding
  761. * with compound names, doBind( ) calls this method recursively.
  762. * @param n a sequence of NameComponents which is the name under which
  763. * the object will be bound.
  764. * @param obj the object reference to be bound.
  765. * @param bt Type of binding (as object or as context).
  766. * @exception org.omg.CosNaming.NamingContextPackage.NotFound raised
  767. * if the NameComoponent list is invalid
  768. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
  769. * Could not proceed in resolving the Name from the given NameComponent
  770. * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object
  771. * is already bound under the supplied name.
  772. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
  773. * system exceptions
  774. * @see Resolve
  775. * @see Unbind
  776. */
  777. public void Bind(NameComponent n, org.omg.CORBA.Object obj, BindingType bt)
  778. throws SystemException
  779. {
  780. if( obj == null )
  781. {
  782. // Raise a Valid Exception and Return
  783. return;
  784. }
  785. InternalBindingKey key = new InternalBindingKey(n);
  786. InternalBindingValue value;
  787. try
  788. {
  789. if( bt.value() == BindingType._nobject )
  790. {
  791. // If the BindingType is an ObjectRef then Stringify this ref and
  792. // Store it in InternalBindingValue instance. This is required
  793. // because the Object References has to be stored in file
  794. value = new InternalBindingValue(bt,
  795. orb.object_to_string(obj) );
  796. value.setObjectRef( obj );
  797. }
  798. else
  799. {
  800. // If the BindingType is a NamingContext then get it's object key
  801. // from the NameService and store it in the Internal Binding Value instance
  802. String theNCKey = theNameServiceHandle.getObjectKey(
  803. obj );
  804. value = new InternalBindingValue( bt,
  805. theNCKey );
  806. value.setObjectRef( obj );
  807. }
  808. InternalBindingValue oldValue =
  809. (InternalBindingValue)this.theHashtable.put(key,value);
  810. if( oldValue != null)
  811. {
  812. // There was an entry with this name in the Hashtable and hence throw CTX_ALREADY_BOUND
  813. // exception
  814. throw new org.omg.CORBA.INTERNAL(
  815. MinorCodes.NAMING_CTX_REBIND_ALREADY_BOUND,
  816. CompletionStatus.COMPLETED_NO);
  817. }
  818. else
  819. {
  820. try
  821. {
  822. // Everything went smooth so update the NamingContext file with the
  823. // latest Hashtable image
  824. theServantManagerImplHandle.updateContext( objKey,
  825. this );
  826. }
  827. catch( Exception e )
  828. {
  829. // Something went wrong while updating the context
  830. // so speak the error
  831. throw new org.omg.CORBA.UNKNOWN(
  832. (int) 3, // Replace this with a valid constant
  833. CompletionStatus.COMPLETED_MAYBE );
  834. }
  835. }
  836. }
  837. catch( Exception e )
  838. {
  839. // Something went wrong while Binding the Object Reference
  840. // Speak the error again.
  841. throw new org.omg.CORBA.UNKNOWN(
  842. 3, // Replace this with a valid constant
  843. CompletionStatus.COMPLETED_MAYBE );
  844. }
  845. }
  846. /**
  847. * This method resolves the NamingContext or Object Reference for one level
  848. * The doResolve( ) method calls Resolve( ) recursively to resolve n level
  849. * Names.
  850. * @param n a sequence of NameComponents which is the name to be resolved.
  851. * @param bt Type of binding (as object or as context).
  852. * @return the object reference bound under the supplied name.
  853. * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
  854. * or a Corba Object reference not found under this Name
  855. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  856. * in resolving the the supplied name.
  857. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  858. * is invalid (i.e., has length less than 1).
  859. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  860. * @see Bind
  861. */
  862. public Object Resolve(NameComponent n, BindingTypeHolder bth)
  863. throws SystemException
  864. {
  865. if( ( n.id.length() == 0 )
  866. &&( n.kind.length() == 0 ) )
  867. {
  868. // If the NameComponent list has no entry then it means the current
  869. // context was requested
  870. bth.value = BindingType.ncontext;
  871. return theNameServiceHandle.getObjectReferenceFromKey(
  872. this.objKey );
  873. }
  874. InternalBindingKey key = new InternalBindingKey(n);
  875. InternalBindingValue value =
  876. (InternalBindingValue) this.theHashtable.get(key);
  877. if( value == null )
  878. {
  879. // No entry was found for the given name and hence return NULL
  880. // NamingContextDataStore throws appropriate exception if
  881. // required.
  882. return null;
  883. }
  884. Object theObjectFromStringifiedReference = null;
  885. bth.value = value.theBindingType;
  886. try
  887. {
  888. // Check whether the entry found in the Hashtable starts with NC
  889. // Which means it's a name context. So get the NamingContext reference
  890. // from ServantManager, which would either return from the cache or
  891. // read it from the File.
  892. if( value.strObjectRef.startsWith( "NC" ) )
  893. {
  894. bth.value = BindingType.ncontext;
  895. return theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
  896. }
  897. else
  898. {
  899. // Else, It is a Object Reference. Check whether Object Reference
  900. // can be obtained directly, If not then convert the stringified
  901. // reference to object and return.
  902. theObjectFromStringifiedReference = value.getObjectRef( );
  903. if( theObjectFromStringifiedReference == null )
  904. {
  905. try
  906. {
  907. theObjectFromStringifiedReference =
  908. orb.string_to_object( value.strObjectRef );
  909. value.setObjectRef( theObjectFromStringifiedReference );
  910. }
  911. catch( Exception e )
  912. {
  913. // Throw Invalid Reference Exception
  914. throw new org.omg.CORBA.UNKNOWN(
  915. 3, // Replace this with a valid constant
  916. CompletionStatus.COMPLETED_MAYBE );
  917. }
  918. }
  919. }
  920. }
  921. catch ( Exception e )
  922. {
  923. // Something wrong happened while resolving the given NameComponent,
  924. // So, Speak the UNKNOWN error
  925. throw new org.omg.CORBA.UNKNOWN(
  926. 3, // Replace this with a valid constant
  927. CompletionStatus.COMPLETED_MAYBE );
  928. }
  929. return theObjectFromStringifiedReference;
  930. }
  931. /**
  932. * This method Unbinds the NamingContext or Object Reference for one level
  933. * The doUnbind( ) method from superclass calls Unbind() to recursively
  934. * Unbind using compound Names.
  935. * @param n a sequence of NameComponents which is the name to be resolved.
  936. * @return the object reference bound under the supplied name.
  937. * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
  938. * or a Corba Object reference not found under this Name
  939. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
  940. * in resolving the the supplied name.
  941. * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
  942. * is invalid (i.e., has length less than 1).
  943. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  944. * @see Bind
  945. */
  946. public Object Unbind(NameComponent n) throws SystemException
  947. {
  948. try
  949. {
  950. InternalBindingKey key = new InternalBindingKey(n);
  951. InternalBindingValue value = null;
  952. try
  953. {
  954. value = (InternalBindingValue) this.theHashtable.remove(key);
  955. }
  956. catch( Exception e )
  957. {
  958. // Ignore the exception in Hashtable.remove
  959. }
  960. theServantManagerImplHandle.updateContext( objKey,
  961. this );
  962. if( value == null )
  963. {
  964. return null;
  965. }
  966. if( value.strObjectRef.startsWith( "NC" ) )
  967. {
  968. theServantManagerImplHandle.readInContext( value.strObjectRef );
  969. Object theObjectFromStringfiedReference =
  970. theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
  971. return theObjectFromStringfiedReference;
  972. }
  973. else
  974. {
  975. Object theObjectFromStringifiedReference = value.getObjectRef( );
  976. if( theObjectFromStringifiedReference == null )
  977. {
  978. theObjectFromStringifiedReference =
  979. orb.string_to_object( value.strObjectRef );
  980. }
  981. return theObjectFromStringifiedReference;
  982. }
  983. }
  984. catch( Exception e )
  985. {
  986. // Add a new Minor code for Unbind exception
  987. throw new org.omg.CORBA.UNKNOWN(
  988. 3, // Replace this with a valid constant
  989. CompletionStatus.COMPLETED_MAYBE );
  990. }
  991. }
  992. /**
  993. * List the contents of this NamingContext. It creates a new
  994. * PersistentBindingIterator object and passes it a clone of the
  995. * hash table and an orb object. It then uses the
  996. * newly created object to return the required number of bindings.
  997. * @param how_many The number of requested bindings in the BindingList.
  998. * @param bl The BindingList as an out parameter.
  999. * @param bi The BindingIterator as an out parameter.
  1000. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  1001. */
  1002. public void List(int how_many, BindingListHolder bl,
  1003. BindingIteratorHolder bi) throws SystemException
  1004. {
  1005. if( biPOA == null ) {
  1006. createbiPOA( );
  1007. }
  1008. try {
  1009. PersistentBindingIterator bindingIterator =
  1010. new PersistentBindingIterator(this.orb,
  1011. (Hashtable)this.theHashtable.clone(), biPOA);
  1012. // Have it set the binding list
  1013. bindingIterator.list(how_many,bl);
  1014. byte[] objectId = biPOA.activate_object( bindingIterator );
  1015. org.omg.CORBA.Object obj = biPOA.id_to_reference( objectId );
  1016. // Get the object reference for the binding iterator servant
  1017. org.omg.CosNaming.BindingIterator bindingRef =
  1018. org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
  1019. bi.value = bindingRef;
  1020. } catch (org.omg.CORBA.SystemException e) {
  1021. throw e;
  1022. } catch( Exception e ) {
  1023. throw new org.omg.CORBA.INTERNAL(MinorCodes.TRANS_NC_LIST_GOT_EXC,
  1024. CompletionStatus.COMPLETED_NO);
  1025. }
  1026. }
  1027. private synchronized void createbiPOA( ) {
  1028. if( biPOA != null ) {
  1029. return;
  1030. }
  1031. try {
  1032. POA rootPOA = (POA) orb.resolve_initial_references("RootPOA");
  1033. rootPOA.the_POAManager().activate( );
  1034. int i = 0;
  1035. Policy[] poaPolicy = new Policy[3];
  1036. poaPolicy[i++] = rootPOA.create_lifespan_policy(
  1037. LifespanPolicyValue.TRANSIENT);
  1038. poaPolicy[i++] = rootPOA.create_id_assignment_policy(
  1039. IdAssignmentPolicyValue.SYSTEM_ID);
  1040. poaPolicy[i++] = rootPOA.create_servant_retention_policy(
  1041. ServantRetentionPolicyValue.RETAIN);
  1042. biPOA = rootPOA.create_POA("BindingIteratorPOA", null, poaPolicy );
  1043. biPOA.the_POAManager().activate( );
  1044. } catch( Exception e ) {
  1045. throw new INTERNAL("Exception While Creating Binding Iterator POA");
  1046. }
  1047. }
  1048. /**
  1049. * Create a NamingContext object and return its object reference.
  1050. * @return an object reference for a new NamingContext object implemented
  1051. * by this Name Server.
  1052. * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
  1053. */
  1054. public NamingContext NewContext() throws SystemException
  1055. {
  1056. try
  1057. {
  1058. return theNameServiceHandle.NewContext( );
  1059. }
  1060. catch( org.omg.CORBA.SystemException e )
  1061. {
  1062. throw e;
  1063. }
  1064. catch( Exception e )
  1065. {
  1066. throw new org.omg.CORBA.INTERNAL(
  1067. MinorCodes.TRANS_NC_NEWCTX_GOT_EXC,
  1068. CompletionStatus.COMPLETED_NO);
  1069. }
  1070. }
  1071. /**
  1072. * Destroys the NamingContext.
  1073. */
  1074. public void Destroy() throws SystemException
  1075. {
  1076. // XXX note that orb.disconnect is illegal here, since the
  1077. // POA is used. However, there may be some associated state
  1078. // that needs to be cleaned up in ServerManagerImpl which we will
  1079. // look into further at another time.
  1080. /*
  1081. try
  1082. {
  1083. orb.disconnect(
  1084. theNameServiceHandle.getObjectReferenceFromKey( this.objKey ) );
  1085. }
  1086. catch( org.omg.CORBA.SystemException e )
  1087. {
  1088. throw e;
  1089. }
  1090. catch( Exception e )
  1091. {
  1092. //throw new org.omg.CORBA.INTERNAL(
  1093. //MinorCodes.TRANS_NC_DESTROY_GOT_EX,
  1094. //CompletionStatus.COMPLETED_NO );
  1095. }
  1096. */
  1097. }
  1098. /**
  1099. * This operation creates a stringified name from the array of Name
  1100. * components.
  1101. * @param n Name of the object <p>
  1102. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1103. * Indicates the name does not identify a binding.<p>
  1104. *
  1105. */
  1106. public String to_string(org.omg.CosNaming.NameComponent[] n)
  1107. throws org.omg.CosNaming.NamingContextPackage.InvalidName
  1108. {
  1109. // Name valid?
  1110. if ( (n == null ) || (n.length == 0) )
  1111. {
  1112. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1113. }
  1114. String theStringifiedName = getINSImpl().convertToString( n );
  1115. if( theStringifiedName == null )
  1116. {
  1117. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1118. }
  1119. return theStringifiedName;
  1120. }
  1121. /**
  1122. * This operation converts a Stringified Name into an equivalent array
  1123. * of Name Components.
  1124. * @param sn Stringified Name of the object <p>
  1125. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1126. * Indicates the name does not identify a binding.<p>
  1127. *
  1128. */
  1129. public org.omg.CosNaming.NameComponent[] to_name(String sn)
  1130. throws org.omg.CosNaming.NamingContextPackage.InvalidName
  1131. {
  1132. // Name valid?
  1133. if ( (sn == null ) || (sn.length() == 0) )
  1134. {
  1135. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1136. }
  1137. org.omg.CosNaming.NameComponent[] theNameComponents =
  1138. getINSImpl().convertToNameComponent( sn );
  1139. if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
  1140. {
  1141. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1142. }
  1143. for( int i = 0; i < theNameComponents.length; i++ ) {
  1144. // If there is a name component whose id and kind null or
  1145. // zero length string, then an invalid name exception needs to be
  1146. // raised.
  1147. if ( ( ( theNameComponents[i].id == null )
  1148. ||( theNameComponents[i].id.length() == 0 ) )
  1149. &&( ( theNameComponents[i].kind == null )
  1150. ||( theNameComponents[i].kind.length() == 0 ) ) ) {
  1151. throw new InvalidName();
  1152. }
  1153. }
  1154. return theNameComponents;
  1155. }
  1156. /**
  1157. * This operation creates a URL based "iiopname://" format name
  1158. * from the Stringified Name of the object.
  1159. * @param addr internet based address of the host machine where
  1160. * Name Service is running <p>
  1161. * @param sn Stringified Name of the object <p>
  1162. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1163. * Indicates the name does not identify a binding.<p>
  1164. * @exception org.omg.CosNaming.NamingContextPackage.InvalidAddress
  1165. * Indicates the internet based address of the host machine is
  1166. * incorrect <p>
  1167. *
  1168. */
  1169. public String to_url(String addr, String sn)
  1170. throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress,
  1171. org.omg.CosNaming.NamingContextPackage.InvalidName
  1172. {
  1173. // Name valid?
  1174. if ( (sn == null ) || (sn.length() == 0) )
  1175. {
  1176. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1177. }
  1178. if( addr == null )
  1179. {
  1180. throw new org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
  1181. }
  1182. String urlBasedAddress = null;
  1183. try {
  1184. urlBasedAddress = getINSImpl().createURLBasedAddress( addr, sn );
  1185. } catch (Exception e ) {
  1186. urlBasedAddress = null;
  1187. }
  1188. // Extra check to see that corba name url created is valid as per
  1189. // INS spec grammer.
  1190. CorbaName corbaName = null;
  1191. try {
  1192. corbaName = ((com.sun.corba.se.internal.corba.ORB)orb).
  1193. getInitialNamingClient().checkcorbanameGrammer(
  1194. urlBasedAddress );
  1195. } catch( BAD_PARAM e ) {
  1196. throw new
  1197. org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
  1198. }
  1199. if ( corbaName == null ) {
  1200. throw new InvalidName();
  1201. }
  1202. return urlBasedAddress;
  1203. }
  1204. /**
  1205. * This operation resolves the Stringified name into the object
  1206. * reference.
  1207. * @param sn Stringified Name of the object <p>
  1208. * @exception org.omg.CosNaming.NamingContextPackage.NotFound
  1209. * Indicates there is no object reference for the given name. <p>
  1210. * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
  1211. * Indicates that the given compound name is incorrect <p>
  1212. * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
  1213. * Indicates the name does not identify a binding.<p>
  1214. *
  1215. */
  1216. public org.omg.CORBA.Object resolve_str(String sn)
  1217. throws org.omg.CosNaming.NamingContextPackage.NotFound,
  1218. org.omg.CosNaming.NamingContextPackage.CannotProceed,
  1219. org.omg.CosNaming.NamingContextPackage.InvalidName
  1220. {
  1221. org.omg.CORBA.Object theObject = null;
  1222. // Name valid?
  1223. if ( (sn == null ) || (sn.length() == 0) )
  1224. {
  1225. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1226. }
  1227. org.omg.CosNaming.NameComponent[] theNameComponents =
  1228. getINSImpl().convertToNameComponent( sn );
  1229. if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
  1230. {
  1231. throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
  1232. }
  1233. theObject = resolve( theNameComponents );
  1234. return theObject;
  1235. }
  1236. /**
  1237. * This is a Debugging Method
  1238. */
  1239. public boolean IsEmpty()
  1240. {
  1241. return this.theHashtable.isEmpty();
  1242. }
  1243. /**
  1244. * This is a Debugging Method
  1245. */
  1246. public void printSize( )
  1247. {
  1248. System.out.println( "Hashtable Size = " + theHashtable.size( ) );
  1249. java.util.Enumeration e = theHashtable.keys( );
  1250. for( ; e.hasMoreElements(); )
  1251. {
  1252. InternalBindingValue thevalue =
  1253. (InternalBindingValue) this.theHashtable.get(e.nextElement());
  1254. if( thevalue != null )
  1255. {
  1256. System.out.println( "value = " + thevalue.strObjectRef);
  1257. }
  1258. }
  1259. }
  1260. }