1. /*
  2. * @(#)SearchResult.java 1.7 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.Binding;
  12. /**
  13. * This class represents an item in the NamingEnumeration returned as a
  14. * result of the DirContext.search() methods.
  15. *<p>
  16. * A SearchResult instance is not synchronized against concurrent
  17. * multithreaded access. Multiple threads trying to access and modify
  18. * a single SearchResult instance should lock the object.
  19. *
  20. * @author Rosanna Lee
  21. * @author Scott Seligman
  22. * @version 1.7 01/02/09
  23. *
  24. * @see DirContext#search
  25. * @since 1.3
  26. */
  27. public class SearchResult extends Binding {
  28. /**
  29. * Contains the attributes returned with the object.
  30. * @serial
  31. */
  32. private Attributes attrs;
  33. /**
  34. * Constructs a search result using the result's name, its bound object, and
  35. * its attributes.
  36. *<p>
  37. * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
  38. * (or null if <tt>obj</tt> is null) unless the class name has been
  39. * explicitly set using <tt>setClassName()</tt>.
  40. *
  41. * @param name The non-null name of the search item. It is relative
  42. * to the <em>target context</em> of the search (which is
  43. * named by the first parameter of the <code>search()</code> method)
  44. *
  45. * @param obj The object bound to name. Can be null.
  46. * @param attrs The attributes that were requested to be returned with
  47. * this search item. Cannot be null.
  48. * @see javax.naming.NameClassPair#setClassName
  49. * @see javax.naming.NameClassPair#getClassName
  50. */
  51. public SearchResult(String name, Object obj, Attributes attrs) {
  52. super(name, obj);
  53. this.attrs = attrs;
  54. }
  55. /**
  56. * Constructs a search result using the result's name, its bound object, and
  57. * its attributes, and whether the name is relative.
  58. *<p>
  59. * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
  60. * (or null if <tt>obj</tt> is null) unless the class name has been
  61. * explicitly set using <tt>setClassName()</tt>
  62. *
  63. * @param name The non-null name of the search item.
  64. * @param obj The object bound to name. Can be null.
  65. * @param attrs The attributes that were requested to be returned with
  66. * this search item. Cannot be null.
  67. * @param isRelative true if <code>name</code> is relative
  68. * to the target context of the search (which is named by
  69. * the first parameter of the <code>search()</code> method);
  70. * false if <code>name</code> is a URL string.
  71. * @see javax.naming.NameClassPair#setClassName
  72. * @see javax.naming.NameClassPair#getClassName
  73. */
  74. public SearchResult(String name, Object obj, Attributes attrs,
  75. boolean isRelative) {
  76. super(name, obj, isRelative);
  77. this.attrs = attrs;
  78. }
  79. /**
  80. * Constructs a search result using the result's name, its class name,
  81. * its bound object, and its attributes.
  82. *
  83. * @param name The non-null name of the search item. It is relative
  84. * to the <em>target context</em> of the search (which is
  85. * named by the first parameter of the <code>search()</code> method)
  86. *
  87. * @param className The possibly null class name of the object
  88. * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
  89. * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
  90. * <tt>getClassName()</tt> will return null.
  91. * @param obj The object bound to name. Can be null.
  92. * @param attrs The attributes that were requested to be returned with
  93. * this search item. Cannot be null.
  94. * @see javax.naming.NameClassPair#setClassName
  95. * @see javax.naming.NameClassPair#getClassName
  96. */
  97. public SearchResult(String name, String className,
  98. Object obj, Attributes attrs) {
  99. super(name, className, obj);
  100. this.attrs = attrs;
  101. }
  102. /**
  103. * Constructs a search result using the result's name, its class name,
  104. * its bound object, its attributes, and whether the name is relative.
  105. *
  106. * @param name The non-null name of the search item.
  107. * @param className The possibly null class name of the object
  108. * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
  109. * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
  110. * <tt>getClassName()</tt> will return null.
  111. * @param obj The object bound to name. Can be null.
  112. * @param attrs The attributes that were requested to be returned with
  113. * this search item. Cannot be null.
  114. * @param isRelative true if <code>name</code> is relative
  115. * to the target context of the search (which is named by
  116. * the first parameter of the <code>search()</code> method);
  117. * false if <code>name</code> is a URL string.
  118. * @see javax.naming.NameClassPair#setClassName
  119. * @see javax.naming.NameClassPair#getClassName
  120. */
  121. public SearchResult(String name, String className, Object obj,
  122. Attributes attrs, boolean isRelative) {
  123. super(name, className, obj, isRelative);
  124. this.attrs = attrs;
  125. }
  126. /**
  127. * Retrieves the attributes in this search result.
  128. *
  129. * @return The non-null attributes in this search result. Can be empty.
  130. * @see #setAttributes
  131. */
  132. public Attributes getAttributes() {
  133. return attrs;
  134. }
  135. /**
  136. * Sets the attributes of this search result to <code>attrs</code>.
  137. * @param attrs The non-null attributes to use. Can be empty.
  138. * @see #getAttributes
  139. */
  140. public void setAttributes(Attributes attrs) {
  141. this.attrs = attrs;
  142. // ??? check for null?
  143. }
  144. /**
  145. * Generates the string representation of this SearchResult.
  146. * The string representation consists of the string representation
  147. * of the binding and the string representation of
  148. * this search result's attributes, separated by ':'.
  149. * The contents of this string is useful
  150. * for debugging and is not meant to be interpreted programmatically.
  151. *
  152. * @return The string representation of this SearchResult. Cannot be null.
  153. */
  154. public String toString() {
  155. return super.toString() + ":" + getAttributes();
  156. }
  157. /**
  158. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  159. */
  160. private static final long serialVersionUID = -9158063327699723172L;
  161. }