Path: blob/master/src/java.naming/share/classes/javax/naming/directory/SearchResult.java
41159 views
/*1* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.directory;2627import javax.naming.Binding;2829/**30* This class represents an item in the NamingEnumeration returned as a31* result of the DirContext.search() methods.32*<p>33* A SearchResult instance is not synchronized against concurrent34* multithreaded access. Multiple threads trying to access and modify35* a single SearchResult instance should lock the object.36*37* @author Rosanna Lee38* @author Scott Seligman39*40* @see DirContext#search41* @since 1.342*/4344public class SearchResult extends Binding {45/**46* Contains the attributes returned with the object.47* @serial48*/49private Attributes attrs;5051/**52* Constructs a search result using the result's name, its bound object, and53* its attributes.54*<p>55* {@code getClassName()} will return the class name of {@code obj}56* (or null if {@code obj} is null) unless the class name has been57* explicitly set using {@code setClassName()}.58*59* @param name The non-null name of the search item. It is relative60* to the <em>target context</em> of the search (which is61* named by the first parameter of the <code>search()</code> method)62*63* @param obj The object bound to name. Can be null.64* @param attrs The attributes that were requested to be returned with65* this search item. Cannot be null.66* @see javax.naming.NameClassPair#setClassName67* @see javax.naming.NameClassPair#getClassName68*/69public SearchResult(String name, Object obj, Attributes attrs) {70super(name, obj);71this.attrs = attrs;72}7374/**75* Constructs a search result using the result's name, its bound object, and76* its attributes, and whether the name is relative.77*<p>78* {@code getClassName()} will return the class name of {@code obj}79* (or null if {@code obj} is null) unless the class name has been80* explicitly set using {@code setClassName()}81*82* @param name The non-null name of the search item.83* @param obj The object bound to name. Can be null.84* @param attrs The attributes that were requested to be returned with85* this search item. Cannot be null.86* @param isRelative true if <code>name</code> is relative87* to the target context of the search (which is named by88* the first parameter of the <code>search()</code> method);89* false if <code>name</code> is a URL string.90* @see javax.naming.NameClassPair#setClassName91* @see javax.naming.NameClassPair#getClassName92*/93public SearchResult(String name, Object obj, Attributes attrs,94boolean isRelative) {95super(name, obj, isRelative);96this.attrs = attrs;97}9899/**100* Constructs a search result using the result's name, its class name,101* its bound object, and its attributes.102*103* @param name The non-null name of the search item. It is relative104* to the <em>target context</em> of the search (which is105* named by the first parameter of the <code>search()</code> method)106*107* @param className The possibly null class name of the object108* bound to {@code name}. If null, the class name of {@code obj} is109* returned by {@code getClassName()}. If {@code obj} is also null,110* {@code getClassName()} 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 with113* this search item. Cannot be null.114* @see javax.naming.NameClassPair#setClassName115* @see javax.naming.NameClassPair#getClassName116*/117public SearchResult(String name, String className,118Object obj, Attributes attrs) {119super(name, className, obj);120this.attrs = attrs;121}122123/**124* Constructs a search result using the result's name, its class name,125* its bound object, its attributes, and whether the name is relative.126*127* @param name The non-null name of the search item.128* @param className The possibly null class name of the object129* bound to {@code name}. If null, the class name of {@code obj} is130* returned by {@code getClassName()}. If {@code obj} is also null,131* {@code getClassName()} will return null.132* @param obj The object bound to name. Can be null.133* @param attrs The attributes that were requested to be returned with134* this search item. Cannot be null.135* @param isRelative true if <code>name</code> is relative136* to the target context of the search (which is named by137* the first parameter of the <code>search()</code> method);138* false if <code>name</code> is a URL string.139* @see javax.naming.NameClassPair#setClassName140* @see javax.naming.NameClassPair#getClassName141*/142public SearchResult(String name, String className, Object obj,143Attributes attrs, boolean isRelative) {144super(name, className, obj, isRelative);145this.attrs = attrs;146}147148/**149* Retrieves the attributes in this search result.150*151* @return The non-null attributes in this search result. Can be empty.152* @see #setAttributes153*/154public Attributes getAttributes() {155return attrs;156}157158159/**160* Sets the attributes of this search result to <code>attrs</code>.161* @param attrs The non-null attributes to use. Can be empty.162* @see #getAttributes163*/164public void setAttributes(Attributes attrs) {165this.attrs = attrs;166// ??? check for null?167}168169170/**171* Generates the string representation of this SearchResult.172* The string representation consists of the string representation173* of the binding and the string representation of174* this search result's attributes, separated by ':'.175* The contents of this string is useful176* for debugging and is not meant to be interpreted programmatically.177*178* @return The string representation of this SearchResult. Cannot be null.179*/180public String toString() {181return super.toString() + ":" + getAttributes();182}183184/**185* Use serialVersionUID from JNDI 1.1.1 for interoperability186*/187private static final long serialVersionUID = -9158063327699723172L;188}189190191