SearchResult.java revision 0
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright 1999-2000 Sun Microsystems, Inc. All Rights Reserved.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This code is free software; you can redistribute it and/or modify it
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * under the terms of the GNU General Public License version 2 only, as
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * published by the Free Software Foundation. Sun designates this
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * particular file as subject to the "Classpath" exception as provided
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * by Sun in the LICENSE file that accompanied this code.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This code is distributed in the hope that it will be useful, but WITHOUT
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * version 2 for more details (a copy is included in the LICENSE file that
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * accompanied this code).
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License version
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * 2 along with this work; if not, write to the Free Software Foundation,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CA 95054 USA or visit www.sun.com if you need additional information or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * have any questions.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artempackage javax.naming.directory;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artemimport javax.naming.Binding;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This class represents an item in the NamingEnumeration returned as a
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * result of the DirContext.search() methods.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *<p>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * A SearchResult instance is not synchronized against concurrent
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * multithreaded access. Multiple threads trying to access and modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * a single SearchResult instance should lock the object.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @author Rosanna Lee
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @author Scott Seligman
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see DirContext#search
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @since 1.3
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artempublic class SearchResult extends Binding {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Contains the attributes returned with the object.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @serial
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem private Attributes attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Constructs a search result using the result's name, its bound object, and
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * its attributes.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *<p>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (or null if <tt>obj</tt> is null) unless the class name has been
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * explicitly set using <tt>setClassName()</tt>.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param name The non-null name of the search item. It is relative
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * to the <em>target context</em> of the search (which is
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * named by the first parameter of the <code>search()</code> method)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param obj The object bound to name. Can be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param attrs The attributes that were requested to be returned with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this search item. Cannot be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#setClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#getClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public SearchResult(String name, Object obj, Attributes attrs) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem super(name, obj);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem this.attrs = attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Constructs a search result using the result's name, its bound object, and
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * its attributes, and whether the name is relative.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *<p>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (or null if <tt>obj</tt> is null) unless the class name has been
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * explicitly set using <tt>setClassName()</tt>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param name The non-null name of the search item.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param obj The object bound to name. Can be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param attrs The attributes that were requested to be returned with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this search item. Cannot be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param isRelative true if <code>name</code> is relative
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * to the target context of the search (which is named by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the first parameter of the <code>search()</code> method);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * false if <code>name</code> is a URL string.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#setClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#getClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public SearchResult(String name, Object obj, Attributes attrs,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem boolean isRelative) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem super(name, obj, isRelative);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem this.attrs = attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Constructs a search result using the result's name, its class name,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * its bound object, and its attributes.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param name The non-null name of the search item. It is relative
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * to the <em>target context</em> of the search (which is
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * named by the first parameter of the <code>search()</code> method)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param className The possibly null class name of the object
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * <tt>getClassName()</tt> will return null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param obj The object bound to name. Can be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param attrs The attributes that were requested to be returned with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this search item. Cannot be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#setClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#getClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public SearchResult(String name, String className,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem Object obj, Attributes attrs) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem super(name, className, obj);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem this.attrs = attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Constructs a search result using the result's name, its class name,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * its bound object, its attributes, and whether the name is relative.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param name The non-null name of the search item.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param className The possibly null class name of the object
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * <tt>getClassName()</tt> will return null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param obj The object bound to name. Can be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param attrs The attributes that were requested to be returned with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this search item. Cannot be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param isRelative true if <code>name</code> is relative
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * to the target context of the search (which is named by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the first parameter of the <code>search()</code> method);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * false if <code>name</code> is a URL string.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#setClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see javax.naming.NameClassPair#getClassName
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public SearchResult(String name, String className, Object obj,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem Attributes attrs, boolean isRelative) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem super(name, className, obj, isRelative);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem this.attrs = attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Retrieves the attributes in this search result.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return The non-null attributes in this search result. Can be empty.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see #setAttributes
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public Attributes getAttributes() {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Sets the attributes of this search result to <code>attrs</code>.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param attrs The non-null attributes to use. Can be empty.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @see #getAttributes
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public void setAttributes(Attributes attrs) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem this.attrs = attrs;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem // ??? check for null?
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Generates the string representation of this SearchResult.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The string representation consists of the string representation
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * of the binding and the string representation of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this search result's attributes, separated by ':'.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The contents of this string is useful
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * for debugging and is not meant to be interpreted programmatically.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return The string representation of this SearchResult. Cannot be null.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem public String toString() {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return super.toString() + ":" + getAttributes();
18c2aff776a775d34a4c9893a4c72e0434d68e36artem }
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /**
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Use serialVersionUID from JNDI 1.1.1 for interoperability
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem private static final long serialVersionUID = -9158063327699723172L;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem}
18c2aff776a775d34a4c9893a4c72e0434d68e36artem