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