src/java.naming/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
     2
 * Copyright (c) 1999, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 com.sun.jndi.toolkit.url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.spi.ResolveResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.spi.NamingManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This abstract class is a generic URL context that accepts as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * name argument either a string URL or a Name whose first component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is a URL. It resolves the URL to a target context and then continues
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the operation using the remaining name in the target context as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the first component names a junction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * A subclass must define getRootURLContext()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * to process the URL into head/tail pieces. If it wants to control how
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * URL strings are parsed and compared for the rename() operation, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * it should override getNonRootURLSuffixes() and urlEquals().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
abstract public class GenericURLContext implements Context {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    51
    protected Hashtable<String, Object> myEnv = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    53
    @SuppressWarnings("unchecked") // Expect Hashtable<String, Object>
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    54
    public GenericURLContext(Hashtable<?,?> env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        // context that is not tied to any specific URL
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
    56
        myEnv =
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
    57
            (Hashtable<String, Object>)(env == null ? null : env.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public void close() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        myEnv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public String getNameInNamespace() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return ""; // %%% check this out: A URL context's name is ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      * Resolves 'name' into a target context with remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      * For example, with a JNDI URL "jndi://dnsname/rest_name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      * this method resolves "jndi://dnsname/" to a target context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      * and returns the target context with "rest_name".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      * The definition of "root URL" and how much of the URL to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
      * consume is implementation specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      * If rename() is supported for a particular URL scheme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      * getRootURLContext(), getURLPrefix(), and getURLSuffix()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
      * must be in sync wrt how URLs are parsed and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    abstract protected ResolveResult getRootURLContext(String url,
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    80
        Hashtable<?,?> env) throws NamingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      * Returns the suffix of the url. The result should be identical to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      * that of calling getRootURLContext().getRemainingName(), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      * without the overhead of doing anything with the prefix like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      * creating a context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      * This method returns a Name instead of a String because to give
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      * the provider an opportunity to return a Name (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      * for weakly separated naming systems like COS naming).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * The default implementation uses skips 'prefix', calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * UrlUtil.decode() on it, and returns the result as a single component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      * CompositeName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      * Subclass should override if this is not appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
      * This method is used only by rename().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      * If rename() is supported for a particular URL scheme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      * getRootURLContext(), getURLPrefix(), and getURLSuffix()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      * must be in sync wrt how URLs are parsed and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      * For many URL schemes, this method is very similar to URL.getFile(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      * except getFile() will return a leading slash in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      * 2nd, 3rd, and 4th cases. For schemes like "ldap" and "iiop",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      * the leading slash must be skipped before the name is an acceptable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      * format for operation by the Context methods. For schemes that treat the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      * leading slash as significant (such as "file"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      * the subclass must override getURLSuffix() to get the correct behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      * Remember, the behavior must match getRootURLContext().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   110
      * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      * URL                                     Suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      * foo://host:port                         <empty string>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      * foo://host:port/rest/of/name            rest/of/name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      * foo:///rest/of/name                     rest/of/name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * foo:/rest/of/name                       rest/of/name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      * foo:rest/of/name                        rest/of/name
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   117
      * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected Name getURLSuffix(String prefix, String url) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        String suffix = url.substring(prefix.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (suffix.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (suffix.charAt(0) == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            suffix = suffix.substring(1); // skip leading slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return new CompositeName().add(UrlUtil.decode(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new InvalidNameException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      * Finds the prefix of a URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      * Default implementation looks for slashes and then extracts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      * prefixes using String.substring().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      * Subclass should override if this is not appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      * This method is used only by rename().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      * If rename() is supported for a particular URL scheme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      * getRootURLContext(), getURLPrefix(), and getURLSuffix()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      * must be in sync wrt how URLs are parsed and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      * URL                                     Prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      * foo://host:port                         foo://host:port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      * foo://host:port/rest/of/name            foo://host:port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      * foo:///rest/of/name                     foo://
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      * foo:/rest/of/name                       foo:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      * foo:rest/of/name                        foo:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    protected String getURLPrefix(String url) throws NamingException {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 17725
diff changeset
   154
        int start = url.indexOf(':');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw new OperationNotSupportedException("Invalid URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        ++start; // skip ':'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (url.startsWith("//", start)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            start += 2;  // skip double slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // find last slash
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 17725
diff changeset
   165
            int posn = url.indexOf('/', start);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if (posn >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                start = posn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                start = url.length();  // rest of URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24685
diff changeset
   173
        // else 0 or 1 initial slashes; start is unchanged
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return url.substring(0, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Determines whether two URLs are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Default implementation uses String.equals().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Subclass should override if this is not appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * This method is used by rename().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected boolean urlEquals(String url1, String url2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return url1.equals(url2);
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
     * Gets the context in which to continue the operation. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * is called when this context is asked to process a multicomponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Name in which the first component is a URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Treat the first component like a junction: resolve it and then use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * NamingManager.getContinuationContext() to get the target context in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * which to operate on the remainder of the name (n.getSuffix(1)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    protected Context getContinuationContext(Name n) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        Object obj = lookup(n.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        CannotProceedException cpe = new CannotProceedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        cpe.setResolvedObj(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        cpe.setEnvironment(myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return NamingManager.getContinuationContext(cpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return ctx.lookup(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public Object lookup(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return lookup(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                return ctx.lookup(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void bind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            ctx.bind(res.getRemainingName(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void bind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            bind(name.get(0), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                ctx.bind(name.getSuffix(1), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public void rebind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            ctx.rebind(res.getRemainingName(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public void rebind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            rebind(name.get(0), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                ctx.rebind(name.getSuffix(1), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void unbind(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            ctx.unbind(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public void unbind(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            unbind(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                ctx.unbind(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
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
    public void rename(String oldName, String newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        String oldPrefix = getURLPrefix(oldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        String newPrefix = getURLPrefix(newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (!urlEquals(oldPrefix, newPrefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throw new OperationNotSupportedException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                "Renaming using different URL prefixes not supported : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                oldName + " " + newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        ResolveResult res = getRootURLContext(oldName, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            ctx.rename(res.getRemainingName(), getURLSuffix(newPrefix, newName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void rename(Name name, Name newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (newName.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                throw new OperationNotSupportedException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            "Renaming to a Name with more components not supported: " + newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            rename(name.get(0), newName.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            // > 1 component with 1st one being URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            // URLs must be identical; cannot deal with diff URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (!urlEquals(name.get(0), newName.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                throw new OperationNotSupportedException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    "Renaming using different URLs as first components not supported: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    name + " " + newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                ctx.rename(name.getSuffix(1), newName.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public NamingEnumeration<NameClassPair> list(String name)   throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return ctx.list(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return list(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                return ctx.list(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public NamingEnumeration<Binding> listBindings(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return ctx.listBindings(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return listBindings(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                return ctx.listBindings(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public void destroySubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            ctx.destroySubcontext(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public void destroySubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            destroySubcontext(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                ctx.destroySubcontext(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public Context createSubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return ctx.createSubcontext(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public Context createSubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return createSubcontext(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                return ctx.createSubcontext(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public Object lookupLink(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            return ctx.lookupLink(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            return lookupLink(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                return ctx.lookupLink(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        Context ctx = (Context)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return ctx.getNameParser(res.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            return getNameParser(name.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            Context ctx = getContinuationContext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                return ctx.getNameParser(name.getSuffix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public String composeName(String name, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        throws NamingException {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   479
            if (prefix.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                return name;
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   481
            } else if (name.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                return prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                return (prefix + "/" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            }
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 Name composeName(Name name, Name prefix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        Name result = (Name)prefix.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        result.addAll(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public Object removeFromEnvironment(String propName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (myEnv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return myEnv.remove(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public Object addToEnvironment(String propName, Object propVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        throws NamingException {
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
   504
            if (myEnv == null) {
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
   505
                myEnv = new Hashtable<String, Object>(11, 0.75f);
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
   506
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            return myEnv.put(propName, propVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   510
    @SuppressWarnings("unchecked") // clone()
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   511
    public Hashtable<String, Object> getEnvironment() throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (myEnv == null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   513
            return new Hashtable<>(5, 0.75f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } else {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   515
            return (Hashtable<String, Object>)myEnv.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
// To test, declare getURLPrefix and getURLSuffix static.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        String[] tests = {"file://host:port",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                          "file:///rest/of/name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                          "file://host:port/rest/of/name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                          "file:/rest/of/name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                          "file:rest/of/name"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        for (int i = 0; i < tests.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            String pre = getURLPrefix(tests[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            System.out.println(pre);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            System.out.println(getURLSuffix(pre, tests[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
}