1. /*
  2. * @(#)Context.java 1.12 04/07/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.naming;
  8. import java.util.Hashtable;
  9. /**
  10. * This interface represents a naming context, which
  11. * consists of a set of name-to-object bindings.
  12. * It contains methods for examining and updating these bindings.
  13. * <p>
  14. * <h4>Names</h4>
  15. * Each name passed as an argument to a <tt>Context</tt> method is relative
  16. * to that context. The empty name is used to name the context itself.
  17. * A name parameter may never be null.
  18. * <p>
  19. * Most of the methods have overloaded versions with one taking a
  20. * <code>Name</code> parameter and one taking a <code>String</code>.
  21. * These overloaded versions are equivalent in that if
  22. * the <code>Name</code> and <code>String</code> parameters are just
  23. * different representations of the same name, then the overloaded
  24. * versions of the same methods behave the same.
  25. * In the method descriptions below, only one version is fully documented.
  26. * The second version instead has a link to the first: the same
  27. * documentation applies to both.
  28. * <p>
  29. * For systems that support federation, <tt>String</tt> name arguments to
  30. * <tt>Context</tt> methods are composite names. Name arguments that are
  31. * instances of <tt>CompositeName</tt> are treated as composite names,
  32. * while <tt>Name</tt> arguments that are not instances of
  33. * <tt>CompositeName</tt> are treated as compound names (which might be
  34. * instances of <tt>CompoundName</tt> or other implementations of compound
  35. * names). This allows the results of <tt>NameParser.parse()</tt> to be used as
  36. * arguments to the <tt>Context</tt> methods.
  37. * Prior to JNDI 1.2, all name arguments were treated as composite names.
  38. *<p>
  39. * Furthermore, for systems that support federation, all names returned
  40. * in a <tt>NamingEnumeration</tt>
  41. * from <tt>list()</tt> and <tt>listBindings()</tt> are composite names
  42. * represented as strings.
  43. * See <tt>CompositeName</tt> for the string syntax of names.
  44. *<p>
  45. * For systems that do not support federation, the name arguments (in
  46. * either <tt>Name</tt> or <tt>String</tt> forms) and the names returned in
  47. * <tt>NamingEnumeration</tt> may be names in their own namespace rather than
  48. * names in a composite namespace, at the discretion of the service
  49. * provider.
  50. *<p>
  51. *<h4>Exceptions</h4>
  52. * All the methods in this interface can throw a <tt>NamingException</tt> or
  53. * any of its subclasses. See <tt>NamingException</tt> and their subclasses
  54. * for details on each exception.
  55. *<p>
  56. *<h4>Concurrent Access</h4>
  57. * A Context instance is not guaranteed to be synchronized against
  58. * concurrent access by multiple threads. Threads that need to access
  59. * a single Context instance concurrently should synchronize amongst
  60. * themselves and provide the necessary locking. Multiple threads
  61. * each manipulating a different Context instance need not
  62. * synchronize. Note that the {@link #lookup(Name) <tt>lookup</tt>}
  63. * method, when passed an empty name, will return a new Context instance
  64. * representing the same naming context.
  65. *<p>
  66. * For purposes of concurrency control,
  67. * a Context operation that returns a <tt>NamingEnumeration</tt> is
  68. * not considered to have completed while the enumeration is still in
  69. * use, or while any referrals generated by that operation are still
  70. * being followed.
  71. *
  72. *<p>
  73. *<h4>Parameters</h4>
  74. * A <tt>Name</tt> parameter passed to any method of the
  75. * <tt>Context</tt> interface or one of its subinterfaces
  76. * will not be modified by the service provider.
  77. * The service provider may keep a reference to it
  78. * for the duration of the operation, including any enumeration of the
  79. * method's results and the processing of any referrals generated.
  80. * The caller should not modify the object during this time.
  81. * A <tt>Name</tt> returned by any such method is owned by the caller.
  82. * The caller may subsequently modify it; the service provider may not.
  83. *
  84. *<p>
  85. *<h4>Environment Properties</h4>
  86. *<p>
  87. * JNDI applications need a way to communicate various preferences
  88. * and properties that define the environment in which naming and
  89. * directory services are accessed. For example, a context might
  90. * require specification of security credentials in order to access
  91. * the service. Another context might require that server configuration
  92. * information be supplied. These are referred to as the <em>environment</em>
  93. * of a context. The <tt>Context</tt> interface provides methods for
  94. * retrieving and updating this environment.
  95. *<p>
  96. * The environment is inherited from the parent context as
  97. * context methods proceed from one context to the next. Changes to
  98. * the environment of one context do not directly affect those
  99. * of other contexts.
  100. *<p>
  101. * It is implementation-dependent when environment properties are used
  102. * and/or verified for validity. For example, some of the
  103. * security-related properties are used by service providers to "log in"
  104. * to the directory. This login process might occur at the time the
  105. * context is created, or the first time a method is invoked on the
  106. * context. When, and whether this occurs at all, is
  107. * implementation-dependent. When environment properties are added or
  108. * removed from the context, verifying the validity of the changes is again
  109. * implementation-dependent. For example, verification of some properties
  110. * might occur at the time the change is made, or at the time the next
  111. * operation is performed on the context, or not at all.
  112. *<p>
  113. * Any object with a reference to a context may examine that context's
  114. * environment. Sensitive information such as clear-text
  115. * passwords should not be stored there unless the implementation is
  116. * known to protect it.
  117. *
  118. *<p>
  119. *<a name=RESOURCEFILES></a>
  120. *<h4>Resource Files</h4>
  121. *<p>
  122. * To simplify the task of setting up the environment
  123. * required by a JNDI application,
  124. * application components and service providers may be distributed
  125. * along with <em>resource files.</em>
  126. * A JNDI resource file is a file in the properties file format (see
  127. * {@link java.util.Properties#load <tt>java.util.Properties</tt>}),
  128. * containing a list of key/value pairs.
  129. * The key is the name of the property (e.g. "java.naming.factory.object")
  130. * and the value is a string in the format defined
  131. * for that property. Here is an example of a JNDI resource file:
  132. *
  133. * <blockquote><tt><pre>
  134. * java.naming.factory.object=com.sun.jndi.ldap.AttrsToCorba:com.wiz.from.Person
  135. * java.naming.factory.state=com.sun.jndi.ldap.CorbaToAttrs:com.wiz.from.Person
  136. * java.naming.factory.control=com.sun.jndi.ldap.ResponseControlFactory
  137. * </pre></tt></blockquote>
  138. *
  139. * The JNDI class library reads the resource files and makes the property
  140. * values freely available. Thus JNDI resource files should be considered
  141. * to be "world readable", and sensitive information such as clear-text
  142. * passwords should not be stored there.
  143. *<p>
  144. * There are two kinds of JNDI resource files:
  145. * <em>provider</em> and <em>application</em>.
  146. *
  147. * <h5>Provider Resource Files</h5>
  148. *
  149. * Each service provider has an optional resource that lists properties
  150. * specific to that provider. The name of this resource is:
  151. * <blockquote>
  152. * [<em>prefix</em>/]<tt>jndiprovider.properties</tt>
  153. * </blockquote>
  154. * where <em>prefix</em> is
  155. * the package name of the provider's context implementation(s),
  156. * with each period (".") converted to a slash ("/").
  157. *
  158. * For example, suppose a service provider defines a context
  159. * implementation with class name <tt>com.sun.jndi.ldap.LdapCtx</tt>.
  160. * The provider resource for this provider is named
  161. * <tt>com/sun/jndi/ldap/jndiprovider.properties</tt>. If the class is
  162. * not in a package, the resource's name is simply
  163. * <tt>jndiprovider.properties</tt>.
  164. *
  165. * <p>
  166. * <a name=LISTPROPS></a>
  167. * Certain methods in the JNDI class library make use of the standard
  168. * JNDI properties that specify lists of JNDI factories:
  169. * <ul>
  170. * <li>java.naming.factory.object
  171. * <li>java.naming.factory.state
  172. * <li>java.naming.factory.control
  173. * <li>java.naming.factory.url.pkgs
  174. * </ul>
  175. * The JNDI library will consult the provider resource file
  176. * when determining the values of these properties.
  177. * Properties other than these may be set in the provider
  178. * resource file at the discretion of the service provider.
  179. * The service provider's documentation should clearly state which
  180. * properties are allowed; other properties in the file will be ignored.
  181. *
  182. * <h5>Application Resource Files</h5>
  183. *
  184. * When an application is deployed, it will generally have several
  185. * codebase directories and JARs in its classpath. Similarly, when an
  186. * applet is deployed, it will have a codebase and archives specifying
  187. * where to find the applet's classes. JNDI locates (using
  188. * {@link ClassLoader#getResources <tt>ClassLoader.getResources()</tt>})
  189. * all <em>application resource files</em> named <tt>jndi.properties</tt>
  190. * in the classpath.
  191. * In addition, if the file <i>java.home</i><tt>/lib/jndi.properties</tt>
  192. * exists and is readable,
  193. * JNDI treats it as an additional application resource file.
  194. * (<i>java.home</i> indicates the
  195. * directory named by the <tt>java.home</tt> system property.)
  196. * All of the properties contained in these files are placed
  197. * into the environment of the initial context. This environment
  198. * is then inherited by other contexts.
  199. *
  200. * <p>
  201. * For each property found in more than one application resource file,
  202. * JNDI uses the first value found or, in a few cases where it makes
  203. * sense to do so, it concatenates all of the values (details are given
  204. * below).
  205. * For example, if the "java.naming.factory.object" property is found in
  206. * three <tt>jndi.properties</tt> resource files, the
  207. * list of object factories is a concatenation of the property
  208. * values from all three files.
  209. * Using this scheme, each deployable component is responsible for
  210. * listing the factories that it exports. JNDI automatically
  211. * collects and uses all of these export lists when searching for factory
  212. * classes.
  213. *
  214. * <p>
  215. * Application resource files are available beginning with the Java 2
  216. * Platform, except that the file in
  217. * <i>java.home</i><tt>/lib</tt> may be used on earlier Java platforms as well.
  218. *
  219. * <h5>Search Algorithm for Properties</h5>
  220. *
  221. * When JNDI constructs an initial context, the context's environment
  222. * is initialized with properties defined in the environment parameter
  223. * passed to the constructor, the system properties, the applet parameters,
  224. * and the application resource files. See
  225. * <a href=InitialContext.html#ENVIRONMENT><tt>InitialContext</tt></a>
  226. * for details.
  227. * This initial environment is then inherited by other context instances.
  228. *
  229. * <p>
  230. * When the JNDI class library needs to determine
  231. * the value of a property, it does so by merging
  232. * the values from the following two sources, in order:
  233. * <ol>
  234. * <li>The environment of the context being operated on.
  235. * <li>The provider resource file (<tt>jndiprovider.properties</tt>)
  236. * for the context being operated on.
  237. * </ol>
  238. * For each property found in both of these two sources,
  239. * JNDI determines the property's value as follows. If the property is
  240. * one of the standard JNDI properties that specify a list of JNDI
  241. * factories (listed <a href=#LISTPROPS>above</a>), the values are
  242. * concatenated into a single colon-separated list. For other
  243. * properties, only the first value found is used.
  244. *
  245. * <p>
  246. * When a service provider needs to determine the value of a property,
  247. * it will generally take that value directly from the environment.
  248. * A service provider may define provider-specific properties
  249. * to be placed in its own provider resource file. In that
  250. * case it should merge values as described in the previous paragraph.
  251. *
  252. * <p>
  253. * In this way, each service provider developer can specify a list of
  254. * factories to use with that service provider. These can be modified by
  255. * the application resources specified by the deployer of the application
  256. * or applet, which in turn can be modified by the user.
  257. *
  258. * @author Rosanna Lee
  259. * @author Scott Seligman
  260. * @author R. Vasudevan
  261. * @version 1.12 04/07/16
  262. *
  263. * @since 1.3
  264. */
  265. public interface Context {
  266. /**
  267. * Retrieves the named object.
  268. * If <tt>name</tt> is empty, returns a new instance of this context
  269. * (which represents the same naming context as this context, but its
  270. * environment may be modified independently and it may be accessed
  271. * concurrently).
  272. *
  273. * @param name
  274. * the name of the object to look up
  275. * @return the object bound to <tt>name</tt>
  276. * @throws NamingException if a naming exception is encountered
  277. *
  278. * @see #lookup(String)
  279. * @see #lookupLink(Name)
  280. */
  281. public Object lookup(Name name) throws NamingException;
  282. /**
  283. * Retrieves the named object.
  284. * See {@link #lookup(Name)} for details.
  285. * @param name
  286. * the name of the object to look up
  287. * @return the object bound to <tt>name</tt>
  288. * @throws NamingException if a naming exception is encountered
  289. */
  290. public Object lookup(String name) throws NamingException;
  291. /**
  292. * Binds a name to an object.
  293. * All intermediate contexts and the target context (that named by all
  294. * but terminal atomic component of the name) must already exist.
  295. *
  296. * @param name
  297. * the name to bind; may not be empty
  298. * @param obj
  299. * the object to bind; possibly null
  300. * @throws NameAlreadyBoundException if name is already bound
  301. * @throws javax.naming.directory.InvalidAttributesException
  302. * if object did not supply all mandatory attributes
  303. * @throws NamingException if a naming exception is encountered
  304. *
  305. * @see #bind(String, Object)
  306. * @see #rebind(Name, Object)
  307. * @see javax.naming.directory.DirContext#bind(Name, Object,
  308. * javax.naming.directory.Attributes)
  309. */
  310. public void bind(Name name, Object obj) throws NamingException;
  311. /**
  312. * Binds a name to an object.
  313. * See {@link #bind(Name, Object)} for details.
  314. *
  315. * @param name
  316. * the name to bind; may not be empty
  317. * @param obj
  318. * the object to bind; possibly null
  319. * @throws NameAlreadyBoundException if name is already bound
  320. * @throws javax.naming.directory.InvalidAttributesException
  321. * if object did not supply all mandatory attributes
  322. * @throws NamingException if a naming exception is encountered
  323. */
  324. public void bind(String name, Object obj) throws NamingException;
  325. /**
  326. * Binds a name to an object, overwriting any existing binding.
  327. * All intermediate contexts and the target context (that named by all
  328. * but terminal atomic component of the name) must already exist.
  329. *
  330. * <p> If the object is a <tt>DirContext</tt>, any existing attributes
  331. * associated with the name are replaced with those of the object.
  332. * Otherwise, any existing attributes associated with the name remain
  333. * unchanged.
  334. *
  335. * @param name
  336. * the name to bind; may not be empty
  337. * @param obj
  338. * the object to bind; possibly null
  339. * @throws javax.naming.directory.InvalidAttributesException
  340. * if object did not supply all mandatory attributes
  341. * @throws NamingException if a naming exception is encountered
  342. *
  343. * @see #rebind(String, Object)
  344. * @see #bind(Name, Object)
  345. * @see javax.naming.directory.DirContext#rebind(Name, Object,
  346. * javax.naming.directory.Attributes)
  347. * @see javax.naming.directory.DirContext
  348. */
  349. public void rebind(Name name, Object obj) throws NamingException;
  350. /**
  351. * Binds a name to an object, overwriting any existing binding.
  352. * See {@link #rebind(Name, Object)} for details.
  353. *
  354. * @param name
  355. * the name to bind; may not be empty
  356. * @param obj
  357. * the object to bind; possibly null
  358. * @throws javax.naming.directory.InvalidAttributesException
  359. * if object did not supply all mandatory attributes
  360. * @throws NamingException if a naming exception is encountered
  361. */
  362. public void rebind(String name, Object obj) throws NamingException;
  363. /**
  364. * Unbinds the named object.
  365. * Removes the terminal atomic name in <code>name</code>
  366. * from the target context--that named by all but the terminal
  367. * atomic part of <code>name</code>.
  368. *
  369. * <p> This method is idempotent.
  370. * It succeeds even if the terminal atomic name
  371. * is not bound in the target context, but throws
  372. * <tt>NameNotFoundException</tt>
  373. * if any of the intermediate contexts do not exist.
  374. *
  375. * <p> Any attributes associated with the name are removed.
  376. * Intermediate contexts are not changed.
  377. *
  378. * @param name
  379. * the name to unbind; may not be empty
  380. * @throws NameNotFoundException if an intermediate context does not exist
  381. * @throws NamingException if a naming exception is encountered
  382. * @see #unbind(String)
  383. */
  384. public void unbind(Name name) throws NamingException;
  385. /**
  386. * Unbinds the named object.
  387. * See {@link #unbind(Name)} for details.
  388. *
  389. * @param name
  390. * the name to unbind; may not be empty
  391. * @throws NameNotFoundException if an intermediate context does not exist
  392. * @throws NamingException if a naming exception is encountered
  393. */
  394. public void unbind(String name) throws NamingException;
  395. /**
  396. * Binds a new name to the object bound to an old name, and unbinds
  397. * the old name. Both names are relative to this context.
  398. * Any attributes associated with the old name become associated
  399. * with the new name.
  400. * Intermediate contexts of the old name are not changed.
  401. *
  402. * @param oldName
  403. * the name of the existing binding; may not be empty
  404. * @param newName
  405. * the name of the new binding; may not be empty
  406. * @throws NameAlreadyBoundException if <tt>newName</tt> is already bound
  407. * @throws NamingException if a naming exception is encountered
  408. *
  409. * @see #rename(String, String)
  410. * @see #bind(Name, Object)
  411. * @see #rebind(Name, Object)
  412. */
  413. public void rename(Name oldName, Name newName) throws NamingException;
  414. /**
  415. * Binds a new name to the object bound to an old name, and unbinds
  416. * the old name.
  417. * See {@link #rename(Name, Name)} for details.
  418. *
  419. * @param oldName
  420. * the name of the existing binding; may not be empty
  421. * @param newName
  422. * the name of the new binding; may not be empty
  423. * @throws NameAlreadyBoundException if <tt>newName</tt> is already bound
  424. * @throws NamingException if a naming exception is encountered
  425. */
  426. public void rename(String oldName, String newName) throws NamingException;
  427. /**
  428. * Enumerates the names bound in the named context, along with the
  429. * class names of objects bound to them.
  430. * The contents of any subcontexts are not included.
  431. *
  432. * <p> If a binding is added to or removed from this context,
  433. * its effect on an enumeration previously returned is undefined.
  434. *
  435. * @param name
  436. * the name of the context to list
  437. * @return an enumeration of the names and class names of the
  438. * bindings in this context. Each element of the
  439. * enumeration is of type <tt>NameClassPair</tt>.
  440. * @throws NamingException if a naming exception is encountered
  441. *
  442. * @see #list(String)
  443. * @see #listBindings(Name)
  444. * @see NameClassPair
  445. */
  446. public NamingEnumeration<NameClassPair> list(Name name)
  447. throws NamingException;
  448. /**
  449. * Enumerates the names bound in the named context, along with the
  450. * class names of objects bound to them.
  451. * See {@link #list(Name)} for details.
  452. *
  453. * @param name
  454. * the name of the context to list
  455. * @return an enumeration of the names and class names of the
  456. * bindings in this context. Each element of the
  457. * enumeration is of type <tt>NameClassPair</tt>.
  458. * @throws NamingException if a naming exception is encountered
  459. */
  460. public NamingEnumeration<NameClassPair> list(String name)
  461. throws NamingException;
  462. /**
  463. * Enumerates the names bound in the named context, along with the
  464. * objects bound to them.
  465. * The contents of any subcontexts are not included.
  466. *
  467. * <p> If a binding is added to or removed from this context,
  468. * its effect on an enumeration previously returned is undefined.
  469. *
  470. * @param name
  471. * the name of the context to list
  472. * @return an enumeration of the bindings in this context.
  473. * Each element of the enumeration is of type
  474. * <tt>Binding</tt>.
  475. * @throws NamingException if a naming exception is encountered
  476. *
  477. * @see #listBindings(String)
  478. * @see #list(Name)
  479. * @see Binding
  480. */
  481. public NamingEnumeration<Binding> listBindings(Name name)
  482. throws NamingException;
  483. /**
  484. * Enumerates the names bound in the named context, along with the
  485. * objects bound to them.
  486. * See {@link #listBindings(Name)} for details.
  487. *
  488. * @param name
  489. * the name of the context to list
  490. * @return an enumeration of the bindings in this context.
  491. * Each element of the enumeration is of type
  492. * <tt>Binding</tt>.
  493. * @throws NamingException if a naming exception is encountered
  494. */
  495. public NamingEnumeration<Binding> listBindings(String name)
  496. throws NamingException;
  497. /**
  498. * Destroys the named context and removes it from the namespace.
  499. * Any attributes associated with the name are also removed.
  500. * Intermediate contexts are not destroyed.
  501. *
  502. * <p> This method is idempotent.
  503. * It succeeds even if the terminal atomic name
  504. * is not bound in the target context, but throws
  505. * <tt>NameNotFoundException</tt>
  506. * if any of the intermediate contexts do not exist.
  507. *
  508. * <p> In a federated naming system, a context from one naming system
  509. * may be bound to a name in another. One can subsequently
  510. * look up and perform operations on the foreign context using a
  511. * composite name. However, an attempt destroy the context using
  512. * this composite name will fail with
  513. * <tt>NotContextException</tt>, because the foreign context is not
  514. * a "subcontext" of the context in which it is bound.
  515. * Instead, use <tt>unbind()</tt> to remove the
  516. * binding of the foreign context. Destroying the foreign context
  517. * requires that the <tt>destroySubcontext()</tt> be performed
  518. * on a context from the foreign context's "native" naming system.
  519. *
  520. * @param name
  521. * the name of the context to be destroyed; may not be empty
  522. * @throws NameNotFoundException if an intermediate context does not exist
  523. * @throws NotContextException if the name is bound but does not name a
  524. * context, or does not name a context of the appropriate type
  525. * @throws ContextNotEmptyException if the named context is not empty
  526. * @throws NamingException if a naming exception is encountered
  527. *
  528. * @see #destroySubcontext(String)
  529. */
  530. public void destroySubcontext(Name name) throws NamingException;
  531. /**
  532. * Destroys the named context and removes it from the namespace.
  533. * See {@link #destroySubcontext(Name)} for details.
  534. *
  535. * @param name
  536. * the name of the context to be destroyed; may not be empty
  537. * @throws NameNotFoundException if an intermediate context does not exist
  538. * @throws NotContextException if the name is bound but does not name a
  539. * context, or does not name a context of the appropriate type
  540. * @throws ContextNotEmptyException if the named context is not empty
  541. * @throws NamingException if a naming exception is encountered
  542. */
  543. public void destroySubcontext(String name) throws NamingException;
  544. /**
  545. * Creates and binds a new context.
  546. * Creates a new context with the given name and binds it in
  547. * the target context (that named by all but terminal atomic
  548. * component of the name). All intermediate contexts and the
  549. * target context must already exist.
  550. *
  551. * @param name
  552. * the name of the context to create; may not be empty
  553. * @return the newly created context
  554. *
  555. * @throws NameAlreadyBoundException if name is already bound
  556. * @throws javax.naming.directory.InvalidAttributesException
  557. * if creation of the subcontext requires specification of
  558. * mandatory attributes
  559. * @throws NamingException if a naming exception is encountered
  560. *
  561. * @see #createSubcontext(String)
  562. * @see javax.naming.directory.DirContext#createSubcontext
  563. */
  564. public Context createSubcontext(Name name) throws NamingException;
  565. /**
  566. * Creates and binds a new context.
  567. * See {@link #createSubcontext(Name)} for details.
  568. *
  569. * @param name
  570. * the name of the context to create; may not be empty
  571. * @return the newly created context
  572. *
  573. * @throws NameAlreadyBoundException if name is already bound
  574. * @throws javax.naming.directory.InvalidAttributesException
  575. * if creation of the subcontext requires specification of
  576. * mandatory attributes
  577. * @throws NamingException if a naming exception is encountered
  578. */
  579. public Context createSubcontext(String name) throws NamingException;
  580. /**
  581. * Retrieves the named object, following links except
  582. * for the terminal atomic component of the name.
  583. * If the object bound to <tt>name</tt> is not a link,
  584. * returns the object itself.
  585. *
  586. * @param name
  587. * the name of the object to look up
  588. * @return the object bound to <tt>name</tt>, not following the
  589. * terminal link (if any).
  590. * @throws NamingException if a naming exception is encountered
  591. *
  592. * @see #lookupLink(String)
  593. */
  594. public Object lookupLink(Name name) throws NamingException;
  595. /**
  596. * Retrieves the named object, following links except
  597. * for the terminal atomic component of the name.
  598. * See {@link #lookupLink(Name)} for details.
  599. *
  600. * @param name
  601. * the name of the object to look up
  602. * @return the object bound to <tt>name</tt>, not following the
  603. * terminal link (if any)
  604. * @throws NamingException if a naming exception is encountered
  605. */
  606. public Object lookupLink(String name) throws NamingException;
  607. /**
  608. * Retrieves the parser associated with the named context.
  609. * In a federation of namespaces, different naming systems will
  610. * parse names differently. This method allows an application
  611. * to get a parser for parsing names into their atomic components
  612. * using the naming convention of a particular naming system.
  613. * Within any single naming system, <tt>NameParser</tt> objects
  614. * returned by this method must be equal (using the <tt>equals()</tt>
  615. * test).
  616. *
  617. * @param name
  618. * the name of the context from which to get the parser
  619. * @return a name parser that can parse compound names into their atomic
  620. * components
  621. * @throws NamingException if a naming exception is encountered
  622. *
  623. * @see #getNameParser(String)
  624. * @see CompoundName
  625. */
  626. public NameParser getNameParser(Name name) throws NamingException;
  627. /**
  628. * Retrieves the parser associated with the named context.
  629. * See {@link #getNameParser(Name)} for details.
  630. *
  631. * @param name
  632. * the name of the context from which to get the parser
  633. * @return a name parser that can parse compound names into their atomic
  634. * components
  635. * @throws NamingException if a naming exception is encountered
  636. */
  637. public NameParser getNameParser(String name) throws NamingException;
  638. /**
  639. * Composes the name of this context with a name relative to
  640. * this context.
  641. * Given a name (<code>name</code>) relative to this context, and
  642. * the name (<code>prefix</code>) of this context relative to one
  643. * of its ancestors, this method returns the composition of the
  644. * two names using the syntax appropriate for the naming
  645. * system(s) involved. That is, if <code>name</code> names an
  646. * object relative to this context, the result is the name of the
  647. * same object, but relative to the ancestor context. None of the
  648. * names may be null.
  649. * <p>
  650. * For example, if this context is named "wiz.com" relative
  651. * to the initial context, then
  652. * <pre>
  653. * composeName("east", "wiz.com") </pre>
  654. * might return <code>"east.wiz.com"</code>.
  655. * If instead this context is named "org/research", then
  656. * <pre>
  657. * composeName("user/jane", "org/research") </pre>
  658. * might return <code>"org/research/user/jane"</code> while
  659. * <pre>
  660. * composeName("user/jane", "research") </pre>
  661. * returns <code>"research/user/jane"</code>.
  662. *
  663. * @param name
  664. * a name relative to this context
  665. * @param prefix
  666. * the name of this context relative to one of its ancestors
  667. * @return the composition of <code>prefix</code> and <code>name</code>
  668. * @throws NamingException if a naming exception is encountered
  669. *
  670. * @see #composeName(String, String)
  671. */
  672. public Name composeName(Name name, Name prefix)
  673. throws NamingException;
  674. /**
  675. * Composes the name of this context with a name relative to
  676. * this context.
  677. * See {@link #composeName(Name, Name)} for details.
  678. *
  679. * @param name
  680. * a name relative to this context
  681. * @param prefix
  682. * the name of this context relative to one of its ancestors
  683. * @return the composition of <code>prefix</code> and <code>name</code>
  684. * @throws NamingException if a naming exception is encountered
  685. */
  686. public String composeName(String name, String prefix)
  687. throws NamingException;
  688. /**
  689. * Adds a new environment property to the environment of this
  690. * context. If the property already exists, its value is overwritten.
  691. * See class description for more details on environment properties.
  692. *
  693. * @param propName
  694. * the name of the environment property to add; may not be null
  695. * @param propVal
  696. * the value of the property to add; may not be null
  697. * @return the previous value of the property, or null if the property was
  698. * not in the environment before
  699. * @throws NamingException if a naming exception is encountered
  700. *
  701. * @see #getEnvironment()
  702. * @see #removeFromEnvironment(String)
  703. */
  704. public Object addToEnvironment(String propName, Object propVal)
  705. throws NamingException;
  706. /**
  707. * Removes an environment property from the environment of this
  708. * context. See class description for more details on environment
  709. * properties.
  710. *
  711. * @param propName
  712. * the name of the environment property to remove; may not be null
  713. * @return the previous value of the property, or null if the property was
  714. * not in the environment
  715. * @throws NamingException if a naming exception is encountered
  716. *
  717. * @see #getEnvironment()
  718. * @see #addToEnvironment(String, Object)
  719. */
  720. public Object removeFromEnvironment(String propName)
  721. throws NamingException;
  722. /**
  723. * Retrieves the environment in effect for this context.
  724. * See class description for more details on environment properties.
  725. *
  726. * <p> The caller should not make any changes to the object returned:
  727. * their effect on the context is undefined.
  728. * The environment of this context may be changed using
  729. * <tt>addToEnvironment()</tt> and <tt>removeFromEnvironment()</tt>.
  730. *
  731. * @return the environment of this context; never null
  732. * @throws NamingException if a naming exception is encountered
  733. *
  734. * @see #addToEnvironment(String, Object)
  735. * @see #removeFromEnvironment(String)
  736. */
  737. public Hashtable<?,?> getEnvironment() throws NamingException;
  738. /**
  739. * Closes this context.
  740. * This method releases this context's resources immediately, instead of
  741. * waiting for them to be released automatically by the garbage collector.
  742. *
  743. * <p> This method is idempotent: invoking it on a context that has
  744. * already been closed has no effect. Invoking any other method
  745. * on a closed context is not allowed, and results in undefined behaviour.
  746. *
  747. * @throws NamingException if a naming exception is encountered
  748. */
  749. public void close() throws NamingException;
  750. /**
  751. * Retrieves the full name of this context within its own namespace.
  752. *
  753. * <p> Many naming services have a notion of a "full name" for objects
  754. * in their respective namespaces. For example, an LDAP entry has
  755. * a distinguished name, and a DNS record has a fully qualified name.
  756. * This method allows the client application to retrieve this name.
  757. * The string returned by this method is not a JNDI composite name
  758. * and should not be passed directly to context methods.
  759. * In naming systems for which the notion of full name does not
  760. * make sense, <tt>OperationNotSupportedException</tt> is thrown.
  761. *
  762. * @return this context's name in its own namespace; never null
  763. * @throws OperationNotSupportedException if the naming system does
  764. * not have the notion of a full name
  765. * @throws NamingException if a naming exception is encountered
  766. *
  767. * @since 1.3
  768. */
  769. public String getNameInNamespace() throws NamingException;
  770. // public static final: JLS says recommended style is to omit these modifiers
  771. // because they are the default
  772. /**
  773. * Constant that holds the name of the environment property
  774. * for specifying the initial context factory to use. The value
  775. * of the property should be the fully qualified class name
  776. * of the factory class that will create an initial context.
  777. * This property may be specified in the environment parameter
  778. * passed to the initial context constructor, an applet parameter,
  779. * a system property, or an application resource file.
  780. * If it is not specified in any of these sources,
  781. * <tt>NoInitialContextException</tt> is thrown when an initial
  782. * context is required to complete an operation.
  783. *
  784. * <p> The value of this constant is "java.naming.factory.initial".
  785. *
  786. * @see InitialContext
  787. * @see javax.naming.directory.InitialDirContext
  788. * @see javax.naming.spi.NamingManager#getInitialContext
  789. * @see javax.naming.spi.InitialContextFactory
  790. * @see NoInitialContextException
  791. * @see #addToEnvironment(String, Object)
  792. * @see #removeFromEnvironment(String)
  793. * @see #APPLET
  794. */
  795. String INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial";
  796. /**
  797. * Constant that holds the name of the environment property
  798. * for specifying the list of object factories to use. The value
  799. * of the property should be a colon-separated list of the fully
  800. * qualified class names of factory classes that will create an object
  801. * given information about the object.
  802. * This property may be specified in the environment, an applet
  803. * parameter, a system property, or one or more resource files.
  804. *
  805. * <p> The value of this constant is "java.naming.factory.object".
  806. *
  807. * @see javax.naming.spi.NamingManager#getObjectInstance
  808. * @see javax.naming.spi.ObjectFactory
  809. * @see #addToEnvironment(String, Object)
  810. * @see #removeFromEnvironment(String)
  811. * @see #APPLET
  812. */
  813. String OBJECT_FACTORIES = "java.naming.factory.object";
  814. /**
  815. * Constant that holds the name of the environment property
  816. * for specifying the list of state factories to use. The value
  817. * of the property should be a colon-separated list of the fully
  818. * qualified class names of state factory classes that will be used
  819. * to get an object's state given the object itself.
  820. * This property may be specified in the environment, an applet
  821. * parameter, a system property, or one or more resource files.
  822. *
  823. * <p> The value of this constant is "java.naming.factory.state".
  824. *
  825. * @see javax.naming.spi.NamingManager#getStateToBind
  826. * @see javax.naming.spi.StateFactory
  827. * @see #addToEnvironment(String, Object)
  828. * @see #removeFromEnvironment(String)
  829. * @see #APPLET
  830. * @since 1.3
  831. */
  832. String STATE_FACTORIES = "java.naming.factory.state";
  833. /**
  834. * Constant that holds the name of the environment property
  835. * for specifying the list of package prefixes to use when
  836. * loading in URL context factories. The value
  837. * of the property should be a colon-separated list of package
  838. * prefixes for the class name of the factory class that will create
  839. * a URL context factory.
  840. * This property may be specified in the environment,
  841. * an applet parameter, a system property, or one or more
  842. * resource files.
  843. * The prefix <tt>com.sun.jndi.url</tt> is always appended to
  844. * the possibly empty list of package prefixes.
  845. *
  846. * <p> The value of this constant is "java.naming.factory.url.pkgs".
  847. *
  848. * @see javax.naming.spi.NamingManager#getObjectInstance
  849. * @see javax.naming.spi.NamingManager#getURLContext
  850. * @see javax.naming.spi.ObjectFactory
  851. * @see #addToEnvironment(String, Object)
  852. * @see #removeFromEnvironment(String)
  853. * @see #APPLET
  854. */
  855. String URL_PKG_PREFIXES = "java.naming.factory.url.pkgs";
  856. /**
  857. * Constant that holds the name of the environment property
  858. * for specifying configuration information for the service provider
  859. * to use. The value of the property should contain a URL string
  860. * (e.g. "ldap://somehost:389").
  861. * This property may be specified in the environment,
  862. * an applet parameter, a system property, or a resource file.
  863. * If it is not specified in any of these sources,
  864. * the default configuration is determined by the service provider.
  865. *
  866. * <p> The value of this constant is "java.naming.provider.url".
  867. *
  868. * @see #addToEnvironment(String, Object)
  869. * @see #removeFromEnvironment(String)
  870. * @see #APPLET
  871. */
  872. String PROVIDER_URL = "java.naming.provider.url";
  873. /**
  874. * Constant that holds the name of the environment property
  875. * for specifying the DNS host and domain names to use for the
  876. * JNDI URL context (for example, "dns://somehost/wiz.com").
  877. * This property may be specified in the environment,
  878. * an applet parameter, a system property, or a resource file.
  879. * If it is not specified in any of these sources
  880. * and the program attempts to use a JNDI URL containing a DNS name,
  881. * a <tt>ConfigurationException</tt> will be thrown.
  882. *
  883. * <p> The value of this constant is "java.naming.dns.url".
  884. *
  885. * @see #addToEnvironment(String, Object)
  886. * @see #removeFromEnvironment(String)
  887. */
  888. String DNS_URL = "java.naming.dns.url";
  889. /**
  890. * Constant that holds the name of the environment property for
  891. * specifying the authoritativeness of the service requested.
  892. * If the value of the property is the string "true", it means
  893. * that the access is to the most authoritative source (i.e. bypass
  894. * any cache or replicas). If the value is anything else,
  895. * the source need not be (but may be) authoritative.
  896. * If unspecified, the value defaults to "false".
  897. *
  898. * <p> The value of this constant is "java.naming.authoritative".
  899. *
  900. * @see #addToEnvironment(String, Object)
  901. * @see #removeFromEnvironment(String)
  902. */
  903. String AUTHORITATIVE = "java.naming.authoritative";
  904. /**
  905. * Constant that holds the name of the environment property for
  906. * specifying the batch size to use when returning data via the
  907. * service's protocol. This is a hint to the provider to return
  908. * the results of operations in batches of the specified size, so
  909. * the provider can optimize its performance and usage of resources.
  910. * The value of the property is the string representation of an
  911. * integer.
  912. * If unspecified, the batch size is determined by the service
  913. * provider.
  914. *
  915. * <p> The value of this constant is "java.naming.batchsize".
  916. *
  917. * @see #addToEnvironment(String, Object)
  918. * @see #removeFromEnvironment(String)
  919. */
  920. String BATCHSIZE = "java.naming.batchsize";
  921. /**
  922. * Constant that holds the name of the environment property for
  923. * specifying how referrals encountered by the service provider
  924. * are to be processed. The value of the property is one of the
  925. * following strings:
  926. * <dl>
  927. * <dt>"follow"
  928. * <dd>follow referrals automatically
  929. * <dt>"ignore"
  930. * <dd>ignore referrals
  931. * <dt>"throw"
  932. * <dd>throw <tt>ReferralException</tt> when a referral is encountered.
  933. * </dl>
  934. * If this property is not specified, the default is
  935. * determined by the provider.
  936. *
  937. * <p> The value of this constant is "java.naming.referral".
  938. *
  939. * @see #addToEnvironment(String, Object)
  940. * @see #removeFromEnvironment(String)
  941. */
  942. String REFERRAL = "java.naming.referral";
  943. /**
  944. * Constant that holds the name of the environment property for
  945. * specifying the security protocol to use.
  946. * Its value is a string determined by the service provider
  947. * (e.g. "ssl").
  948. * If this property is unspecified,
  949. * the behaviour is determined by the service provider.
  950. *
  951. * <p> The value of this constant is "java.naming.security.protocol".
  952. *
  953. * @see #addToEnvironment(String, Object)
  954. * @see #removeFromEnvironment(String)
  955. */
  956. String SECURITY_PROTOCOL = "java.naming.security.protocol";
  957. /**
  958. * Constant that holds the name of the environment property for
  959. * specifying the security level to use.
  960. * Its value is one of the following strings:
  961. * "none", "simple", "strong".
  962. * If this property is unspecified,
  963. * the behaviour is determined by the service provider.
  964. *
  965. * <p> The value of this constant is "java.naming.security.authentication".
  966. *
  967. * @see #addToEnvironment(String, Object)
  968. * @see #removeFromEnvironment(String)
  969. */
  970. String SECURITY_AUTHENTICATION = "java.naming.security.authentication";
  971. /**
  972. * Constant that holds the name of the environment property for
  973. * specifying the identity of the principal for authenticating
  974. * the caller to the service. The format of the principal
  975. * depends on the authentication scheme.
  976. * If this property is unspecified,
  977. * the behaviour is determined by the service provider.
  978. *
  979. * <p> The value of this constant is "java.naming.security.principal".
  980. *
  981. * @see #addToEnvironment(String, Object)
  982. * @see #removeFromEnvironment(String)
  983. */
  984. String SECURITY_PRINCIPAL = "java.naming.security.principal";
  985. /**
  986. * Constant that holds the name of the environment property for
  987. * specifying the credentials of the principal for authenticating
  988. * the caller to the service. The value of the property depends
  989. * on the authentication scheme. For example, it could be a hashed
  990. * password, clear-text password, key, certificate, and so on.
  991. * If this property is unspecified,
  992. * the behaviour is determined by the service provider.
  993. *
  994. * <p> The value of this constant is "java.naming.security.credentials".
  995. *
  996. * @see #addToEnvironment(String, Object)
  997. * @see #removeFromEnvironment(String)
  998. */
  999. String SECURITY_CREDENTIALS = "java.naming.security.credentials";
  1000. /**
  1001. * Constant that holds the name of the environment property for
  1002. * specifying the preferred language to use with the service.
  1003. * The value of the property is a colon-separated list of language
  1004. * tags as defined in RFC 1766.
  1005. * If this property is unspecified,
  1006. * the language preference is determined by the service provider.
  1007. *
  1008. * <p> The value of this constant is "java.naming.language".
  1009. *
  1010. * @see #addToEnvironment(String, Object)
  1011. * @see #removeFromEnvironment(String)
  1012. */
  1013. String LANGUAGE = "java.naming.language";
  1014. /**
  1015. * Constant that holds the name of the environment property for
  1016. * specifying an applet for the initial context constructor to use
  1017. * when searching for other properties.
  1018. * The value of this property is the
  1019. * <tt>java.applet.Applet</tt> instance that is being executed.
  1020. * This property may be specified in the environment parameter
  1021. * passed to the initial context constructor.
  1022. * When this property is set, each property that the initial context
  1023. * constructor looks for in the system properties is first looked for
  1024. * in the applet's parameter list.
  1025. * If this property is unspecified, the initial context constructor
  1026. * will search for properties only in the environment parameter
  1027. * passed to it, the system properties, and application resource files.
  1028. *
  1029. * <p> The value of this constant is "java.naming.applet".
  1030. *
  1031. * @see #addToEnvironment(String, Object)
  1032. * @see #removeFromEnvironment(String)
  1033. * @see InitialContext
  1034. *
  1035. * @since 1.3
  1036. */
  1037. String APPLET = "java.naming.applet";
  1038. };