0N/A/*
2362N/A * Copyright (c) 1999, 2009, 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/Aimport java.util.Hashtable;
0N/Aimport javax.naming.spi.NamingManager;
0N/Aimport javax.naming.*;
0N/A
0N/A/**
0N/A * This class is the starting context for performing
0N/A * directory operations. The documentation in the class description
0N/A * of InitialContext (including those for synchronization) apply here.
0N/A *
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A *
0N/A * @see javax.naming.InitialContext
0N/A * @since 1.3
0N/A */
0N/A
0N/Apublic class InitialDirContext extends InitialContext implements DirContext {
0N/A
0N/A /**
0N/A * Constructs an initial DirContext with the option of not
0N/A * initializing it. This may be used by a constructor in
0N/A * a subclass when the value of the environment parameter
0N/A * is not yet known at the time the <tt>InitialDirContext</tt>
0N/A * constructor is called. The subclass's constructor will
0N/A * call this constructor, compute the value of the environment,
0N/A * and then call <tt>init()</tt> before returning.
0N/A *
0N/A * @param lazy
0N/A * true means do not initialize the initial DirContext; false
0N/A * is equivalent to calling <tt>new InitialDirContext()</tt>
0N/A * @throws NamingException if a naming exception is encountered
0N/A *
0N/A * @see InitialContext#init(Hashtable)
0N/A * @since 1.3
0N/A */
0N/A protected InitialDirContext(boolean lazy) throws NamingException {
0N/A super(lazy);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initial DirContext.
0N/A * No environment properties are supplied.
0N/A * Equivalent to <tt>new InitialDirContext(null)</tt>.
0N/A *
0N/A * @throws NamingException if a naming exception is encountered
0N/A *
0N/A * @see #InitialDirContext(Hashtable)
0N/A */
0N/A public InitialDirContext() throws NamingException {
0N/A super();
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initial DirContext using the supplied environment.
0N/A * Environment properties are discussed in the
0N/A * <tt>javax.naming.InitialContext</tt> class description.
0N/A *
0N/A * <p> This constructor will not modify <tt>environment</tt>
0N/A * or save a reference to it, but may save a clone.
1954N/A * Caller should not modify mutable keys and values in
1954N/A * <tt>environment</tt> after it has been passed to the constructor.
0N/A *
0N/A * @param environment
0N/A * environment used to create the initial DirContext.
0N/A * Null indicates an empty environment.
0N/A *
0N/A * @throws NamingException if a naming exception is encountered
0N/A */
0N/A public InitialDirContext(Hashtable<?,?> environment)
0N/A throws NamingException
0N/A {
0N/A super(environment);
0N/A }
0N/A
0N/A private DirContext getURLOrDefaultInitDirCtx(String name)
0N/A throws NamingException {
0N/A Context answer = getURLOrDefaultInitCtx(name);
0N/A if (!(answer instanceof DirContext)) {
0N/A if (answer == null) {
0N/A throw new NoInitialContextException();
0N/A } else {
0N/A throw new NotContextException(
0N/A "Not an instance of DirContext");
0N/A }
0N/A }
0N/A return (DirContext)answer;
0N/A }
0N/A
0N/A private DirContext getURLOrDefaultInitDirCtx(Name name)
0N/A throws NamingException {
0N/A Context answer = getURLOrDefaultInitCtx(name);
0N/A if (!(answer instanceof DirContext)) {
0N/A if (answer == null) {
0N/A throw new NoInitialContextException();
0N/A } else {
0N/A throw new NotContextException(
0N/A "Not an instance of DirContext");
0N/A }
0N/A }
0N/A return (DirContext)answer;
0N/A }
0N/A
0N/A// DirContext methods
0N/A// Most Javadoc is deferred to the DirContext interface.
0N/A
0N/A public Attributes getAttributes(String name)
0N/A throws NamingException {
0N/A return getAttributes(name, null);
0N/A }
0N/A
0N/A public Attributes getAttributes(String name, String[] attrIds)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name)
0N/A throws NamingException {
0N/A return getAttributes(name, null);
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name, String[] attrIds)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
0N/A }
0N/A
0N/A public void modifyAttributes(String name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
0N/A }
0N/A
0N/A public void modifyAttributes(String name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
0N/A }
0N/A
0N/A public void bind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
0N/A }
0N/A
0N/A public void bind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
0N/A }
0N/A
0N/A public void rebind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
0N/A }
0N/A
0N/A public void rebind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
0N/A }
0N/A
0N/A public DirContext createSubcontext(String name, Attributes attrs)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
0N/A }
0N/A
0N/A public DirContext createSubcontext(Name name, Attributes attrs)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
0N/A }
0N/A
0N/A public DirContext getSchema(String name) throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getSchema(name);
0N/A }
0N/A
0N/A public DirContext getSchema(Name name) throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getSchema(name);
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(String name)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(Name name)
0N/A throws NamingException {
0N/A return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
0N/A }
0N/A
0N/A// -------------------- search operations
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name, Attributes matchingAttributes)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name, Attributes matchingAttributes)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name,
0N/A matchingAttributes,
0N/A attributesToReturn);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name,
0N/A matchingAttributes,
0N/A attributesToReturn);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A String filterExpr,
0N/A Object[] filterArgs,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
0N/A filterArgs, cons);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A String filterExpr,
0N/A Object[] filterArgs,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
0N/A filterArgs, cons);
0N/A }
0N/A}