Path: blob/master/src/java.naming/share/classes/javax/naming/directory/SearchControls.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*/242526package javax.naming.directory;2728/**29* This class encapsulates30* factors that determine scope of search and what gets returned31* as a result of the search.32*<p>33* A SearchControls instance is not synchronized against concurrent34* multithreaded access. Multiple threads trying to access and modify35* a single SearchControls instance should lock the object.36*37* @author Rosanna Lee38* @author Scott Seligman39* @since 1.340*/4142public class SearchControls implements java.io.Serializable {43/**44* Search the named object.45*<p>46* The NamingEnumeration that results from search()47* using OBJECT_SCOPE will contain one or zero element.48* The enumeration contains one element if the named object satisfies49* the search filter specified in search().50* The element will have as its name the empty string because the names51* of elements in the NamingEnumeration are relative to the52* target context--in this case, the target context is the named object.53* It contains zero element if the named object does not satisfy54* the search filter specified in search().55* <p>56* The value of this constant is {@code 0}.57*/58public static final int OBJECT_SCOPE = 0;5960/**61* Search one level of the named context.62*<p>63* The NamingEnumeration that results from search()64* using ONELEVEL_SCOPE contains elements with65* objects in the named context that satisfy66* the search filter specified in search().67* The names of elements in the NamingEnumeration are atomic names68* relative to the named context.69* <p>70* The value of this constant is {@code 1}.71*/72public static final int ONELEVEL_SCOPE = 1;73/**74* Search the entire subtree rooted at the named object.75*<p>76* If the named object is not a DirContext, search only the object.77* If the named object is a DirContext, search the subtree78* rooted at the named object, including the named object itself.79*<p>80* The search will not cross naming system boundaries.81*<p>82* The NamingEnumeration that results from search()83* using SUBTREE_SCOPE contains elements of objects84* from the subtree (including the named context)85* that satisfy the search filter specified in search().86* The names of elements in the NamingEnumeration are either87* relative to the named context or is a URL string.88* If the named context satisfies the search filter, it is89* included in the enumeration with the empty string as90* its name.91* <p>92* The value of this constant is {@code 2}.93*/94public static final int SUBTREE_SCOPE = 2;9596/**97* Contains the scope with which to apply the search. One of98* {@code ONELEVEL_SCOPE}, {@code OBJECT_SCOPE}, or99* {@code SUBTREE_SCOPE}.100* @serial101*/102private int searchScope;103104/**105* Contains the milliseconds to wait before returning106* from search.107* @serial108*/109private int timeLimit;110111/**112* Indicates whether JNDI links are dereferenced during113* search.114* @serial115*/116private boolean derefLink;117118/**119* Indicates whether object is returned in {@code SearchResult}.120* @serial121*/122private boolean returnObj;123124/**125* Contains the maximum number of SearchResults to return.126* @serial127*/128private long countLimit;129130/**131* Contains the list of attributes to be returned in132* {@code SearchResult} for each matching entry of search. {@code null}133* indicates that all attributes are to be returned.134* @serial135*/136private String[] attributesToReturn;137138/**139* Constructs a search constraints using defaults.140*<p>141* The defaults are:142* <ul>143* <li>search one level144* <li>no maximum return limit for search results145* <li>no time limit for search146* <li>return all attributes associated with objects that satisfy147* the search filter.148* <li>do not return named object (return only name and class)149* <li>do not dereference links during search150*</ul>151*/152public SearchControls() {153searchScope = ONELEVEL_SCOPE;154timeLimit = 0; // no limit155countLimit = 0; // no limit156derefLink = false;157returnObj = false;158attributesToReturn = null; // return all159}160161/**162* Constructs a search constraints using arguments.163* @param scope The search scope. One of:164* OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.165* @param timelim The number of milliseconds to wait before returning.166* If 0, wait indefinitely.167* @param deref If true, dereference links during search.168* @param countlim The maximum number of entries to return. If 0, return169* all entries that satisfy filter.170* @param retobj If true, return the object bound to the name of the171* entry; if false, do not return object.172* @param attrs The identifiers of the attributes to return along with173* the entry. If null, return all attributes. If empty174* return no attributes.175*/176public SearchControls(int scope,177long countlim,178int timelim,179String[] attrs,180boolean retobj,181boolean deref) {182searchScope = scope;183timeLimit = timelim; // no limit184derefLink = deref;185returnObj = retobj;186countLimit = countlim; // no limit187attributesToReturn = attrs; // return all188}189190/**191* Retrieves the search scope of these SearchControls.192*<p>193* One of OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.194*195* @return The search scope of this SearchControls.196* @see #setSearchScope197*/198public int getSearchScope() {199return searchScope;200}201202/**203* Retrieves the time limit of these SearchControls in milliseconds.204*<p>205* If the value is 0, this means to wait indefinitely.206* @return The time limit of these SearchControls in milliseconds.207* @see #setTimeLimit208*/209public int getTimeLimit() {210return timeLimit;211}212213/**214* Determines whether links will be dereferenced during the search.215*216* @return true if links will be dereferenced; false otherwise.217* @see #setDerefLinkFlag218*/219public boolean getDerefLinkFlag() {220return derefLink;221}222223/**224* Determines whether objects will be returned as part of the result.225*226* @return true if objects will be returned; false otherwise.227* @see #setReturningObjFlag228*/229public boolean getReturningObjFlag() {230return returnObj;231}232233/**234* Retrieves the maximum number of entries that will be returned235* as a result of the search.236*<p>237* 0 indicates that all entries will be returned.238* @return The maximum number of entries that will be returned.239* @see #setCountLimit240*/241public long getCountLimit() {242return countLimit;243}244245/**246* Retrieves the attributes that will be returned as part of the search.247*<p>248* A value of null indicates that all attributes will be returned.249* An empty array indicates that no attributes are to be returned.250*251* @return An array of attribute ids identifying the attributes that252* will be returned. Can be null.253* @see #setReturningAttributes254*/255public String[] getReturningAttributes() {256return attributesToReturn;257}258259/**260* Sets the search scope to one of:261* OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.262* @param scope The search scope of this SearchControls.263* @see #getSearchScope264*/265public void setSearchScope(int scope) {266searchScope = scope;267}268269/**270* Sets the time limit of these SearchControls in milliseconds.271*<p>272* If the value is 0, this means to wait indefinitely.273* @param ms The time limit of these SearchControls in milliseconds.274* @see #getTimeLimit275*/276public void setTimeLimit(int ms) {277timeLimit = ms;278}279280/**281* Enables/disables link dereferencing during the search.282*283* @param on if true links will be dereferenced; if false, not followed.284* @see #getDerefLinkFlag285*/286public void setDerefLinkFlag(boolean on) {287derefLink = on;288}289290/**291* Enables/disables returning objects returned as part of the result.292*<p>293* If disabled, only the name and class of the object is returned.294* If enabled, the object will be returned.295*296* @param on if true, objects will be returned; if false,297* objects will not be returned.298* @see #getReturningObjFlag299*/300public void setReturningObjFlag(boolean on) {301returnObj = on;302}303304/**305* Sets the maximum number of entries to be returned306* as a result of the search.307*<p>308* 0 indicates no limit: all entries will be returned.309*310* @param limit The maximum number of entries that will be returned.311* @see #getCountLimit312*/313public void setCountLimit(long limit) {314countLimit = limit;315}316317/**318* Specifies the attributes that will be returned as part of the search.319*<p>320* null indicates that all attributes will be returned.321* An empty array indicates no attributes are returned.322*323* @param attrs An array of attribute ids identifying the attributes that324* will be returned. Can be null.325* @see #getReturningAttributes326*/327public void setReturningAttributes(String[] attrs) {328attributesToReturn = attrs;329}330331/**332* Use serialVersionUID from JNDI 1.1.1 for interoperability.333*/334private static final long serialVersionUID = -2480540967773454797L;335}336337338