src/java.naming/share/classes/javax/naming/InitialContext.java
author herrick
Tue, 24 Sep 2019 13:41:16 -0400
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4349
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4349
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4349
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4349
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4349
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.spi.NamingManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.naming.internal.ResourceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class is the starting context for performing naming operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * All naming operations are relative to a context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The initial context implements the Context interface and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * provides the starting point for resolution of names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *<p>
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
    39
 * <a id=ENVIRONMENT></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * When the initial context is constructed, its environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is initialized with properties defined in the environment parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * passed to the constructor, and in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <a href=Context.html#RESOURCEFILES>application resource files</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * JNDI determines each property's value by merging
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the values from the following two sources, in order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The first occurrence of the property from the constructor's
25752
8df7ddac1cb3 8051422: Remove JNDI dependency on java.applet.Applet
prappo
parents: 25176
diff changeset
    50
 * environment parameter and system properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <li>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    52
 * The application resource files ({@code jndi.properties}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * For each property found in both of these two sources, or in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * more than one application resource file, the property's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * is determined as follows.  If the property is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * one of the standard JNDI properties that specify a list of JNDI
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    58
 * factories (see <a href=Context.html#LISTPROPS>{@code Context}</a>),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * all of the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * concatenated into a single colon-separated list.  For other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * properties, only the first value found is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The initial context implementation is determined at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The default policy uses the environment property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * "{@link Context#INITIAL_CONTEXT_FACTORY java.naming.factory.initial}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * which contains the class name of the initial context factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * An exception to this policy is made when resolving URL strings, as described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    71
 * When a URL string (a {@code String} of the form
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <em>scheme_id:rest_of_name</em>) is passed as a name parameter to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * any method, a URL context factory for handling that scheme is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * located and used to resolve the URL.  If no such factory is found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * the initial context specified by
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    76
 * {@code "java.naming.factory.initial"} is used.  Similarly, when a
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    77
 * {@code CompositeName} object whose first component is a URL string is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * passed as a name parameter to any method, a URL context factory is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * located and used to resolve the first name component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * See {@link NamingManager#getURLContext
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    81
 * NamingManager.getURLContext()} for a description of how URL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * context factories are located.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * This default policy of locating the initial context and URL context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * factories may be overridden
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * by calling
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    87
 * {@code NamingManager.setInitialContextFactoryBuilder()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * NoInitialContextException is thrown when an initial context cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * be instantiated. This exception can be thrown during any interaction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * with the InitialContext, not only when the InitialContext is constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * For example, the implementation of the initial context might lazily
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * retrieve the context only when actual methods are invoked on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * The application should not have any dependency on when the existence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * of an initial context is determined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * When the environment property "java.naming.factory.initial" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * non-null, the InitialContext constructor will attempt to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * initial context specified therein. At that time, the initial context factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * involved might throw an exception if a problem is encountered. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * it is provider implementation-dependent when it verifies and indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * to the users of the initial context any environment property- or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * connection- related problems. It can do so lazily--delaying until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * an operation is performed on the context, or eagerly, at the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * the context is constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * An InitialContext instance is not synchronized against concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * access by multiple threads. Multiple threads each manipulating a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * different InitialContext instance need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Threads that need to access a single InitialContext instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * concurrently should synchronize amongst themselves and provide the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * necessary locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * @see Context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * @see NamingManager#setInitialContextFactoryBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *      NamingManager.setInitialContextFactoryBuilder
25176
3c2ba9344cbf 8047721: @since should have JDK version
henryjen
parents: 21285
diff changeset
   120
 * @since 1.3, JNDI 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
public class InitialContext implements Context {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * The environment associated with this InitialContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * It is initialized to null and is updated by the constructor
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   128
     * that accepts an environment or by the {@code init()} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #addToEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #removeFromEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #getEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    protected Hashtable<Object,Object> myProps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Field holding the result of calling NamingManager.getInitialContext().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * It is set by getDefaultInitCtx() the first time getDefaultInitCtx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * is called. Subsequent invocations of getDefaultInitCtx() return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the value of defaultInitCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see #getDefaultInitCtx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected Context defaultInitCtx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Field indicating whether the initial context has been obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * by calling NamingManager.getInitialContext().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * If true, its result is in <code>defaultInitCtx</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected boolean gotDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Constructs an initial context with the option of not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * initializing it.  This may be used by a constructor in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * a subclass when the value of the environment parameter
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   155
     * is not yet known at the time the {@code InitialContext}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * constructor is called.  The subclass's constructor will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * call this constructor, compute the value of the environment,
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   158
     * and then call {@code init()} before returning.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param lazy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *          true means do not initialize the initial context; false
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   162
     *          is equivalent to calling {@code new InitialContext()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws  NamingException if a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see #init(Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected InitialContext(boolean lazy) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (!lazy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            init(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Constructs an initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * No environment properties are supplied.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   177
     * Equivalent to {@code new InitialContext(null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @throws  NamingException if a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see #InitialContext(Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public InitialContext() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        init(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Constructs an initial context using the supplied environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Environment properties are discussed in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   191
     * <p> This constructor will not modify {@code environment}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * or save a reference to it, but may save a clone.
4349
c72a4e2ec170 6886058: JNDI LDAP InitialLdapContext SECURITY_CREDENTIALS byte[] can be corrupted, then LDAP referral fails
weijun
parents: 2
diff changeset
   193
     * Caller should not modify mutable keys and values in
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   194
     * {@code environment} after it has been passed to the constructor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          environment used to create the initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          Null indicates an empty environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @throws  NamingException if a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public InitialContext(Hashtable<?,?> environment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (environment != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            environment = (Hashtable)environment.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        init(environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Initializes the initial context using the supplied environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Environment properties are discussed in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   215
     * <p> This method will modify {@code environment} and save
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * a reference to it.  The caller may no longer modify it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *          environment used to create the initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *          Null indicates an empty environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws  NamingException if a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see #InitialContext(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   227
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    protected void init(Hashtable<?,?> environment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   231
        myProps = (Hashtable<Object,Object>)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   232
                ResourceManager.getInitialEnvironment(environment);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (myProps.get(Context.INITIAL_CONTEXT_FACTORY) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // user has specified initial context factory; try to get it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            getDefaultInitCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * A static method to retrieve the named object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * This is a shortcut method equivalent to invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *        InitialContext ic = new InitialContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *        Object obj = ic.lookup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * </code>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   248
     * <p> If {@code name} is empty, returns a new instance of this context
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * (which represents the same naming context as this context, but its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * environment may be modified independently and it may be accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * concurrently).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
18580
6c4badf4ffba 8019407: Fix doclint issues in javax.naming.*
darcy
parents: 10324
diff changeset
   253
     * @param <T> the type of the returned object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *          the name of the object to look up
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   256
     * @return  the object bound to {@code name}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @throws  NamingException if a naming exception is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see #doLookup(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see #lookup(Name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   263
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public static <T> T doLookup(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return (T) (new InitialContext()).lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * A static method to retrieve the named object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * See {@link #doLookup(Name)} for details.
18580
6c4badf4ffba 8019407: Fix doclint issues in javax.naming.*
darcy
parents: 10324
diff changeset
   272
     * @param <T> the type of the returned object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *          the name of the object to look up
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   275
     * @return  the object bound to {@code name}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws  NamingException if a naming exception is encountered
18580
6c4badf4ffba 8019407: Fix doclint issues in javax.naming.*
darcy
parents: 10324
diff changeset
   277
     * @since 1.6
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   279
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public static <T> T doLookup(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return (T) (new InitialContext()).lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private static String getURLScheme(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        int colon_posn = str.indexOf(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int slash_posn = str.indexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return str.substring(0, colon_posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Retrieves the initial context by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <code>NamingManager.getInitialContext()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * and cache it in defaultInitCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Set <code>gotDefault</code> so that we know we've tried this before.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return The non-null cached initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @exception NoInitialContextException If cannot find an initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @exception NamingException If a naming exception was encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    protected Context getDefaultInitCtx() throws NamingException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (!gotDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            defaultInitCtx = NamingManager.getInitialContext(myProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            gotDefault = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (defaultInitCtx == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            throw new NoInitialContextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return defaultInitCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Retrieves a context for resolving the string name <code>name</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * If <code>name</code> name is a URL string, then attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * to find a URL context for it. If none is found, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <code>name</code> is not a URL string, then return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <code>getDefaultInitCtx()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * See getURLOrDefaultInitCtx(Name) for description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * of how a subclass should use this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param name The non-null name for which to get the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return A URL context for <code>name</code> or the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *         initial context. The result cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @exception NoInitialContextException If cannot find an initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @exception NamingException In a naming exception is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see javax.naming.spi.NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    protected Context getURLOrDefaultInitCtx(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (NamingManager.hasInitialContextFactoryBuilder()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return getDefaultInitCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        String scheme = getURLScheme(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (scheme != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            Context ctx = NamingManager.getURLContext(scheme, myProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (ctx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                return ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return getDefaultInitCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Retrieves a context for resolving <code>name</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * If the first component of <code>name</code> name is a URL string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * then attempt to find a URL context for it. If none is found, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * the first component of <code>name</code> is not a URL string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * then return <code>getDefaultInitCtx()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * When creating a subclass of InitialContext, use this method as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Define a new method that uses this method to get an initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * context of the desired subclass.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
   356
     * <blockquote><pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *  Context answer = getURLOrDefaultInitCtx(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *  if (!(answer instanceof XXXContext)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *    if (answer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *      throw new NoInitialContextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *      throw new NotContextException("Not an XXXContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *  return (XXXContext)answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * When providing implementations for the new methods in the subclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * use this newly defined method to get the initial context.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
   372
     * <blockquote><pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * public Object XXXMethod1(Name name, ...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *  throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @param name The non-null name for which to get the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return A URL context for <code>name</code> or the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *         initial context. The result cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @exception NoInitialContextException If cannot find an initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @exception NamingException In a naming exception is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @see javax.naming.spi.NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    protected Context getURLOrDefaultInitCtx(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (NamingManager.hasInitialContextFactoryBuilder()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return getDefaultInitCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (name.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            String first = name.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            String scheme = getURLScheme(first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            if (scheme != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                Context ctx = NamingManager.getURLContext(scheme, myProps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                if (ctx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    return ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return getDefaultInitCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
// Context methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
// Most Javadoc is deferred to the Context interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return getURLOrDefaultInitCtx(name).lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public Object lookup(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return getURLOrDefaultInitCtx(name).lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public void bind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        getURLOrDefaultInitCtx(name).bind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void bind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        getURLOrDefaultInitCtx(name).bind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public void rebind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        getURLOrDefaultInitCtx(name).rebind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public void rebind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        getURLOrDefaultInitCtx(name).rebind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void unbind(String name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        getURLOrDefaultInitCtx(name).unbind(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public void unbind(Name name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        getURLOrDefaultInitCtx(name).unbind(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void rename(String oldName, String newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public void rename(Name oldName, Name newName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public NamingEnumeration<NameClassPair> list(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return (getURLOrDefaultInitCtx(name).list(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public NamingEnumeration<NameClassPair> list(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return (getURLOrDefaultInitCtx(name).list(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public NamingEnumeration<Binding> listBindings(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return getURLOrDefaultInitCtx(name).listBindings(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public NamingEnumeration<Binding> listBindings(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return getURLOrDefaultInitCtx(name).listBindings(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public void destroySubcontext(String name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        getURLOrDefaultInitCtx(name).destroySubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public void destroySubcontext(Name name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        getURLOrDefaultInitCtx(name).destroySubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public Context createSubcontext(String name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return getURLOrDefaultInitCtx(name).createSubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public Context createSubcontext(Name name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return getURLOrDefaultInitCtx(name).createSubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public Object lookupLink(String name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return getURLOrDefaultInitCtx(name).lookupLink(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return getURLOrDefaultInitCtx(name).lookupLink(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return getURLOrDefaultInitCtx(name).getNameParser(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return getURLOrDefaultInitCtx(name).getNameParser(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Composes the name of this context with a name relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Since an initial context may never be named relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * to any context other than itself, the value of the
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   509
     * {@code prefix} parameter must be an empty name ({@code ""}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public String composeName(String name, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Composes the name of this context with a name relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Since an initial context may never be named relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * to any context other than itself, the value of the
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   521
     * {@code prefix} parameter must be an empty name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public Name composeName(Name name, Name prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return (Name)name.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public Object addToEnvironment(String propName, Object propVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        myProps.put(propName, propVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return getDefaultInitCtx().addToEnvironment(propName, propVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public Object removeFromEnvironment(String propName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        myProps.remove(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return getDefaultInitCtx().removeFromEnvironment(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public Hashtable<?,?> getEnvironment() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return getDefaultInitCtx().getEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void close() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        myProps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (defaultInitCtx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            defaultInitCtx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            defaultInitCtx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        gotDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public String getNameInNamespace() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return getDefaultInitCtx().getNameInNamespace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
};