Context.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. /* Context.java -- A naming context
  2. Copyright (C) 2000, 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 javax.naming;
  32. import java.util.Hashtable;
  33. import javax.naming.directory.InvalidAttributesException;
  34. public interface Context
  35. {
  36. /**
  37. * Property with name of the inital context factory to use
  38. */
  39. String INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial";
  40. /**
  41. * Property with colon-separated list of object factories to use.
  42. */
  43. String OBJECT_FACTORIES = "java.naming.factory.object";
  44. /**
  45. * Property with colon-separated list of state factories to use.
  46. */
  47. String STATE_FACTORIES = "java.naming.factory.state";
  48. /**
  49. * Property with colon-separated list of package prefixes to use.
  50. */
  51. String URL_PKG_PREFIXES = "java.naming.factory.url.pkgs";
  52. /**
  53. * Property with URL specifying configuration for the service provider to use.
  54. */
  55. String PROVIDER_URL = "java.naming.provider.url";
  56. /**
  57. * Property with the DNS host and domain names to use.
  58. */
  59. String DNS_URL = "java.naming.dns.url";
  60. /**
  61. * Property with the authoritativeness of the service requested.
  62. */
  63. String AUTHORITATIVE = "java.naming.authoritative";
  64. /**
  65. * Property with the batch size to use when returning data via the service's
  66. * protocol.
  67. */
  68. String BATCHSIZE = "java.naming.batchsize";
  69. /**
  70. * Property defining how referrals encountered by the service provider are to
  71. * be processed.
  72. */
  73. String REFERRAL = "java.naming.referral";
  74. /**
  75. * Property specifying the security protocol to use.
  76. */
  77. String SECURITY_PROTOCOL = "java.naming.security.protocol";
  78. /**
  79. * Property specifying the security level to use.
  80. */
  81. String SECURITY_AUTHENTICATION = "java.naming.security.authentication";
  82. /**
  83. * Property for the identity of the principal for authenticating the caller to
  84. * the service.
  85. */
  86. String SECURITY_PRINCIPAL = "java.naming.security.principal";
  87. /**
  88. * Property specifying the credentials of the principal for authenticating the
  89. * caller to the service.
  90. */
  91. String SECURITY_CREDENTIALS = "java.naming.security.credentials";
  92. /**
  93. * Property for specifying the preferred language to use with the service.
  94. */
  95. String LANGUAGE = "java.naming.language";
  96. /**
  97. * Property for the initial context constructor to use when searching for
  98. * other properties.
  99. */
  100. String APPLET = "java.naming.applet";
  101. /**
  102. * Give the specified name for the specified object. The passed name must not
  103. * be already bound to some other object.
  104. *
  105. * @param name the name that will be given to the object (in the scope of this
  106. * context).
  107. * @param obj the object being named.
  108. * @throws NameAlreadyBoundException if this name is already used to name some
  109. * object.
  110. * @throws InvalidAttributesException if the object does not supply all
  111. * required attributes.
  112. * @throws NamingException if the naming operation has failed due other
  113. * reasons.
  114. */
  115. void bind(Name name, Object obj) throws NamingException;
  116. /**
  117. * Give the specified name for the specified object. The passed name must not
  118. * be already bound to some other object.
  119. *
  120. * @param name the name that will be given to the object (in the scope of this
  121. * context).
  122. * @param obj the object being named.
  123. * @throws NameAlreadyBoundException if this name is already used to name some
  124. * object.
  125. * @throws InvalidAttributesException if the object does not supply all
  126. * required attributes.
  127. * @throws NamingException if the naming operation has failed due other
  128. * reasons.
  129. */
  130. void bind(String name, Object obj) throws NamingException;
  131. /**
  132. * Gets the previously named object by name. If the passed name is empty, the
  133. * method should return a cloned instance of this naming context.
  134. *
  135. * @param name the name of the object being searched in this context
  136. * @return the named object
  137. * @throws NamingException if the naming fails.
  138. */
  139. Object lookup(Name name) throws NamingException;
  140. /**
  141. * Gets the previously named object by name. If the passed name is empty, the
  142. * method should return a cloned instance of this naming context.
  143. *
  144. * @param name the name of the object being searched in this context
  145. * @return the named object
  146. * @throws NamingException if the naming fails.
  147. */
  148. Object lookup(String name) throws NamingException;
  149. /**
  150. * Give the specified name for the specified object. Unlike bind, this method
  151. * silently replaces the existing binding for this name, if one exists.
  152. *
  153. * @param name the name that will be given to the object (in the scope of this
  154. * context).
  155. * @param obj the object being named.
  156. * @throws InvalidAttributesException if the object does not supply all
  157. * required attributes.
  158. * @throws NamingException if the naming operation has failed due other
  159. * reasons.
  160. */
  161. void rebind(Name name, Object obj) throws NamingException;
  162. /**
  163. * Give the specified name for the specified object. Unlike bind, this method
  164. * silently replaces the existing binding for this name, if one exists.
  165. *
  166. * @param name the name that will be given to the object (in the scope of this
  167. * context).
  168. * @param obj the object being named.
  169. * @throws InvalidAttributesException if the object does not supply all
  170. * required attributes.
  171. * @throws NamingException if the naming operation has failed due other
  172. * reasons.
  173. */
  174. void rebind(String name, Object obj) throws NamingException;
  175. /**
  176. * Removes the name - object mapping from the current context. This method
  177. * returns without action if the name is not bound to an object in the
  178. * terminal context, but throws {@link NameNotFoundException} if one of the
  179. * intermadiate contexts does not exist.
  180. *
  181. * @param name the name to be removed
  182. * @throws NameNotFoundException if one of the intermediate naming contexts
  183. * does not exist. Will not be thrown if just the terminal binding
  184. * is missing.
  185. * @throws NamingException if the naming operation has failed due other
  186. * reasons.
  187. */
  188. void unbind(Name name) throws NamingException;
  189. /**
  190. * Removes the name - object mapping from the current context. This method
  191. * returns without action if the name is not bound to an object in the
  192. * terminal context, but throws {@link NameNotFoundException} if one of the
  193. * intermadiate contexts does not exist.
  194. *
  195. * @param name the name to be removed
  196. * @throws NameNotFoundException if one of the intermediate naming contexts
  197. * does not exist. Will not be thrown if just the terminal binding
  198. * is missing.
  199. * @throws NamingException if the naming operation has failed due other
  200. * reasons.
  201. */
  202. void unbind(String name) throws NamingException;
  203. /**
  204. * Renames the existing binding, removing the existing and giving the new name
  205. * for the same object.
  206. *
  207. * @param oldName the existing name of the known object
  208. * @param newName the new name of the same object
  209. * @throws NameNotFoundException if the oldName is unknown for this context
  210. * @throws NamingException if the naming operation has failed due other
  211. * reasons.
  212. */
  213. void rename(Name oldName, Name newName) throws NamingException;
  214. /**
  215. * Renames the existing binding, removing the existing and giving the new name
  216. * for the same object.
  217. *
  218. * @param oldName the existing name of the known object
  219. * @param newName the new name of the same object
  220. * @throws NameNotFoundException if the oldName is unknown for this context
  221. * @throws NamingException if the naming operation has failed due other
  222. * reasons.
  223. */
  224. void rename(String oldName, String newName) throws NamingException;
  225. /**
  226. * Creates and returns the enumeration over the name bindings that are present
  227. * the given subcontext. The enumeration elements have the type of
  228. * {@link NameClassPair}, providing also information about the class of the
  229. * bound object. The behaviour in the case if the bindings are added or
  230. * removed later is not defined. The contents of the subcontexts are not
  231. * included.
  232. *
  233. * @param name the name of the subcontext
  234. * @return the enumeration over the names, known for the given subcontext.
  235. * @throws NamingException
  236. */
  237. NamingEnumeration<NameClassPair> list(Name name) throws NamingException;
  238. /**
  239. * Creates and returns the enumeration over the name bindings that are present
  240. * the given subcontext. The enumeration elements have the type of
  241. * {@link NameClassPair}, providing also information about the class of the
  242. * bound object. The behaviour in the case if the bindings are added or
  243. * removed later is not defined. The contents of the subcontexts are not
  244. * included.
  245. *
  246. * @param name the name of the subcontext
  247. * @return the enumeration over the names, known for the given subcontext.
  248. * @throws NamingException
  249. */
  250. NamingEnumeration<NameClassPair> list(String name) throws NamingException;
  251. /**
  252. * Creates and returns the enumeration over the name - object bindings that
  253. * are present the given subcontext. The enumeration elements have the type of
  254. * {@link Binding}, providing also information about the class of the bound
  255. * object. The behaviour in the case if the bindings are added or removed
  256. * later is not defined. The contents of the subcontexts are not included.
  257. *
  258. * @param name the name of the subcontext
  259. * @return the enumeration over the names, known for the given subcontext.
  260. * @throws NamingException
  261. */
  262. NamingEnumeration<Binding> listBindings(Name name) throws NamingException;
  263. /**
  264. * Creates and returns the enumeration over the name - object bindings that
  265. * are present the given subcontext. The enumeration elements have the type of
  266. * {@link Binding}, providing also information about the class of the bound
  267. * object. The behaviour in the case if the bindings are added or removed
  268. * later is not defined. The contents of the subcontexts are not included.
  269. *
  270. * @param name the name of the subcontext
  271. * @return the enumeration over the names, known for the given subcontext.
  272. * @throws NamingException
  273. */
  274. NamingEnumeration<Binding> listBindings(String name) throws NamingException;
  275. /**
  276. * Creates the new naming subcontext and binds it to the current (this)
  277. * context.
  278. *
  279. * @param name the name of the new context being created
  280. * @return the newly created context, bound to the instance of the context on
  281. * that the method has been called
  282. * @throws NameAlreadyBoundException if this name is already bound
  283. * @throws InvalidAttributesException if the creation of the new context
  284. * requires the missing mandatory attributes
  285. * @throws NamingException
  286. */
  287. Context createSubcontext(Name name) throws NamingException;
  288. /**
  289. * Creates the new naming subcontext and binds it to the current (this)
  290. * context.
  291. *
  292. * @param name the name of the new context being created
  293. * @return the newly created context, bound to the instance of the context on
  294. * that the method has been called
  295. * @throws NameAlreadyBoundException if this name is already bound
  296. * @throws InvalidAttributesException if the creation of the new context
  297. * requires the missing mandatory attributes
  298. * @throws NamingException
  299. */
  300. Context createSubcontext(String name) throws NamingException;
  301. /**
  302. * Removes the naming subcontext from this naming context. Returns without
  303. * action if such subcontext does not exist. The context being destroyed must
  304. * be empty.
  305. *
  306. * @param name the name of the subcontext beig removed.
  307. * @throws ContextNotEmptyException if the named context is not empty.
  308. * @throws NamingException
  309. */
  310. void destroySubcontext(Name name) throws NamingException;
  311. /**
  312. * Removes the naming subcontext from this naming context. Returns without
  313. * action if such subcontext does not exist. The context being destroyed must
  314. * be empty.
  315. *
  316. * @param name the name of the subcontext beig removed.
  317. * @throws ContextNotEmptyException if the named context is not empty.
  318. * @throws NamingException
  319. */
  320. void destroySubcontext(String name) throws NamingException;
  321. /**
  322. * Retrieves the named object, not following the link of the terminal atomic
  323. * component of the name. If the object, named by the passed name, is not a
  324. * link, returns that object itself. The intermediate links, if present, are
  325. * followed.
  326. *
  327. * @param name the name of the object that may be a link, leading to another
  328. * object.
  329. * @return the named object, not following the terminal link (if present).
  330. * @throws NamingException
  331. */
  332. Object lookupLink(Name name) throws NamingException;
  333. /**
  334. * Retrieves the named object, not following the link of the terminal atomic
  335. * component of the name. If the object, named by the passed name, is not a
  336. * link, returns that object itself. The intermediate links, if present, are
  337. * followed.
  338. *
  339. * @param name the name of the object that may be a link, leading to another
  340. * object.
  341. * @return the named object, not following the terminal link (if present).
  342. * @throws NamingException
  343. */
  344. Object lookupLink(String name) throws NamingException;
  345. /**
  346. * Obtains the name parser for parsing the names of the given naming
  347. * subcontext.
  348. *
  349. * @param name the name of the subcontext for that the parser must be obtained
  350. * @return the parser to parse the names of that context
  351. * @throws NamingException
  352. */
  353. NameParser getNameParser(Name name) throws NamingException;
  354. /**
  355. * Obtains the name parser for parsing the names of the given naming
  356. * subcontext.
  357. *
  358. * @param name the name of the subcontext for that the parser must be obtained
  359. * @return the parser to parse the names of that context
  360. * @throws NamingException
  361. */
  362. NameParser getNameParser(String name) throws NamingException;
  363. /**
  364. * Composes the name of this context together with another name, related to
  365. * this context.
  366. *
  367. * @param name a name, defined in the scope of this context
  368. * @param prefix a name of this context itself, defined in the scope of some
  369. * ancestor
  370. * @return the name of the same object as named by the first parameter, but
  371. * related to the context of the specified ancestor.
  372. * @throws NamingException
  373. */
  374. Name composeName(Name name, Name prefix) throws NamingException;
  375. /**
  376. * Composes the name of this context together with another name, related to
  377. * this context.
  378. *
  379. * @param name a name, defined in the scope of this context
  380. * @param prefix a name of this context itself, defined in the scope of some
  381. * ancestor
  382. * @return the name of the same object as named by the first parameter, but
  383. * related to the context of the specified ancestor.
  384. * @throws NamingException
  385. */
  386. String composeName(String name, String prefix) throws NamingException;
  387. /**
  388. * Add new environment property to the environment of this context. Both name
  389. * and value of the new property must not be null. If the property is already
  390. * defined, is current value is replaced by the propVal.
  391. *
  392. * @param propName the name of the new property
  393. * @param propVal the value of the new property
  394. * @return the previous value of this property or null if the property has not
  395. * been previously defined
  396. * @throws NamingException
  397. */
  398. Object addToEnvironment(String propName, Object propVal)
  399. throws NamingException;
  400. /**
  401. * Removes the property with the given name from the environment. Returns
  402. * without action if this property is not defined.
  403. *
  404. * @param propName the name of the property being removed.
  405. * @return the value of the property that has been removed or null if the
  406. * property was not defined.
  407. * @throws NamingException
  408. */
  409. Object removeFromEnvironment(String propName) throws NamingException;
  410. /**
  411. * Returns the environment, associated with this naming context. The returned
  412. * table should never be modified by the caller. Use {@link #addToEnvironment}
  413. * and {@link #removeFromEnvironment} to modify the environement, if needed.
  414. *
  415. * @return the table, representing the environment of this context
  416. * @throws NamingException
  417. */
  418. Hashtable<?,?> getEnvironment() throws NamingException;
  419. /**
  420. * Releases all resources, associated with this context. The close() method
  421. * can be called several times, but after it has been once invoked, it is not
  422. * allowed to call any other method of this context,
  423. *
  424. * @throws NamingException
  425. */
  426. void close() throws NamingException;
  427. /**
  428. * Returs the full name of this naming context. The returned string is not a
  429. * JNDI composite name and should not be passed directly to the methods of the
  430. * naming context.
  431. *
  432. * @return the full name of this naming context, in its own namespace.
  433. * @throws OperationNotSupportedException if the naming system, represented by
  434. * this context, does not support the notation of the full name.
  435. * @throws NamingException
  436. */
  437. String getNameInNamespace() throws NamingException;
  438. }