KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > directory > SearchResult


1 /*
2  * @(#)SearchResult.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming.directory;
9
10 import javax.naming.Binding JavaDoc;
11
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.9 03/12/19
23   *
24   * @see DirContext#search
25   * @since 1.3
26   */

27
28 public class SearchResult extends Binding JavaDoc {
29     /**
30      * Contains the attributes returned with the object.
31      * @serial
32      */

33     private Attributes JavaDoc attrs;
34
35     /**
36       * Constructs a search result using the result's name, its bound object, and
37       * its attributes.
38       *<p>
39       * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
40       * (or null if <tt>obj</tt> is null) unless the class name has been
41       * explicitly set using <tt>setClassName()</tt>.
42       *
43       * @param name The non-null name of the search item. It is relative
44       * to the <em>target context</em> of the search (which is
45       * named by the first parameter of the <code>search()</code> method)
46       *
47       * @param obj The object bound to name. Can be null.
48       * @param attrs The attributes that were requested to be returned with
49       * this search item. Cannot be null.
50       * @see javax.naming.NameClassPair#setClassName
51       * @see javax.naming.NameClassPair#getClassName
52       */

53     public SearchResult(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs) {
54     super(name, obj);
55     this.attrs = attrs;
56     }
57
58     /**
59       * Constructs a search result using the result's name, its bound object, and
60       * its attributes, and whether the name is relative.
61       *<p>
62       * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
63       * (or null if <tt>obj</tt> is null) unless the class name has been
64       * explicitly set using <tt>setClassName()</tt>
65       *
66       * @param name The non-null name of the search item.
67       * @param obj The object bound to name. Can be null.
68       * @param attrs The attributes that were requested to be returned with
69       * this search item. Cannot be null.
70       * @param isRelative true if <code>name</code> is relative
71       * to the target context of the search (which is named by
72       * the first parameter of the <code>search()</code> method);
73       * false if <code>name</code> is a URL string.
74       * @see javax.naming.NameClassPair#setClassName
75       * @see javax.naming.NameClassPair#getClassName
76       */

77     public SearchResult(String JavaDoc name, Object JavaDoc obj, Attributes JavaDoc attrs,
78     boolean isRelative) {
79     super(name, obj, isRelative);
80     this.attrs = attrs;
81     }
82
83     /**
84       * Constructs a search result using the result's name, its class name,
85       * its bound object, and its attributes.
86       *
87       * @param name The non-null name of the search item. It is relative
88       * to the <em>target context</em> of the search (which is
89       * named by the first parameter of the <code>search()</code> method)
90       *
91       * @param className The possibly null class name of the object
92       * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
93       * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
94       * <tt>getClassName()</tt> will return null.
95       * @param obj The object bound to name. Can be null.
96       * @param attrs The attributes that were requested to be returned with
97       * this search item. Cannot be null.
98       * @see javax.naming.NameClassPair#setClassName
99       * @see javax.naming.NameClassPair#getClassName
100       */

101     public SearchResult(String JavaDoc name, String JavaDoc className,
102     Object JavaDoc obj, Attributes JavaDoc attrs) {
103     super(name, className, obj);
104     this.attrs = attrs;
105     }
106
107     /**
108       * Constructs a search result using the result's name, its class name,
109       * its bound object, its attributes, and whether the name is relative.
110       *
111       * @param name The non-null name of the search item.
112       * @param className The possibly null class name of the object
113       * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
114       * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
115       * <tt>getClassName()</tt> will return null.
116       * @param obj The object bound to name. Can be null.
117       * @param attrs The attributes that were requested to be returned with
118       * this search item. Cannot be null.
119       * @param isRelative true if <code>name</code> is relative
120       * to the target context of the search (which is named by
121       * the first parameter of the <code>search()</code> method);
122       * false if <code>name</code> is a URL string.
123       * @see javax.naming.NameClassPair#setClassName
124       * @see javax.naming.NameClassPair#getClassName
125       */

126     public SearchResult(String JavaDoc name, String JavaDoc className, Object JavaDoc obj,
127     Attributes JavaDoc attrs, boolean isRelative) {
128     super(name, className, obj, isRelative);
129     this.attrs = attrs;
130     }
131
132     /**
133      * Retrieves the attributes in this search result.
134      *
135      * @return The non-null attributes in this search result. Can be empty.
136      * @see #setAttributes
137      */

138     public Attributes JavaDoc getAttributes() {
139     return attrs;
140     }
141
142
143     /**
144      * Sets the attributes of this search result to <code>attrs</code>.
145      * @param attrs The non-null attributes to use. Can be empty.
146      * @see #getAttributes
147      */

148     public void setAttributes(Attributes JavaDoc attrs) {
149     this.attrs = attrs;
150     // ??? check for null?
151
}
152
153
154     /**
155       * Generates the string representation of this SearchResult.
156       * The string representation consists of the string representation
157       * of the binding and the string representation of
158       * this search result's attributes, separated by ':'.
159       * The contents of this string is useful
160       * for debugging and is not meant to be interpreted programmatically.
161       *
162       * @return The string representation of this SearchResult. Cannot be null.
163       */

164     public String JavaDoc toString() {
165     return super.toString() + ":" + getAttributes();
166     }
167
168     /**
169      * Use serialVersionUID from JNDI 1.1.1 for interoperability
170      */

171     private static final long serialVersionUID = -9158063327699723172L;
172 }
173
Popular Tags