Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/naming/directory/InitialDirContext.java
38918 views
/*1* Copyright (c) 1999, 2009, 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;2728import java.util.Hashtable;29import javax.naming.spi.NamingManager;30import javax.naming.*;3132/**33* This class is the starting context for performing34* directory operations. The documentation in the class description35* of InitialContext (including those for synchronization) apply here.36*37*38* @author Rosanna Lee39* @author Scott Seligman40*41* @see javax.naming.InitialContext42* @since 1.343*/4445public class InitialDirContext extends InitialContext implements DirContext {4647/**48* Constructs an initial DirContext with the option of not49* initializing it. This may be used by a constructor in50* a subclass when the value of the environment parameter51* is not yet known at the time the <tt>InitialDirContext</tt>52* constructor is called. The subclass's constructor will53* call this constructor, compute the value of the environment,54* and then call <tt>init()</tt> before returning.55*56* @param lazy57* true means do not initialize the initial DirContext; false58* is equivalent to calling <tt>new InitialDirContext()</tt>59* @throws NamingException if a naming exception is encountered60*61* @see InitialContext#init(Hashtable)62* @since 1.363*/64protected InitialDirContext(boolean lazy) throws NamingException {65super(lazy);66}6768/**69* Constructs an initial DirContext.70* No environment properties are supplied.71* Equivalent to <tt>new InitialDirContext(null)</tt>.72*73* @throws NamingException if a naming exception is encountered74*75* @see #InitialDirContext(Hashtable)76*/77public InitialDirContext() throws NamingException {78super();79}8081/**82* Constructs an initial DirContext using the supplied environment.83* Environment properties are discussed in the84* <tt>javax.naming.InitialContext</tt> class description.85*86* <p> This constructor will not modify <tt>environment</tt>87* or save a reference to it, but may save a clone.88* Caller should not modify mutable keys and values in89* <tt>environment</tt> after it has been passed to the constructor.90*91* @param environment92* environment used to create the initial DirContext.93* Null indicates an empty environment.94*95* @throws NamingException if a naming exception is encountered96*/97public InitialDirContext(Hashtable<?,?> environment)98throws NamingException99{100super(environment);101}102103private DirContext getURLOrDefaultInitDirCtx(String name)104throws NamingException {105Context answer = getURLOrDefaultInitCtx(name);106if (!(answer instanceof DirContext)) {107if (answer == null) {108throw new NoInitialContextException();109} else {110throw new NotContextException(111"Not an instance of DirContext");112}113}114return (DirContext)answer;115}116117private DirContext getURLOrDefaultInitDirCtx(Name name)118throws NamingException {119Context answer = getURLOrDefaultInitCtx(name);120if (!(answer instanceof DirContext)) {121if (answer == null) {122throw new NoInitialContextException();123} else {124throw new NotContextException(125"Not an instance of DirContext");126}127}128return (DirContext)answer;129}130131// DirContext methods132// Most Javadoc is deferred to the DirContext interface.133134public Attributes getAttributes(String name)135throws NamingException {136return getAttributes(name, null);137}138139public Attributes getAttributes(String name, String[] attrIds)140throws NamingException {141return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);142}143144public Attributes getAttributes(Name name)145throws NamingException {146return getAttributes(name, null);147}148149public Attributes getAttributes(Name name, String[] attrIds)150throws NamingException {151return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);152}153154public void modifyAttributes(String name, int mod_op, Attributes attrs)155throws NamingException {156getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);157}158159public void modifyAttributes(Name name, int mod_op, Attributes attrs)160throws NamingException {161getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);162}163164public void modifyAttributes(String name, ModificationItem[] mods)165throws NamingException {166getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);167}168169public void modifyAttributes(Name name, ModificationItem[] mods)170throws NamingException {171getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);172}173174public void bind(String name, Object obj, Attributes attrs)175throws NamingException {176getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);177}178179public void bind(Name name, Object obj, Attributes attrs)180throws NamingException {181getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);182}183184public void rebind(String name, Object obj, Attributes attrs)185throws NamingException {186getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);187}188189public void rebind(Name name, Object obj, Attributes attrs)190throws NamingException {191getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);192}193194public DirContext createSubcontext(String name, Attributes attrs)195throws NamingException {196return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);197}198199public DirContext createSubcontext(Name name, Attributes attrs)200throws NamingException {201return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);202}203204public DirContext getSchema(String name) throws NamingException {205return getURLOrDefaultInitDirCtx(name).getSchema(name);206}207208public DirContext getSchema(Name name) throws NamingException {209return getURLOrDefaultInitDirCtx(name).getSchema(name);210}211212public DirContext getSchemaClassDefinition(String name)213throws NamingException {214return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);215}216217public DirContext getSchemaClassDefinition(Name name)218throws NamingException {219return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);220}221222// -------------------- search operations223224public NamingEnumeration<SearchResult>225search(String name, Attributes matchingAttributes)226throws NamingException227{228return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);229}230231public NamingEnumeration<SearchResult>232search(Name name, Attributes matchingAttributes)233throws NamingException234{235return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);236}237238public NamingEnumeration<SearchResult>239search(String name,240Attributes matchingAttributes,241String[] attributesToReturn)242throws NamingException243{244return getURLOrDefaultInitDirCtx(name).search(name,245matchingAttributes,246attributesToReturn);247}248249public NamingEnumeration<SearchResult>250search(Name name,251Attributes matchingAttributes,252String[] attributesToReturn)253throws NamingException254{255return getURLOrDefaultInitDirCtx(name).search(name,256matchingAttributes,257attributesToReturn);258}259260public NamingEnumeration<SearchResult>261search(String name,262String filter,263SearchControls cons)264throws NamingException265{266return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);267}268269public NamingEnumeration<SearchResult>270search(Name name,271String filter,272SearchControls cons)273throws NamingException274{275return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);276}277278public NamingEnumeration<SearchResult>279search(String name,280String filterExpr,281Object[] filterArgs,282SearchControls cons)283throws NamingException284{285return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,286filterArgs, cons);287}288289public NamingEnumeration<SearchResult>290search(Name name,291String filterExpr,292Object[] filterArgs,293SearchControls cons)294throws NamingException295{296return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,297filterArgs, cons);298}299}300301302