GiopNamingServiceURLContext.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /* GiopNamingServiceURLContext.java -- handles corbaname: urls
  2. Copyright (C) 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.javax.naming.giop;
  32. import gnu.CORBA.NamingService.Ext;
  33. import gnu.CORBA.NamingService.NameTransformer;
  34. import java.util.Hashtable;
  35. import javax.naming.Binding;
  36. import javax.naming.Context;
  37. import javax.naming.ContextNotEmptyException;
  38. import javax.naming.InvalidNameException;
  39. import javax.naming.Name;
  40. import javax.naming.NameAlreadyBoundException;
  41. import javax.naming.NameClassPair;
  42. import javax.naming.NameNotFoundException;
  43. import javax.naming.NameParser;
  44. import javax.naming.NamingEnumeration;
  45. import javax.naming.NamingException;
  46. import javax.naming.OperationNotSupportedException;
  47. import javax.naming.directory.InvalidAttributesException;
  48. import org.omg.CORBA.ORB;
  49. import org.omg.CORBA.portable.Delegate;
  50. import org.omg.CORBA.portable.ObjectImpl;
  51. import org.omg.CosNaming.BindingIteratorHolder;
  52. import org.omg.CosNaming.BindingListHolder;
  53. import org.omg.CosNaming.NameComponent;
  54. import org.omg.CosNaming.NamingContext;
  55. import org.omg.CosNaming.NamingContextExt;
  56. import org.omg.CosNaming.NamingContextExtHelper;
  57. import org.omg.CosNaming.NamingContextHelper;
  58. import org.omg.CosNaming._NamingContextExtStub;
  59. import org.omg.CosNaming._NamingContextStub;
  60. import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  61. import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  62. import org.omg.CosNaming.NamingContextPackage.InvalidName;
  63. import org.omg.CosNaming.NamingContextPackage.NotFound;
  64. /**
  65. * The context to represent the corba naming service. Being the naming service,
  66. * the returned context supports creating the subcontexts, forwarding this task
  67. * to the existing naming service. When listing bindings, it uses the
  68. * {@link Context#BATCHSIZE} property to determine, how many bindings should
  69. * be returned at once (the process is transparend)
  70. *
  71. * @author Audrius Meskauskas (audriusa@Bioinformatics.org)
  72. */
  73. public class GiopNamingServiceURLContext extends CorbalocParser implements
  74. Context
  75. {
  76. /**
  77. * This number of bindings will be requested from the naming server at once,
  78. * while the subsequent bindings will be requested via binding iterator one by
  79. * one. Use {@link Context#BATCHSIZE} to override the value of this constant.
  80. */
  81. public int DEFAULT_BATCH_SIZE = 20;
  82. /**
  83. * The object request broker, used to access the naming service. This field
  84. * is only initialised when the context is constructed from the URL.
  85. */
  86. ORB orb;
  87. /**
  88. * The properties.
  89. */
  90. Hashtable properties;
  91. /**
  92. * The parent factory.
  93. */
  94. GiopNamingServiceFactory factory;
  95. /**
  96. * The name transformer to obtain the name from its string representation. The
  97. * to_name method of the naming service is avoided as it may be remote and
  98. * hence expensive. The conversion rules are standard and cannot be service
  99. * specific.
  100. */
  101. static NameTransformer transformer = new NameTransformer();
  102. /**
  103. * The batch size for list operations - how many to return at once.
  104. */
  105. public final int howMany;
  106. /**
  107. * Creates a new naming context that uses naming service, represented by the
  108. * given CORBA object.
  109. *
  110. * @param props
  111. * the environment table.
  112. * @param aFactory
  113. * parent factory. This reference is used during cleanup.
  114. * @param anOrb
  115. * the associated ORB. This reference is used during cleanup.
  116. */
  117. public GiopNamingServiceURLContext(Hashtable props,
  118. GiopNamingServiceFactory aFactory,
  119. ORB anOrb)
  120. {
  121. factory = aFactory;
  122. orb = anOrb;
  123. properties = props;
  124. howMany = getBatchSize();
  125. }
  126. public NamingContextExt getService(String address)
  127. {
  128. org.omg.CORBA.Object nsObject = orb.string_to_object(address);
  129. Delegate delegate = ((ObjectImpl) nsObject)._get_delegate();
  130. // If the IOR provides the IDL ID, we can check if our name
  131. // service is old NamingContext or new NamingContextExt.
  132. // Not all forms of the URL always provide the IDL id.
  133. if (!nsObject._is_a(NamingContextExtHelper.id())
  134. && nsObject._is_a(NamingContextHelper.id()))
  135. {
  136. // We are surely working with the old version.
  137. _NamingContextStub stub = new _NamingContextStub();
  138. stub._set_delegate(delegate);
  139. // The Ext object will add the necessary extensions.
  140. return new Ext(stub);
  141. }
  142. else
  143. {
  144. // We expecte the service to be the NamingContextExt (this is true
  145. // for both Sun's and our implementations). There is no easy way
  146. // to check the version.
  147. _NamingContextExtStub stub = new _NamingContextExtStub();
  148. stub._set_delegate(delegate);
  149. return stub;
  150. }
  151. }
  152. /**
  153. * Split the corbaname name into the address of the naming service (first
  154. * part) and the name of the object in the naming service (second part)
  155. */
  156. public String[] split(String corbaloc) throws InvalidNameException
  157. {
  158. if (corbaloc.endsWith("#"))
  159. corbaloc = corbaloc.substring(0, corbaloc.length() - 1);
  160. // No name part - parse as corbaname.
  161. if (corbaloc.indexOf('#') < 0)
  162. {
  163. if (!corbaloc.regionMatches(true, 0, pxCORBANAME, 0,
  164. pxCORBANAME.length()))
  165. throw new InvalidNameException(corbaloc + " must start with "
  166. + pxCORBANAME);
  167. corbaloc = pxCORBALOC + corbaloc.substring(pxCORBANAME.length());
  168. return new String[] { corbaloc, "" };
  169. }
  170. return corbaloc(corbaloc, orb);
  171. }
  172. /**
  173. * Give the specified name for the specified object. The passed name must not
  174. * be already bound to some other object. The components of the name are
  175. * mapped into the components of the CORBA name.
  176. *
  177. * @param name
  178. * the name that will be given to the object (in the scope of this
  179. * context).
  180. * @param obj
  181. * the object being named.
  182. * @throws NameAlreadyBoundException
  183. * if this name is already used to name some object.
  184. * @throws InvalidAttributesException
  185. * if the object does not supply all required attributes.
  186. * @throws NamingException
  187. * if the naming operation has failed due other reasons.
  188. */
  189. public void bind(Name name, Object obj) throws NamingException
  190. {
  191. bind(name.toString(), obj);
  192. }
  193. /**
  194. * Give the specified name for the specified object. The passed name must not
  195. * be already bound to some other object.
  196. *
  197. * @param name
  198. * the name that will be given to the object (in the scope of this
  199. * context).
  200. * @param obj
  201. * the object being named.
  202. * @throws NameAlreadyBoundException
  203. * if this name is already used to name some object.
  204. * @throws InvalidAttributesException
  205. * if the object does not supply all required attributes.
  206. * @throws NamingException
  207. * if the naming operation has failed due other reasons.
  208. */
  209. public void bind(String name, Object obj) throws NamingException
  210. {
  211. try
  212. {
  213. String[] n = split(name);
  214. org.omg.CORBA.Object object = (org.omg.CORBA.Object) obj;
  215. getService(n[0]).bind(transformer.toName(n[1]), object);
  216. }
  217. catch (ClassCastException e)
  218. {
  219. throw new NamingException(org.omg.CORBA.Object.class + " required ");
  220. }
  221. catch (InvalidName e)
  222. {
  223. throw new InvalidNameException();
  224. }
  225. catch (AlreadyBound e)
  226. {
  227. throw new NameAlreadyBoundException();
  228. }
  229. catch (Exception e)
  230. {
  231. throw new NamingException(e.toString());
  232. }
  233. }
  234. /**
  235. * Releases all resources, associated with this context. The close() method
  236. * can be called several times, but after it has been once invoked, it is not
  237. * allowed to call any other method of this context. This method destroys
  238. * the ORB, if we have one.
  239. *
  240. * @throws NamingException
  241. */
  242. public void close() throws NamingException
  243. {
  244. if (orb != null && factory != null)
  245. {
  246. factory.checkIfReferenced(orb);
  247. }
  248. }
  249. /**
  250. * Not supported.
  251. */
  252. public Name composeName(Name name, Name prefix) throws NamingException
  253. {
  254. throw new OperationNotSupportedException();
  255. }
  256. /**
  257. * Not supported
  258. */
  259. public String composeName(String name1, String name2) throws NamingException
  260. {
  261. throw new OperationNotSupportedException();
  262. }
  263. /**
  264. * Creates the new naming subcontext and binds it to the current (this)
  265. * context. The returned object will wrap around the newly created CORBA
  266. * subcontext
  267. *
  268. * @param subContext
  269. * the name of the new context being created
  270. * @return the newly created context, bound to the instance of the context on
  271. * that the method has been called
  272. * @throws NameAlreadyBoundException
  273. * if this name is already bound
  274. * @throws InvalidAttributesException
  275. * if the creation of the new context requires the missing mandatory
  276. * attributes
  277. * @throws NamingException
  278. */
  279. public Context createSubcontext(Name subContext) throws NamingException
  280. {
  281. return createSubcontext(subContext.toString());
  282. }
  283. /**
  284. * Creates the new naming subcontext and binds it to the current (this)
  285. * context. The returned object will wrap around the newly created CORBA
  286. * subcontext
  287. *
  288. * @param subContext
  289. * the name of the new context being created
  290. * @return the newly created context, bound to the instance of the context on
  291. * that the method has been called
  292. * @throws NameAlreadyBoundException
  293. * if this name is already bound
  294. * @throws InvalidAttributesException
  295. * if the creation of the new context requires the missing mandatory
  296. * attributes
  297. * @throws NamingException
  298. */
  299. public Context createSubcontext(String subContext) throws NamingException
  300. {
  301. try
  302. {
  303. String[] n = split(subContext);
  304. org.omg.CORBA.Object subcontext = getService(n[0]).bind_new_context(
  305. transformer.toName(n[1]));
  306. Hashtable clonedProps = new Hashtable();
  307. clonedProps.putAll(properties);
  308. // Nulls are passed both for orb and factory, as the child contexts
  309. // need not to do any cleanup.
  310. return new ContextContinuation(subcontext, clonedProps, null, null);
  311. }
  312. catch (AlreadyBound e)
  313. {
  314. throw new NameAlreadyBoundException(subContext);
  315. }
  316. catch (InvalidName e)
  317. {
  318. throw new InvalidNameException(subContext);
  319. }
  320. catch (Exception ex)
  321. {
  322. throw new NamingException(ex.toString());
  323. }
  324. }
  325. /**
  326. * Removes the naming subcontext from this naming context. Returns without
  327. * action if such subcontext does not exist. The context being destroyed must
  328. * be empty.
  329. *
  330. * @param subContext
  331. * the name of the subcontext beig removed.
  332. * @throws ContextNotEmptyException
  333. * if the named context is not empty.
  334. * @throws NamingException
  335. */
  336. public void destroySubcontext(Name subContext) throws NamingException
  337. {
  338. unbind(subContext);
  339. }
  340. /**
  341. * Removes the naming subcontext from this naming context. Returns without
  342. * action if such subcontext does not exist. The context being destroyed must
  343. * be empty.
  344. *
  345. * @param subContext
  346. * the name of the subcontext beig removed.
  347. * @throws ContextNotEmptyException
  348. * if the named context is not empty.
  349. * @throws NamingException
  350. */
  351. public void destroySubcontext(String subContext) throws NamingException
  352. {
  353. unbind(subContext);
  354. }
  355. /**
  356. * Returs the empty string.
  357. */
  358. public String getNameInNamespace() throws NamingException
  359. {
  360. return "";
  361. }
  362. /**
  363. * Not supported.
  364. */
  365. public NameParser getNameParser(Name name) throws NamingException
  366. {
  367. throw new UnsupportedOperationException();
  368. }
  369. /**
  370. * Not supported.
  371. */
  372. public NameParser getNameParser(String name) throws NamingException
  373. {
  374. throw new UnsupportedOperationException();
  375. }
  376. /**
  377. * Creates and returns the enumeration over the name bindings that are present
  378. * the given subcontext. The enumeration elements have the type of
  379. * {@link NameClassPair}, providing also information about the class of the
  380. * bound object. The behaviour in the case if the bindings are added or
  381. * removed later is not defined. The contents of the subcontexts are not
  382. * included.
  383. *
  384. * @param name
  385. * the name of the subcontext
  386. * @return the enumeration over the names, known for the given subcontext.
  387. * @throws NamingException
  388. */
  389. public NamingEnumeration list(Name name) throws NamingException
  390. {
  391. return list(name.toString());
  392. }
  393. /**
  394. * Creates and returns the enumeration over the name bindings that are present
  395. * the given subcontext. The enumeration elements have the type of
  396. * {@link NameClassPair}, providing also information about the class of the
  397. * bound object. The behaviour in the case if the bindings are added or
  398. * removed later is not defined. The contents of the subcontexts are not
  399. * included.
  400. *
  401. * @param name
  402. * the name of the subcontext
  403. * @return the enumeration over the names, known for the given subcontext.
  404. * @throws NamingException
  405. */
  406. public NamingEnumeration list(String name) throws NamingException
  407. {
  408. BindingIteratorHolder bi = new BindingIteratorHolder();
  409. BindingListHolder bl = new BindingListHolder();
  410. NamingContext subcontext;
  411. String [] n = split(name);
  412. NamingContextExt service = getService(n[0]);
  413. if (n[1].length() == 0)
  414. subcontext = service;
  415. else
  416. {
  417. try
  418. {
  419. subcontext = (NamingContextHelper.narrow(service.resolve_str(n[1])));
  420. }
  421. catch (Exception e)
  422. {
  423. throw new NamingException(e.toString());
  424. }
  425. }
  426. subcontext.list(howMany, bl, bi);
  427. return new ListEnumeration(bl, bi, howMany);
  428. }
  429. /**
  430. * Creates and returns the enumeration over the name - object bindings that
  431. * are present the given subcontext. The enumeration elements have the type of
  432. * {@link Binding}, providing also information about the class of the bound
  433. * object. The behaviour in the case if the bindings are added or removed
  434. * later is not defined. The contents of the subcontexts are not included.
  435. *
  436. * @param name
  437. * the name of the subcontext
  438. * @return the enumeration over the names, known for the given subcontext.
  439. * @throws NamingException
  440. */
  441. public NamingEnumeration listBindings(Name name) throws NamingException
  442. {
  443. return listBindings(name.toString());
  444. }
  445. /**
  446. * Creates and returns the enumeration over the name - object bindings that
  447. * are present the given subcontext. The enumeration elements have the type of
  448. * {@link Binding}, providing also information about the class of the bound
  449. * object. The behaviour in the case if the bindings are added or removed
  450. * later is not defined. The contents of the subcontexts are not included.
  451. *
  452. * @param name
  453. * the name of the subcontext
  454. * @return the enumeration over the names, known for the given subcontext.
  455. * @throws NamingException
  456. */
  457. public NamingEnumeration listBindings(String name) throws NamingException
  458. {
  459. BindingIteratorHolder bi = new BindingIteratorHolder();
  460. BindingListHolder bl = new BindingListHolder();
  461. NamingContext subcontext;
  462. String [] n = split(name);
  463. NamingContextExt service = getService(n[0]);
  464. if (n[1].length() == 0)
  465. subcontext = service;
  466. else
  467. {
  468. try
  469. {
  470. subcontext = (NamingContextHelper.narrow(service.resolve_str(n[1])));
  471. }
  472. catch (Exception e)
  473. {
  474. throw new NamingException(e.toString());
  475. }
  476. }
  477. subcontext.list(howMany, bl, bi);
  478. return new ListBindingsEnumeration(bl, bi, howMany, subcontext);
  479. }
  480. /**
  481. * Gets the previously named object by name. If the passed name is empty, the
  482. * method should return a cloned instance of this naming context.
  483. *
  484. * @param name
  485. * the name of the object being searched in this context
  486. * @return the named object
  487. * @throws NameNotFoundException
  488. * if the name is not found
  489. */
  490. public Object lookup(Name name) throws NamingException
  491. {
  492. return lookup(name.toString());
  493. }
  494. /**
  495. * Gets the previously named object by name. If the passed name is empty, the
  496. * method should return a cloned instance of this naming context.
  497. *
  498. * @param name
  499. * the name of the object being searched in this context
  500. * @return the named object
  501. * @throws NamingException
  502. * if the naming fails.
  503. */
  504. public Object lookup(String name) throws NamingException
  505. {
  506. try
  507. {
  508. String [] n = split(name);
  509. NamingContextExt service = getService(n[0]);
  510. return service.resolve_str(n[1]);
  511. }
  512. catch (NotFound e)
  513. {
  514. throw new NameNotFoundException();
  515. }
  516. catch (InvalidName e)
  517. {
  518. throw new InvalidNameException();
  519. }
  520. catch (Exception e)
  521. {
  522. throw new NamingException(e.toString());
  523. }
  524. }
  525. /**
  526. * Not supported.
  527. */
  528. public Object lookupLink(Name name) throws NamingException
  529. {
  530. throw new OperationNotSupportedException();
  531. }
  532. /**
  533. * Not supported.
  534. */
  535. public Object lookupLink(String name) throws NamingException
  536. {
  537. throw new OperationNotSupportedException();
  538. }
  539. /**
  540. * Give the specified name for the specified object. Unlike bind, this method
  541. * silently replaces the existing binding for this name, if one exists.
  542. *
  543. * @param name
  544. * the name that will be given to the object (in the scope of this
  545. * context).
  546. * @param obj
  547. * the object being named.
  548. * @throws InvalidAttributesException
  549. * if the object does not supply all required attributes.
  550. * @throws NamingException
  551. * if the naming operation has failed due other reasons.
  552. */
  553. public void rebind(Name name, Object obj) throws NamingException
  554. {
  555. rebind(name.toString(), obj);
  556. }
  557. /**
  558. * Give the specified name for the specified object. Unlike bind, this method
  559. * silently replaces the existing binding for this name, if one exists.
  560. *
  561. * @param name
  562. * the name that will be given to the object (in the scope of this
  563. * context).
  564. * @param obj
  565. * the object being named.
  566. * @throws InvalidAttributesException
  567. * if the object does not supply all required attributes.
  568. * @throws NamingException
  569. * if the naming operation has failed due other reasons.
  570. */
  571. public void rebind(String name, Object obj) throws NamingException
  572. {
  573. try
  574. {
  575. String[] n = split(name);
  576. NamingContextExt service = getService(n[0]);
  577. org.omg.CORBA.Object object = (org.omg.CORBA.Object) obj;
  578. service.rebind(transformer.toName(n[1]), object);
  579. }
  580. catch (ClassCastException e)
  581. {
  582. throw new NamingException(org.omg.CORBA.Object.class + " required ");
  583. }
  584. catch (InvalidName e)
  585. {
  586. throw new InvalidNameException();
  587. }
  588. catch (Exception e)
  589. {
  590. throw new NamingException(e.toString());
  591. }
  592. }
  593. /**
  594. * Renames the existing binding, removing the existing and giving the new name
  595. * for the same object.
  596. *
  597. * @param oldName
  598. * the existing name of the known object
  599. * @param newName
  600. * the new name of the same object
  601. * @throws NameNotFoundException
  602. * if the oldName is unknown for this context
  603. * @throws NamingException
  604. * if the naming operation has failed due other reasons.
  605. */
  606. public void rename(Name oldName, Name newName) throws NamingException
  607. {
  608. Object object = lookup(oldName);
  609. unbind(oldName);
  610. bind(newName, object);
  611. }
  612. /**
  613. * Renames the existing binding, removing the existing and giving the new name
  614. * for the same object.
  615. *
  616. * @param oldName
  617. * the existing name of the known object
  618. * @param newName
  619. * the new name of the same object
  620. * @throws NameNotFoundException
  621. * if the oldName is unknown for this context
  622. * @throws NamingException
  623. * if the naming operation has failed due other reasons.
  624. */
  625. public void rename(String oldName, String newName) throws NamingException
  626. {
  627. Object object = lookup(oldName);
  628. unbind(oldName);
  629. bind(newName, object);
  630. }
  631. /**
  632. * Removes the name - object mapping from the current context. This method
  633. * returns without action if the name is not bound to an object in the
  634. * terminal context, but throws {@link NameNotFoundException} if one of the
  635. * intermadiate contexts does not exist.
  636. *
  637. * @param name
  638. * the name to be removed
  639. * @throws NameNotFoundException
  640. * if one of the intermediate naming contexts does not exist. Will
  641. * not be thrown if just the terminal binding is missing.
  642. * @throws NamingException
  643. * if the naming operation has failed due other reasons.
  644. */
  645. public void unbind(Name name) throws NamingException
  646. {
  647. unbind(name.toString());
  648. }
  649. /**
  650. * Removes the name - object mapping from the current context. This method
  651. * returns without action if the name is not bound to an object in the
  652. * terminal context, but throws {@link NameNotFoundException} if one of the
  653. * intermadiate contexts does not exist.
  654. *
  655. * @param name
  656. * the name to be removed
  657. * @throws NameNotFoundException
  658. * if one of the intermediate naming contexts does not exist. Will
  659. * not be thrown if just the terminal binding is missing.
  660. * @throws NamingException
  661. * if the naming operation has failed due other reasons.
  662. */
  663. public void unbind(String name) throws NamingException
  664. {
  665. try
  666. {
  667. String[] n = split(name);
  668. NamingContextExt service = getService(n[0]);
  669. service.unbind(transformer.toName(n[1]));
  670. }
  671. catch (NotFound e)
  672. {
  673. throw new NameNotFoundException(name);
  674. }
  675. catch (CannotProceed e)
  676. {
  677. throw new ContextNotEmptyException(name);
  678. }
  679. catch (InvalidName e)
  680. {
  681. throw new InvalidNameException(name);
  682. }
  683. }
  684. /**
  685. * Add new environment property to the environment of this context. Both name
  686. * and value of the new property must not be null. If the property is already
  687. * defined, is current value is replaced by the propVal.
  688. *
  689. * @param key
  690. * the name of the new property
  691. * @param value
  692. * the value of the new property
  693. * @return the previous value of this property or null if the property has not
  694. * been previously defined
  695. * @throws NamingException
  696. */
  697. public Object addToEnvironment(String key, Object value)
  698. throws NamingException
  699. {
  700. if (key == null || value == null)
  701. throw new NullPointerException();
  702. return properties.put(key, value);
  703. }
  704. /**
  705. * Returns the environment, associated with this naming context. The returned
  706. * table should never be modified by the caller. Use {@link #addToEnvironment}
  707. * and {@link #removeFromEnvironment} to modify the environement, if needed.
  708. *
  709. * @return the table, representing the environment of this context
  710. * @throws NamingException
  711. */
  712. public Hashtable getEnvironment() throws NamingException
  713. {
  714. return properties;
  715. }
  716. /**
  717. * Removes the property with the given name from the environment. Returns
  718. * without action if this property is not defined.
  719. *
  720. * @param propName
  721. * the name of the property being removed.
  722. * @return the value of the property that has been removed or null if the
  723. * property was not defined.
  724. * @throws NamingException
  725. */
  726. public Object removeFromEnvironment(String propName) throws NamingException
  727. {
  728. return properties.remove(propName);
  729. }
  730. /**
  731. * Convert the {@link Name} into array of the name components, required to the
  732. * CORBA naming service. First the string representation is obtained, then
  733. * it is converted using parsing rules of the CORBA name.
  734. *
  735. * @param name
  736. * then name to convert
  737. * @return the converted array of components.
  738. */
  739. public NameComponent[] toGiop(Name name) throws InvalidName
  740. {
  741. return transformer.toName(name.toString());
  742. }
  743. /**
  744. * Get the batch size from the environment properties. The batch size is used
  745. * for listing operations.
  746. *
  747. * @return the batch size, or some default value if not specified.
  748. */
  749. public int getBatchSize()
  750. {
  751. int batchSize = DEFAULT_BATCH_SIZE;
  752. Object bs = properties.get(Context.BATCHSIZE);
  753. if (bs != null)
  754. {
  755. try
  756. {
  757. int b = Integer.parseInt(bs.toString());
  758. if (b >= 0)
  759. batchSize = b;
  760. }
  761. catch (NumberFormatException e)
  762. {
  763. // OK, use default value.
  764. }
  765. }
  766. return batchSize;
  767. }
  768. }