1. /*
  2. * @(#)DirContext.java 1.8 01/02/09
  3. *
  4. * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming.directory;
  11. import javax.naming.*;
  12. /**
  13. * The directory service interface, containing
  14. * methods for examining and updating attributes
  15. * associated with objects, and for searching the directory.
  16. * <p>
  17. * <h4>Names</h4>
  18. * Each name passed as an argument to a <tt>DirContext</tt> method is relative
  19. * to that context. The empty name is used to name the context itself.
  20. * The name parameter may never be null.
  21. * <p>
  22. * Most of the methods have overloaded versions with one taking a
  23. * <code>Name</code> parameter and one taking a <code>String</code>.
  24. * These overloaded versions are equivalent in that if
  25. * the <code>Name</code> and <code>String</code> parameters are just
  26. * different representations of the same name, then the overloaded
  27. * versions of the same methods behave the same.
  28. * In the method descriptions below, only one version is documented.
  29. * The second version instead has a link to the first: the same
  30. * documentation applies to both.
  31. * <p>
  32. * See <tt>Context</tt> for a discussion on the interpretation of the
  33. * name argument to the <tt>Context</tt> methods. These same rules
  34. * apply to the name argument to the <tt>DirContext</tt> methods.
  35. * <p>
  36. * <h4>Attribute Models</h4>
  37. * There are two basic models of what attributes should be
  38. * associated with. First, attributes may be directly associated with a
  39. * DirContext object.
  40. * In this model, an attribute operation on the named object is
  41. * roughly equivalent
  42. * to a lookup on the name (which returns the DirContext object),
  43. * followed by the attribute operation invoked on the DirContext object
  44. * in which the caller supplies an empty name. The attributes can be viewed
  45. * as being stored along with the object (note that this does not imply that
  46. * the implementation must do so).
  47. * <p>
  48. * The second model is that attributes are associated with a
  49. * name (typically an atomic name) in a DirContext.
  50. * In this model, an attribute operation on the named object is
  51. * roughly equivalent to a lookup on the name of the parent DirContext of the
  52. * named object, followed by the attribute operation invoked on the parent
  53. * in which the caller supplies the terminal atomic name.
  54. * The attributes can be viewed as being stored in the parent DirContext
  55. * (again, this does not imply that the implementation must do so).
  56. * Objects that are not DirContexts can have attributes, as long as
  57. * their parents are DirContexts.
  58. * <p>
  59. * JNDI support both of these models.
  60. * It is up to the individual service providers to decide where to
  61. * "store" attributes.
  62. * JNDI clients are safest when they do not make assumptions about
  63. * whether an object's attributes are stored as part of the object, or stored
  64. * within the parent object and associated with the object's name.
  65. * <p>
  66. * <h4>Attribute Type Names</h4>
  67. * In the <tt>getAttributes()</tt> and <tt>search()</tt> methods,
  68. * you can supply the attributes to return by supplying a list of
  69. * attribute names (strings).
  70. * The attributes that you get back might not have the same names as the
  71. * attribute names you have specified. This is because some directories
  72. * support features that cause them to return other attributes. Such
  73. * features include attribute subclassing, attribute name synonyms, and
  74. * attribute language codes.
  75. * <p>
  76. * In attribute subclassing, attributes are defined in a class hierarchy.
  77. * In some directories, for example, the "name" attribute might be the
  78. * superclass of all name-related attributes, including "commonName" and
  79. * "surName". Asking for the "name" attribute might return both the
  80. * "commonName" and "surName" attributes.
  81. * <p>
  82. * With attribute type synonyms, a directory can assign multiple names to
  83. * the same attribute. For example, "cn" and "commonName" might both
  84. * refer to the same attribute. Asking for "cn" might return the
  85. * "commonName" attribute.
  86. * <p>
  87. * Some directories support the language codes for attributes.
  88. * Asking such a directory for the "description" attribute, for example,
  89. * might return all of the following attributes:
  90. * <ul>
  91. * <li>description
  92. * <li>description;lang-en
  93. * <li>description;lang-de
  94. * <li>description;lang-fr
  95. * </ul>
  96. *
  97. * <p>
  98. *<h4>Operational Attributes</h4>
  99. *<p>
  100. * Some directories have the notion of "operational attributes" which are
  101. * attributes associated with a directory object for administrative
  102. * purposes. An example of operational attributes is the access control
  103. * list for an object.
  104. * <p>
  105. * In the <tt>getAttributes()</tt> and <tt>search()</tt> methods,
  106. * you can specify that all attributes associated with the requested objects
  107. * be returned by supply <tt>null</tt> as the list of attributes to return.
  108. * The attributes returned do <em>not</em> include operational attributes.
  109. * In order to retrieve operational attributes, you must name them explicitly.
  110. *
  111. * <p>
  112. * <h4>Named Context</h4>
  113. * <p>
  114. * There are certain methods in which the name must resolve to a context
  115. * (for example, when searching a single level context). The documentation
  116. * of such methods
  117. * use the term <em>named context</em> to describe their name parameter.
  118. * For these methods, if the named object is not a DirContext,
  119. * <code>NotContextException</code> is thrown.
  120. * Aside from these methods, there is no requirement that the
  121. * <em>named object</em> be a DirContext.
  122. *<p>
  123. *<h4>Parameters</h4>
  124. *<p>
  125. * An <tt>Attributes</tt>, <tt>SearchControls</tt>, or array object
  126. * passed as a parameter to any method will not be modified by the
  127. * service provider. The service provider may keep a reference to it
  128. * for the duration of the operation, including any enumeration of the
  129. * method's results and the processing of any referrals generated.
  130. * The caller should not modify the object during this time.
  131. * An <tt>Attributes</tt> object returned by any method is owned by
  132. * the caller. The caller may subsequently modify it; the service
  133. * provider will not.
  134. *<p>
  135. *<h4>Exceptions</h4>
  136. *<p>
  137. * All the methods in this interface can throw a NamingException or
  138. * any of its subclasses. See NamingException and their subclasses
  139. * for details on each exception.
  140. *
  141. * @author Rosanna Lee
  142. * @author Scott Seligman
  143. * @author R. Vasudevan
  144. * @version 1.8 01/02/09
  145. *
  146. * @see javax.naming.Context
  147. * @since 1.3
  148. */
  149. public interface DirContext extends Context {
  150. /**
  151. * Retrieves all of the attributes associated with a named object.
  152. * See the class description regarding attribute models, attribute
  153. * type names, and operational attributes.
  154. *
  155. * @param name
  156. * the name of the object from which to retrieve attributes
  157. * @return the set of attributes associated with <code>name</code>.
  158. * Returns an empty attribute set if name has no attributes;
  159. * never null.
  160. * @throws NamingException if a naming exception is encountered
  161. *
  162. * @see #getAttributes(String)
  163. * @see #getAttributes(Name, String[])
  164. */
  165. public Attributes getAttributes(Name name) throws NamingException;
  166. /**
  167. * Retrieves all of the attributes associated with a named object.
  168. * See {@link #getAttributes(Name)} for details.
  169. *
  170. * @param name
  171. * the name of the object from which to retrieve attributes
  172. * @return the set of attributes associated with <code>name</code>
  173. *
  174. * @throws NamingException if a naming exception is encountered
  175. */
  176. public Attributes getAttributes(String name) throws NamingException;
  177. /**
  178. * Retrieves selected attributes associated with a named object.
  179. * See the class description regarding attribute models, attribute
  180. * type names, and operational attributes.
  181. *
  182. * <p> If the object does not have an attribute
  183. * specified, the directory will ignore the nonexistent attribute
  184. * and return those requested attributes that the object does have.
  185. *
  186. * <p> A directory might return more attributes than was requested
  187. * (see <strong>Attribute Type Names</strong> in the class description),
  188. * but is not allowed to return arbitrary, unrelated attributes.
  189. *
  190. * <p> See also <strong>Operational Attributes</strong> in the class
  191. * description.
  192. *
  193. * @param name
  194. * the name of the object from which to retrieve attributes
  195. * @param attrIds
  196. * the identifiers of the attributes to retrieve.
  197. * null indicates that all attributes should be retrieved;
  198. * an empty array indicates that none should be retrieved.
  199. * @return the requested attributes; never null
  200. *
  201. * @throws NamingException if a naming exception is encountered
  202. */
  203. public Attributes getAttributes(Name name, String[] attrIds)
  204. throws NamingException;
  205. /**
  206. * Retrieves selected attributes associated with a named object.
  207. * See {@link #getAttributes(Name, String[])} for details.
  208. *
  209. * @param name
  210. * The name of the object from which to retrieve attributes
  211. * @param attrIds
  212. * the identifiers of the attributes to retrieve.
  213. * null indicates that all attributes should be retrieved;
  214. * an empty array indicates that none should be retrieved.
  215. * @return the requested attributes; never null
  216. *
  217. * @throws NamingException if a naming exception is encountered
  218. */
  219. public Attributes getAttributes(String name, String[] attrIds)
  220. throws NamingException;
  221. /**
  222. * This constant specifies to add an attribute with the specified values.
  223. * <p>
  224. * If attribute does not exist,
  225. * create the attribute. The resulting attribute has a union of the
  226. * specified value set and the prior value set.
  227. * Adding an attribute with no value will throw
  228. * <code>InvalidAttributeValueException</code> if the attribute must have
  229. * at least one value. For a single-valued attribute where that attribute
  230. * already exists, throws <code>AttributeInUseException</code>.
  231. * If attempting to add more than one value to a single-valued attribute,
  232. * throws <code>InvalidAttributeValueException</code>.
  233. * <p>
  234. * The value of this constant is <tt>1</tt>.
  235. *
  236. * @see ModificationItem
  237. * @see #modifyAttributes
  238. */
  239. public final static int ADD_ATTRIBUTE = 1;
  240. /**
  241. * This constant specifies to replace an attribute with specified values.
  242. *<p>
  243. * If attribute already exists,
  244. * replaces all existing values with new specified values. If the
  245. * attribute does not exist, creates it. If no value is specified,
  246. * deletes all the values of the attribute.
  247. * Removal of the last value will remove the attribute if the attribute
  248. * is required to have at least one value. If
  249. * attempting to add more than one value to a single-valued attribute,
  250. * throws <code>InvalidAttributeValueException</code>.
  251. * <p>
  252. * The value of this constant is <tt>2</tt>.
  253. *
  254. * @see ModificationItem
  255. * @see #modifyAttributes
  256. */
  257. public final static int REPLACE_ATTRIBUTE = 2;
  258. /**
  259. * This constant specifies to delete
  260. * the specified attribute values from the attribute.
  261. *<p>
  262. * The resulting attribute has the set difference of its prior value set
  263. * and the specified value set.
  264. * If no values are specified, deletes the entire attribute.
  265. * If the attribute does not exist, or if some or all members of the
  266. * specified value set do not exist, this absence may be ignored
  267. * and the operation succeeds, or a NamingException may be thrown to
  268. * indicate the absence.
  269. * Removal of the last value will remove the attribute if the
  270. * attribute is required to have at least one value.
  271. * <p>
  272. * The value of this constant is <tt>3</tt>.
  273. *
  274. * @see ModificationItem
  275. * @see #modifyAttributes
  276. */
  277. public final static int REMOVE_ATTRIBUTE = 3;
  278. /**
  279. * Modifies the attributes associated with a named object.
  280. * The order of the modifications is not specified. Where
  281. * possible, the modifications are performed atomically.
  282. *
  283. * @param name
  284. * the name of the object whose attributes will be updated
  285. * @param mod_op
  286. * the modification operation, one of:
  287. * <code>ADD_ATTRIBUTE</code>,
  288. * <code>REPLACE_ATTRIBUTE</code>,
  289. * <code>REMOVE_ATTRIBUTE</code>.
  290. * @param attrs
  291. * the attributes to be used for the modification; may not be null
  292. *
  293. * @throws AttributeModificationException if the modification cannot
  294. * be completed successfully
  295. * @throws NamingException if a naming exception is encountered
  296. *
  297. * @see #modifyAttributes(Name, ModificationItem[])
  298. */
  299. public void modifyAttributes(Name name, int mod_op, Attributes attrs)
  300. throws NamingException;
  301. /**
  302. * Modifies the attributes associated with a named object.
  303. * See {@link #modifyAttributes(Name, int, Attributes)} for details.
  304. *
  305. * @param name
  306. * the name of the object whose attributes will be updated
  307. * @param mod_op
  308. * the modification operation, one of:
  309. * <code>ADD_ATTRIBUTE</code>,
  310. * <code>REPLACE_ATTRIBUTE</code>,
  311. * <code>REMOVE_ATTRIBUTE</code>.
  312. * @param attrs
  313. * the attributes to be used for the modification; map not be null
  314. *
  315. * @throws AttributeModificationException if the modification cannot
  316. * be completed successfully
  317. * @throws NamingException if a naming exception is encountered
  318. */
  319. public void modifyAttributes(String name, int mod_op, Attributes attrs)
  320. throws NamingException;
  321. /**
  322. * Modifies the attributes associated with a named object using
  323. * an ordered list of modifications.
  324. * The modifications are performed
  325. * in the order specified. Each modification specifies a
  326. * modification operation code and an attribute on which to
  327. * operate. Where possible, the modifications are
  328. * performed atomically.
  329. *
  330. * @param name
  331. * the name of the object whose attributes will be updated
  332. * @param mods
  333. * an ordered sequence of modifications to be performed;
  334. * may not be null
  335. *
  336. * @throws AttributeModificationException if the modifications
  337. * cannot be completed successfully
  338. * @throws NamingException if a naming exception is encountered
  339. *
  340. * @see #modifyAttributes(Name, int, Attributes)
  341. * @see ModificationItem
  342. */
  343. public void modifyAttributes(Name name, ModificationItem[] mods)
  344. throws NamingException;
  345. /**
  346. * Modifies the attributes associated with a named object using
  347. * an ordered list of modifications.
  348. * See {@link #modifyAttributes(Name, ModificationItem[])} for details.
  349. *
  350. * @param name
  351. * the name of the object whose attributes will be updated
  352. * @param mods
  353. * an ordered sequence of modifications to be performed;
  354. * may not be null
  355. *
  356. * @throws AttributeModificationException if the modifications
  357. * cannot be completed successfully
  358. * @throws NamingException if a naming exception is encountered
  359. */
  360. public void modifyAttributes(String name, ModificationItem[] mods)
  361. throws NamingException;
  362. /**
  363. * Binds a name to an object, along with associated attributes.
  364. * If <tt>attrs</tt> is null, the resulting binding will have
  365. * the attributes associated with <tt>obj</tt> if <tt>obj</tt> is a
  366. * <tt>DirContext</tt>, and no attributes otherwise.
  367. * If <tt>attrs</tt> is non-null, the resulting binding will have
  368. * <tt>attrs</tt> as its attributes; any attributes associated with
  369. * <tt>obj</tt> are ignored.
  370. *
  371. * @param name
  372. * the name to bind; may not be empty
  373. * @param obj
  374. * the object to bind; possibly null
  375. * @param attrs
  376. * the attributes to associate with the binding
  377. *
  378. * @throws NameAlreadyBoundException if name is already bound
  379. * @throws InvalidAttributesException if some "mandatory" attributes
  380. * of the binding are not supplied
  381. * @throws NamingException if a naming exception is encountered
  382. *
  383. * @see Context#bind(Name, Object)
  384. * @see #rebind(Name, Object, Attributes)
  385. */
  386. public void bind(Name name, Object obj, Attributes attrs)
  387. throws NamingException;
  388. /**
  389. * Binds a name to an object, along with associated attributes.
  390. * See {@link #bind(Name, Object, Attributes)} for details.
  391. *
  392. * @param name
  393. * the name to bind; may not be empty
  394. * @param obj
  395. * the object to bind; possibly null
  396. * @param attrs
  397. * the attributes to associate with the binding
  398. *
  399. * @throws NameAlreadyBoundException if name is already bound
  400. * @throws InvalidAttributesException if some "mandatory" attributes
  401. * of the binding are not supplied
  402. * @throws NamingException if a naming exception is encountered
  403. */
  404. public void bind(String name, Object obj, Attributes attrs)
  405. throws NamingException;
  406. /**
  407. * Binds a name to an object, along with associated attributes,
  408. * overwriting any existing binding.
  409. * If <tt>attrs</tt> is null and <tt>obj</tt> is a <tt>DirContext</tt>,
  410. * the attributes from <tt>obj</tt> are used.
  411. * If <tt>attrs</tt> is null and <tt>obj</tt> is not a <tt>DirContext</tt>,
  412. * any existing attributes associated with the object already bound
  413. * in the directory remain unchanged.
  414. * If <tt>attrs</tt> is non-null, any existing attributes associated with
  415. * the object already bound in the directory are removed and <tt>attrs</tt>
  416. * is associated with the named object. If <tt>obj</tt> is a
  417. * <tt>DirContext</tt> and <tt>attrs</tt> is non-null, the attributes
  418. * of <tt>obj</tt> are ignored.
  419. *
  420. * @param name
  421. * the name to bind; may not be empty
  422. * @param obj
  423. * the object to bind; possibly null
  424. * @param attrs
  425. * the attributes to associate with the binding
  426. *
  427. * @throws InvalidAttributesException if some "mandatory" attributes
  428. * of the binding are not supplied
  429. * @throws NamingException if a naming exception is encountered
  430. *
  431. * @see Context#bind(Name, Object)
  432. * @see #bind(Name, Object, Attributes)
  433. */
  434. public void rebind(Name name, Object obj, Attributes attrs)
  435. throws NamingException;
  436. /**
  437. * Binds a name to an object, along with associated attributes,
  438. * overwriting any existing binding.
  439. * See {@link #rebind(Name, Object, Attributes)} for details.
  440. *
  441. * @param name
  442. * the name to bind; may not be empty
  443. * @param obj
  444. * the object to bind; possibly null
  445. * @param attrs
  446. * the attributes to associate with the binding
  447. *
  448. * @throws InvalidAttributesException if some "mandatory" attributes
  449. * of the binding are not supplied
  450. * @throws NamingException if a naming exception is encountered
  451. */
  452. public void rebind(String name, Object obj, Attributes attrs)
  453. throws NamingException;
  454. /**
  455. * Creates and binds a new context, along with associated attributes.
  456. * This method creates a new subcontext with the given name, binds it in
  457. * the target context (that named by all but terminal atomic
  458. * component of the name), and associates the supplied attributes
  459. * with the newly created object.
  460. * All intermediate and target contexts must already exist.
  461. * If <tt>attrs</tt> is null, this method is equivalent to
  462. * <tt>Context.createSubcontext()</tt>.
  463. *
  464. * @param name
  465. * the name of the context to create; may not be empty
  466. * @param attrs
  467. * the attributes to associate with the newly created context
  468. * @return the newly created context
  469. *
  470. * @throws NameAlreadyBoundException if the name is already bound
  471. * @throws InvalidAttributesException if <code>attrs</code> does not
  472. * contain all the mandatory attributes required for creation
  473. * @throws NamingException if a naming exception is encountered
  474. *
  475. * @see Context#createSubcontext(Name)
  476. */
  477. public DirContext createSubcontext(Name name, Attributes attrs)
  478. throws NamingException;
  479. /**
  480. * Creates and binds a new context, along with associated attributes.
  481. * See {@link #createSubcontext(Name, Attributes)} for details.
  482. *
  483. * @param name
  484. * the name of the context to create; may not be empty
  485. * @param attrs
  486. * the attributes to associate with the newly created context
  487. * @return the newly created context
  488. *
  489. * @throws NameAlreadyBoundException if the name is already bound
  490. * @throws InvalidAttributesException if <code>attrs</code> does not
  491. * contain all the mandatory attributes required for creation
  492. * @throws NamingException if a naming exception is encountered
  493. */
  494. public DirContext createSubcontext(String name, Attributes attrs)
  495. throws NamingException;
  496. // -------------------- schema operations
  497. /**
  498. * Retrieves the schema associated with the named object.
  499. * The schema describes rules regarding the structure of the namespace
  500. * and the attributes stored within it. The schema
  501. * specifies what types of objects can be added to the directory and where
  502. * they can be added; what mandatory and optional attributes an object
  503. * can have. The range of support for schemas is directory-specific.
  504. *
  505. * <p> This method returns the root of the schema information tree
  506. * that is applicable to the named object. Several named objects
  507. * (or even an entire directory) might share the same schema.
  508. *
  509. * <p> Issues such as structure and contents of the schema tree,
  510. * permission to modify to the contents of the schema
  511. * tree, and the effect of such modifications on the directory
  512. * are dependent on the underlying directory.
  513. *
  514. * @param name
  515. * the name of the object whose schema is to be retrieved
  516. * @return the schema associated with the context; never null
  517. * @throws OperationNotSupportedException if schema not supported
  518. * @throws NamingException if a naming exception is encountered
  519. */
  520. public DirContext getSchema(Name name) throws NamingException;
  521. /**
  522. * Retrieves the schema associated with the named object.
  523. * See {@link #getSchema(Name)} for details.
  524. *
  525. * @param name
  526. * the name of the object whose schema is to be retrieved
  527. * @return the schema associated with the context; never null
  528. * @throws OperationNotSupportedException if schema not supported
  529. * @throws NamingException if a naming exception is encountered
  530. */
  531. public DirContext getSchema(String name) throws NamingException;
  532. /**
  533. * Retrieves a context containing the schema objects of the
  534. * named object's class definitions.
  535. *<p>
  536. * One category of information found in directory schemas is
  537. * <em>class definitions</em>. An "object class" definition
  538. * specifies the object's <em>type</em> and what attributes (mandatory
  539. * and optional) the object must/can have. Note that the term
  540. * "object class" being referred to here is in the directory sense
  541. * rather than in the Java sense.
  542. * For example, if the named object is a directory object of
  543. * "Person" class, <tt>getSchemaClassDefinition()</tt> would return a
  544. * <tt>DirContext</tt> representing the (directory's) object class
  545. * definition of "Person".
  546. *<p>
  547. * The information that can be retrieved from an object class definition
  548. * is directory-dependent.
  549. *<p>
  550. * Prior to JNDI 1.2, this method
  551. * returned a single schema object representing the class definition of
  552. * the named object.
  553. * Since JNDI 1.2, this method returns a <tt>DirContext</tt> containing
  554. * all of the named object's class definitions.
  555. *
  556. * @param name
  557. * the name of the object whose object class
  558. * definition is to be retrieved
  559. * @return the <tt>DirContext</tt> containing the named
  560. * object's class definitions; never null
  561. *
  562. * @throws OperationNotSupportedException if schema not supported
  563. * @throws NamingException if a naming exception is encountered
  564. */
  565. public DirContext getSchemaClassDefinition(Name name)
  566. throws NamingException;
  567. /**
  568. * Retrieves a context containing the schema objects of the
  569. * named object's class definitions.
  570. * See {@link #getSchemaClassDefinition(Name)} for details.
  571. *
  572. * @param name
  573. * the name of the object whose object class
  574. * definition is to be retrieved
  575. * @return the <tt>DirContext</tt> containing the named
  576. * object's class definitions; never null
  577. *
  578. * @throws OperationNotSupportedException if schema not supported
  579. * @throws NamingException if a naming exception is encountered
  580. */
  581. public DirContext getSchemaClassDefinition(String name)
  582. throws NamingException;
  583. // -------------------- search operations
  584. /**
  585. * Searches in a single context for objects that contain a
  586. * specified set of attributes, and retrieves selected attributes.
  587. * The search is performed using the default
  588. * <code>SearchControls</code> settings.
  589. * <p>
  590. * For an object to be selected, each attribute in
  591. * <code>matchingAttributes</code> must match some attribute of the
  592. * object. If <code>matchingAttributes</code> is empty or
  593. * null, all objects in the target context are returned.
  594. *<p>
  595. * An attribute <em>A</em><sub>1</sub> in
  596. * <code>matchingAttributes</code> is considered to match an
  597. * attribute <em>A</em><sub>2</sub> of an object if
  598. * <em>A</em><sub>1</sub> and <em>A</em><sub>2</sub> have the same
  599. * identifier, and each value of <em>A</em><sub>1</sub> is equal
  600. * to some value of <em>A</em><sub>2</sub>. This implies that the
  601. * order of values is not significant, and that
  602. * <em>A</em><sub>2</sub> may contain "extra" values not found in
  603. * <em>A</em><sub>1</sub> without affecting the comparison. It
  604. * also implies that if <em>A</em><sub>1</sub> has no values, then
  605. * testing for a match is equivalent to testing for the presence
  606. * of an attribute <em>A</em><sub>2</sub> with the same
  607. * identifier.
  608. *<p>
  609. * The precise definition of "equality" used in comparing attribute values
  610. * is defined by the underlying directory service. It might use the
  611. * <code>Object.equals</code> method, for example, or might use a schema
  612. * to specify a different equality operation.
  613. * For matching based on operations other than equality (such as
  614. * substring comparison) use the version of the <code>search</code>
  615. * method that takes a filter argument.
  616. * <p>
  617. * When changes are made to this <tt>DirContext</tt>,
  618. * the effect on enumerations returned by prior calls to this method
  619. * is undefined.
  620. *<p>
  621. * If the object does not have the attribute
  622. * specified, the directory will ignore the nonexistent attribute
  623. * and return the requested attributes that the object does have.
  624. *<p>
  625. * A directory might return more attributes than was requested
  626. * (see <strong>Attribute Type Names</strong> in the class description),
  627. * but is not allowed to return arbitrary, unrelated attributes.
  628. *<p>
  629. * See also <strong>Operational Attributes</strong> in the class
  630. * description.
  631. *
  632. * @param name
  633. * the name of the context to search
  634. * @param matchingAttributes
  635. * the attributes to search for. If empty or null,
  636. * all objects in the target context are returned.
  637. * @param attributesToReturn
  638. * the attributes to return. null indicates that
  639. * all attributes are to be returned;
  640. * an empty array indicates that none are to be returned.
  641. * @return
  642. * a non-null enumeration of <tt>SearchResult</tt> objects.
  643. * Each <tt>SearchResult</tt> contains the attributes
  644. * identified by <code>attributesToReturn</code>
  645. * and the name of the corresponding object, named relative
  646. * to the context named by <code>name</code>.
  647. * @throws NamingException if a naming exception is encountered
  648. *
  649. * @see SearchControls
  650. * @see SearchResult
  651. * @see #search(Name, String, Object[], SearchControls)
  652. */
  653. public NamingEnumeration search(Name name,
  654. Attributes matchingAttributes,
  655. String[] attributesToReturn)
  656. throws NamingException;
  657. /**
  658. * Searches in a single context for objects that contain a
  659. * specified set of attributes, and retrieves selected attributes.
  660. * See {@link #search(Name, Attributes, String[])} for details.
  661. *
  662. * @param name
  663. * the name of the context to search
  664. * @param matchingAttributes
  665. * the attributes to search for
  666. * @param attributesToReturn
  667. * the attributes to return
  668. * @return a non-null enumeration of <tt>SearchResult</tt> objects
  669. * @throws NamingException if a naming exception is encountered
  670. */
  671. public NamingEnumeration search(String name,
  672. Attributes matchingAttributes,
  673. String[] attributesToReturn)
  674. throws NamingException;
  675. /**
  676. * Searches in a single context for objects that contain a
  677. * specified set of attributes.
  678. * This method returns all the attributes of such objects.
  679. * It is equivalent to supplying null as
  680. * the <tt>atributesToReturn</tt> parameter to the method
  681. * <code>search(Name, Attributes, String[])</code>.
  682. * <br>
  683. * See {@link #search(Name, Attributes, String[])} for a full description.
  684. *
  685. * @param name
  686. * the name of the context to search
  687. * @param matchingAttributes
  688. * the attributes to search for
  689. * @return an enumeration of <tt>SearchResult</tt> objects
  690. * @throws NamingException if a naming exception is encountered
  691. *
  692. * @see #search(Name, Attributes, String[])
  693. */
  694. public NamingEnumeration search(Name name,
  695. Attributes matchingAttributes)
  696. throws NamingException;
  697. /**
  698. * Searches in a single context for objects that contain a
  699. * specified set of attributes.
  700. * See {@link #search(Name, Attributes)} for details.
  701. *
  702. * @param name
  703. * the name of the context to search
  704. * @param matchingAttributes
  705. * the attributes to search for
  706. * @return an enumeration of <tt>SearchResult</tt> objects
  707. * @throws NamingException if a naming exception is encountered
  708. */
  709. public NamingEnumeration search(String name,
  710. Attributes matchingAttributes)
  711. throws NamingException;
  712. /**
  713. * Searches in the named context or object for entries that satisfy the
  714. * given search filter. Performs the search as specified by
  715. * the search controls.
  716. * <p>
  717. * The format and interpretation of <code>filter</code> follows RFC 2254
  718. * with the
  719. * following interpretations for <code>attr</code> and <code>value</code>
  720. * mentioned in the RFC.
  721. * <p>
  722. * <code>attr</code> is the attribute's identifier.
  723. * <p>
  724. * <code>value</code> is the string representation the attribute's value.
  725. * The translation of this string representation into the attribute's value
  726. * is directory-specific.
  727. * <p>
  728. * For the assertion "someCount=127", for example, <code>attr</code>
  729. * is "someCount" and <code>value</code> is "127".
  730. * The provider determines, based on the attribute ID ("someCount")
  731. * (and possibly its schema), that the attribute's value is an integer.
  732. * It then parses the string "127" appropriately.
  733. *<p>
  734. * Any non-ASCII characters in the filter string should be
  735. * represented by the appropriate Java (Unicode) characters, and
  736. * not encoded as UTF-8 octets. Alternately, the
  737. * "backslash-hexcode" notation described in RFC 2254 may be used.
  738. *<p>
  739. * If the directory does not support a string representation of
  740. * some or all of its attributes, the form of <code>search</code> that
  741. * accepts filter arguments in the form of Objects can be used instead.
  742. * The service provider for such a directory would then translate
  743. * the filter arguments to its service-specific representation
  744. * for filter evaluation.
  745. * See <code>search(Name, String, Object[], SearchControls)</code>.
  746. * <p>
  747. * RFC 2254 defines certain operators for the filter, including substring
  748. * matches, equality, approximate match, greater than, less than. These
  749. * operators are mapped to operators with corresponding semantics in the
  750. * underlying directory. For example, for the equals operator, suppose
  751. * the directory has a matching rule defining "equality" of the
  752. * attributes in the filter. This rule would be used for checking
  753. * equality of the attributes specified in the filter with the attributes
  754. * of objects in the directory. Similarly, if the directory has a
  755. * matching rule for ordering, this rule would be used for
  756. * making "greater than" and "less than" comparisons.
  757. *<p>
  758. * Not all of the operators defined in RFC 2254 are applicable to all
  759. * attributes. When an operator is not applicable, the exception
  760. * <code>InvalidSearchFilterException</code> is thrown.
  761. * <p>
  762. * The result is returned in an enumeration of <tt>SearchResult</tt>s.
  763. * Each <tt>SearchResult</tt> contains the name of the object
  764. * and other information about the object (see SearchResult).
  765. * The name is either relative to the target context of the search
  766. * (which is named by the <code>name</code> parameter), or
  767. * it is a URL string. If the target context is included in
  768. * the enumeration (as is possible when
  769. * <code>cons</code> specifies a search scope of
  770. * <code>SearchControls.OBJECT_SCOPE</code> or
  771. * <code>SearchControls.SUBSTREE_SCOPE</code>), its name is the empty
  772. * string. The <tt>SearchResult</tt> may also contain attributes of the
  773. * matching object if the <tt>cons</tt> argument specified that attributes
  774. * be returned.
  775. *<p>
  776. * If the object does not have a requested attribute, that
  777. * nonexistent attribute will be ignored. Those requested
  778. * attributes that the object does have will be returned.
  779. *<p>
  780. * A directory might return more attributes than were requested
  781. * (see <strong>Attribute Type Names</strong> in the class description)
  782. * but is not allowed to return arbitrary, unrelated attributes.
  783. *<p>
  784. * See also <strong>Operational Attributes</strong> in the class
  785. * description.
  786. *
  787. * @param name
  788. * the name of the context or object to search
  789. * @param filter
  790. * the filter expression to use for the search; may not be null
  791. * @param cons
  792. * the search controls that control the search. If null,
  793. * the default search controls are used (equivalent
  794. * to <tt>(new SearchControls())</tt>).
  795. * @return an enumeration of <tt>SearchResult</tt>s of
  796. * the objects that satisfy the filter; never null
  797. *
  798. * @throws InvalidSearchFilterException if the search filter specified is
  799. * not supported or understood by the underlying directory
  800. * @throws InvalidSearchControlsException if the search controls
  801. * contain invalid settings
  802. * @throws NamingException if a naming exception is encountered
  803. *
  804. * @see #search(Name, String, Object[], SearchControls)
  805. * @see SearchControls
  806. * @see SearchResult
  807. */
  808. public NamingEnumeration search(Name name,
  809. String filter,
  810. SearchControls cons)
  811. throws NamingException;
  812. /**
  813. * Searches in the named context or object for entries that satisfy the
  814. * given search filter. Performs the search as specified by
  815. * the search controls.
  816. * See {@link #search(Name, String, SearchControls)} for details.
  817. *
  818. * @param name
  819. * the name of the context or object to search
  820. * @param filter
  821. * the filter expression to use for the search; may not be null
  822. * @param cons
  823. * the search controls that control the search. If null,
  824. * the default search controls are used (equivalent
  825. * to <tt>(new SearchControls())</tt>).
  826. *
  827. * @return an enumeration of <tt>SearchResult</tt>s for
  828. * the objects that satisfy the filter.
  829. * @throws InvalidSearchFilterException if the search filter specified is
  830. * not supported or understood by the underlying directory
  831. * @throws InvalidSearchControlsException if the search controls
  832. * contain invalid settings
  833. * @throws NamingException if a naming exception is encountered
  834. */
  835. public NamingEnumeration search(String name,
  836. String filter,
  837. SearchControls cons)
  838. throws NamingException;
  839. /**
  840. * Searches in the named context or object for entries that satisfy the
  841. * given search filter. Performs the search as specified by
  842. * the search controls.
  843. *<p>
  844. * The interpretation of <code>filterExpr</code> is based on RFC
  845. * 2254. It may additionally contain variables of the form
  846. * <code>{i}</code> -- where <code>i</code> is an integer -- that
  847. * refer to objects in the <code>filterArgs</code> array. The
  848. * interpretation of <code>filterExpr</code> is otherwise
  849. * identical to that of the <code>filter</code> parameter of the
  850. * method <code>search(Name, String, SearchControls)</code>.
  851. *<p>
  852. * When a variable <code>{i}</code> appears in a search filter, it
  853. * indicates that the filter argument <code>filterArgs[i]</code>
  854. * is to be used in that place. Such variables may be used
  855. * wherever an <em>attr</em>, <em>value</em>, or
  856. * <em>matchingrule</em> production appears in the filter grammar
  857. * of RFC 2254, section 4. When a string-valued filter argument
  858. * is substituted for a variable, the filter is interpreted as if
  859. * the string were given in place of the variable, with any
  860. * characters having special significance within filters (such as
  861. * <code>'*'</code>) having been escaped according to the rules of
  862. * RFC 2254.
  863. *<p>
  864. * For directories that do not use a string representation for
  865. * some or all of their attributes, the filter argument
  866. * corresponding to an attribute value may be of a type other than
  867. * String. Directories that support unstructured binary-valued
  868. * attributes, for example, should accept byte arrays as filter
  869. * arguments. The interpretation (if any) of filter arguments of
  870. * any other type is determined by the service provider for that
  871. * directory, which maps the filter operations onto operations with
  872. * corresponding semantics in the underlying directory.
  873. *<p>
  874. * This method returns an enumeration of the results.
  875. * Each element in the enumeration contains the name of the object
  876. * and other information about the object (see <code>SearchResult</code>).
  877. * The name is either relative to the target context of the search
  878. * (which is named by the <code>name</code> parameter), or
  879. * it is a URL string. If the target context is included in
  880. * the enumeration (as is possible when
  881. * <code>cons</code> specifies a search scope of
  882. * <code>SearchControls.OBJECT_SCOPE</code> or
  883. * <code>SearchControls.SUBSTREE_SCOPE</code>),
  884. * its name is the empty string.
  885. *<p>
  886. * The <tt>SearchResult</tt> may also contain attributes of the matching
  887. * object if the <tt>cons</tt> argument specifies that attributes be
  888. * returned.
  889. *<p>
  890. * If the object does not have a requested attribute, that
  891. * nonexistent attribute will be ignored. Those requested
  892. * attributes that the object does have will be returned.
  893. *<p>
  894. * A directory might return more attributes than were requested
  895. * (see <strong>Attribute Type Names</strong> in the class description)
  896. * but is not allowed to return arbitrary, unrelated attributes.
  897. *<p>
  898. * If a search filter with invalid variable substitutions is provided
  899. * to this method, the result is undefined.
  900. * When changes are made to this DirContext,
  901. * the effect on enumerations returned by prior calls to this method
  902. * is undefined.
  903. *<p>
  904. * See also <strong>Operational Attributes</strong> in the class
  905. * description.
  906. *
  907. * @param name
  908. * the name of the context or object to search
  909. * @param filterExpr
  910. * the filter expression to use for the search.
  911. * The expression may contain variables of the
  912. * form "<code>{i}</code>" where <code>i</code>
  913. * is a nonnegative integer. May not be null.
  914. * @param filterArgs
  915. * the array of arguments to substitute for the variables
  916. * in <code>filterExpr</code>. The value of
  917. * <code>filterArgs[i]</code> will replace each
  918. * occurrence of "<code>{i}</code>".
  919. * If null, equivalent to an empty array.
  920. * @param cons
  921. * the search controls that control the search. If null,
  922. * the default search controls are used (equivalent
  923. * to <tt>(new SearchControls())</tt>).
  924. * @return an enumeration of <tt>SearchResult</tt>s of the objects
  925. * that satisfy the filter; never null
  926. *
  927. * @throws ArrayIndexOutOfBoundsException if <tt>filterExpr</tt> contains
  928. * <code>{i}</code> expressions where <code>i</code> is outside
  929. * the bounds of the array <code>filterArgs</code>
  930. * @throws InvalidSearchControlsException if <tt>cons</tt> contains
  931. * invalid settings
  932. * @throws InvalidSearchFilterException if <tt>filterExpr</tt> with
  933. * <tt>filterArgs</tt> represents an invalid search filter
  934. * @throws NamingException if a naming exception is encountered
  935. *
  936. * @see #search(Name, Attributes, String[])
  937. * @see java.text.MessageFormat
  938. */
  939. public NamingEnumeration search(Name name,
  940. String filterExpr,
  941. Object[] filterArgs,
  942. SearchControls cons)
  943. throws NamingException;
  944. /**
  945. * Searches in the named context or object for entries that satisfy the
  946. * given search filter. Performs the search as specified by
  947. * the search controls.
  948. * See {@link #search(Name, String, Object[], SearchControls)} for details.
  949. *
  950. * @param name
  951. * the name of the context or object to search
  952. * @param filterExpr
  953. * the filter expression to use for the search.
  954. * The expression may contain variables of the
  955. * form "<code>{i}</code>" where <code>i</code>
  956. * is a nonnegative integer. May not be null.
  957. * @param filterArgs
  958. * the array of arguments to substitute for the variables
  959. * in <code>filterExpr</code>. The value of
  960. * <code>filterArgs[i]</code> will replace each
  961. * occurrence of "<code>{i}</code>".
  962. * If null, equivalent to an empty array.
  963. * @param cons
  964. * the search controls that control the search. If null,
  965. * the default search controls are used (equivalent
  966. * to <tt>(new SearchControls())</tt>).
  967. * @return an enumeration of <tt>SearchResult</tt>s of the objects
  968. * that satisfy the filter; never null
  969. *
  970. * @throws ArrayIndexOutOfBoundsException if <tt>filterExpr</tt> contains
  971. * <code>{i}</code> expressions where <code>i</code> is outside
  972. * the bounds of the array <code>filterArgs</code>
  973. * @throws InvalidSearchControlsException if <tt>cons</tt> contains
  974. * invalid settings
  975. * @throws InvalidSearchFilterException if <tt>filterExpr</tt> with
  976. * <tt>filterArgs</tt> represents an invalid search filter
  977. * @throws NamingException if a naming exception is encountered
  978. */
  979. public NamingEnumeration search(String name,
  980. String filterExpr,
  981. Object[] filterArgs,
  982. SearchControls cons)
  983. throws NamingException;
  984. }