0N/A/*
2362N/A * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage javax.naming.directory;
0N/A
0N/A/**
0N/A * This class encapsulates
0N/A * factors that determine scope of search and what gets returned
0N/A * as a result of the search.
0N/A *<p>
0N/A * A SearchControls instance is not synchronized against concurrent
0N/A * multithreaded access. Multiple threads trying to access and modify
0N/A * a single SearchControls instance should lock the object.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A * @since 1.3
0N/A */
0N/A
0N/Apublic class SearchControls implements java.io.Serializable {
0N/A /**
0N/A * Search the named object.
0N/A *<p>
0N/A * The NamingEnumeration that results from search()
0N/A * using OBJECT_SCOPE will contain one or zero element.
0N/A * The enumeration contains one element if the named object satisfies
0N/A * the search filter specified in search().
0N/A * The element will have as its name the empty string because the names
0N/A * of elements in the NamingEnumeration are relative to the
0N/A * target context--in this case, the target context is the named object.
0N/A * It contains zero element if the named object does not satisfy
0N/A * the search filter specified in search().
0N/A * <p>
0N/A * The value of this constant is <tt>0</tt>.
0N/A */
0N/A public final static int OBJECT_SCOPE = 0;
0N/A
0N/A /**
0N/A * Search one level of the named context.
0N/A *<p>
0N/A * The NamingEnumeration that results from search()
0N/A * using ONELEVEL_SCOPE contains elements with
0N/A * objects in the named context that satisfy
0N/A * the search filter specified in search().
0N/A * The names of elements in the NamingEnumeration are atomic names
0N/A * relative to the named context.
0N/A * <p>
0N/A * The value of this constant is <tt>1</tt>.
0N/A */
0N/A public final static int ONELEVEL_SCOPE = 1;
0N/A /**
0N/A * Search the entire subtree rooted at the named object.
0N/A *<p>
0N/A * If the named object is not a DirContext, search only the object.
0N/A * If the named object is a DirContext, search the subtree
0N/A * rooted at the named object, including the named object itself.
0N/A *<p>
0N/A * The search will not cross naming system boundaries.
0N/A *<p>
0N/A * The NamingEnumeration that results from search()
0N/A * using SUBTREE_SCOPE contains elements of objects
0N/A * from the subtree (including the named context)
0N/A * that satisfy the search filter specified in search().
0N/A * The names of elements in the NamingEnumeration are either
0N/A * relative to the named context or is a URL string.
0N/A * If the named context satisfies the search filter, it is
0N/A * included in the enumeration with the empty string as
0N/A * its name.
0N/A * <p>
0N/A * The value of this constant is <tt>2</tt>.
0N/A */
0N/A public final static int SUBTREE_SCOPE = 2;
0N/A
0N/A /**
0N/A * Contains the scope with which to apply the search. One of
0N/A * <tt>ONELEVEL_SCOPE</tt>, <tt>OBJECT_SCOPE</tt>, or
0N/A * <tt>SUBTREE_SCOPE</tt>.
0N/A * @serial
0N/A */
0N/A private int searchScope;
0N/A
0N/A /**
0N/A * Contains the milliseconds to wait before returning
0N/A * from search.
0N/A * @serial
0N/A */
0N/A private int timeLimit;
0N/A
0N/A /**
0N/A * Indicates whether JNDI links are dereferenced during
0N/A * search.
0N/A * @serial
0N/A */
0N/A private boolean derefLink;
0N/A
0N/A /**
0N/A * Indicates whether object is returned in <tt>SearchResult</tt>.
0N/A * @serial
0N/A */
0N/A private boolean returnObj;
0N/A
0N/A /**
0N/A * Contains the maximum number of SearchResults to return.
0N/A * @serial
0N/A */
0N/A private long countLimit;
0N/A
0N/A /**
0N/A * Contains the list of attributes to be returned in
0N/A * <tt>SearchResult</tt> for each matching entry of search. <tt>null</tt>
0N/A * indicates that all attributes are to be returned.
0N/A * @serial
0N/A */
0N/A private String[] attributesToReturn;
0N/A
0N/A /**
0N/A * Constructs a search constraints using defaults.
0N/A *<p>
0N/A * The defaults are:
0N/A * <ul>
0N/A * <li>search one level
0N/A * <li>no maximum return limit for search results
0N/A * <li>no time limit for search
0N/A * <li>return all attributes associated with objects that satisfy
0N/A * the search filter.
0N/A * <li>do not return named object (return only name and class)
0N/A * <li>do not dereference links during search
0N/A *</ul>
0N/A */
0N/A public SearchControls() {
0N/A searchScope = ONELEVEL_SCOPE;
0N/A timeLimit = 0; // no limit
0N/A countLimit = 0; // no limit
0N/A derefLink = false;
0N/A returnObj = false;
0N/A attributesToReturn = null; // return all
0N/A }
0N/A
0N/A /**
0N/A * Constructs a search constraints using arguments.
0N/A * @param scope The search scope. One of:
0N/A * OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
0N/A * @param timelim The number of milliseconds to wait before returning.
0N/A * If 0, wait indefinitely.
0N/A * @param deref If true, dereference links during search.
0N/A * @param countlim The maximum number of entries to return. If 0, return
0N/A * all entries that satisfy filter.
0N/A * @param retobj If true, return the object bound to the name of the
0N/A * entry; if false, do not return object.
0N/A * @param attrs The identifiers of the attributes to return along with
0N/A * the entry. If null, return all attributes. If empty
0N/A * return no attributes.
0N/A */
0N/A public SearchControls(int scope,
0N/A long countlim,
0N/A int timelim,
0N/A String[] attrs,
0N/A boolean retobj,
0N/A boolean deref) {
0N/A searchScope = scope;
0N/A timeLimit = timelim; // no limit
0N/A derefLink = deref;
0N/A returnObj = retobj;
0N/A countLimit = countlim; // no limit
0N/A attributesToReturn = attrs; // return all
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the search scope of these SearchControls.
0N/A *<p>
0N/A * One of OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
0N/A *
0N/A * @return The search scope of this SearchControls.
0N/A * @see #setSearchScope
0N/A */
0N/A public int getSearchScope() {
0N/A return searchScope;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the time limit of these SearchControls in milliseconds.
0N/A *<p>
0N/A * If the value is 0, this means to wait indefinitely.
0N/A * @return The time limit of these SearchControls in milliseconds.
0N/A * @see #setTimeLimit
0N/A */
0N/A public int getTimeLimit() {
0N/A return timeLimit;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether links will be dereferenced during the search.
0N/A *
0N/A * @return true if links will be dereferenced; false otherwise.
0N/A * @see #setDerefLinkFlag
0N/A */
0N/A public boolean getDerefLinkFlag() {
0N/A return derefLink;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether objects will be returned as part of the result.
0N/A *
0N/A * @return true if objects will be returned; false otherwise.
0N/A * @see #setReturningObjFlag
0N/A */
0N/A public boolean getReturningObjFlag() {
0N/A return returnObj;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the maximum number of entries that will be returned
0N/A * as a result of the search.
0N/A *<p>
0N/A * 0 indicates that all entries will be returned.
0N/A * @return The maximum number of entries that will be returned.
0N/A * @see #setCountLimit
0N/A */
0N/A public long getCountLimit() {
0N/A return countLimit;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the attributes that will be returned as part of the search.
0N/A *<p>
0N/A * A value of null indicates that all attributes will be returned.
0N/A * An empty array indicates that no attributes are to be returned.
0N/A *
0N/A * @return An array of attribute ids identifying the attributes that
0N/A * will be returned. Can be null.
0N/A * @see #setReturningAttributes
0N/A */
0N/A public String[] getReturningAttributes() {
0N/A return attributesToReturn;
0N/A }
0N/A
0N/A /**
0N/A * Sets the search scope to one of:
0N/A * OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
0N/A * @param scope The search scope of this SearchControls.
0N/A * @see #getSearchScope
0N/A */
0N/A public void setSearchScope(int scope) {
0N/A searchScope = scope;
0N/A }
0N/A
0N/A /**
0N/A * Sets the time limit of these SearchControls in milliseconds.
0N/A *<p>
0N/A * If the value is 0, this means to wait indefinitely.
0N/A * @param ms The time limit of these SearchControls in milliseconds.
0N/A * @see #getTimeLimit
0N/A */
0N/A public void setTimeLimit(int ms) {
0N/A timeLimit = ms;
0N/A }
0N/A
0N/A /**
0N/A * Enables/disables link dereferencing during the search.
0N/A *
0N/A * @param on if true links will be dereferenced; if false, not followed.
0N/A * @see #getDerefLinkFlag
0N/A */
0N/A public void setDerefLinkFlag(boolean on) {
0N/A derefLink = on;
0N/A }
0N/A
0N/A /**
0N/A * Enables/disables returning objects returned as part of the result.
0N/A *<p>
0N/A * If disabled, only the name and class of the object is returned.
0N/A * If enabled, the object will be returned.
0N/A *
0N/A * @param on if true, objects will be returned; if false,
0N/A * objects will not be returned.
0N/A * @see #getReturningObjFlag
0N/A */
0N/A public void setReturningObjFlag(boolean on) {
0N/A returnObj = on;
0N/A }
0N/A
0N/A /**
0N/A * Sets the maximum number of entries to be returned
0N/A * as a result of the search.
0N/A *<p>
0N/A * 0 indicates no limit: all entries will be returned.
0N/A *
0N/A * @param limit The maximum number of entries that will be returned.
0N/A * @see #getCountLimit
0N/A */
0N/A public void setCountLimit(long limit) {
0N/A countLimit = limit;
0N/A }
0N/A
0N/A /**
0N/A * Specifies the attributes that will be returned as part of the search.
0N/A *<p>
0N/A * null indicates that all attributes will be returned.
0N/A * An empty array indicates no attributes are returned.
0N/A *
0N/A * @param attrs An array of attribute ids identifying the attributes that
0N/A * will be returned. Can be null.
0N/A * @see #getReturningAttributes
0N/A */
0N/A public void setReturningAttributes(String[] attrs) {
0N/A attributesToReturn = attrs;
0N/A }
0N/A
0N/A /**
0N/A * Use serialVersionUID from JNDI 1.1.1 for interoperability.
0N/A */
0N/A private static final long serialVersionUID = -2480540967773454797L;
0N/A}