src/java.naming/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
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: 3288
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: 3288
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: 3288
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3288
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3288
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.ctx;
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 java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.naming.spi.Resolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.naming.spi.ResolveResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.naming.spi.NamingManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * PartialCompositeContext implements Context operations on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * composite names using implementations of the p_ interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * defined by its subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * The main purpose provided by this class is that it deals with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * partial resolutions and continuations, so that callers of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * Context operation don't have to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * Types of clients that will be direct subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * PartialCompositeContext may be service providers that implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * one of the JNDI protocols, but which do not deal with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * continuations.  Usually, service providers will be using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * one of the subclasses of PartialCompositeContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public abstract class PartialCompositeContext implements Context, Resolver {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected static final int _PARTIAL = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected static final int _COMPONENT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected static final int _ATOMIC = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected int _contextType = _PARTIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final CompositeName _EMPTY_NAME = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static CompositeName _NNS_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            _NNS_NAME = new CompositeName("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            // Should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected PartialCompositeContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
// ------ Abstract methods whose implementations come from subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /* Equivalent to method in  Resolver interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected abstract ResolveResult p_resolveToClass(Name name,
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    80
        Class<?> contextType, Continuation cont) throws NamingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* Equivalent to methods in Context interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected abstract Object p_lookup(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected abstract Object p_lookupLink(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        throws NamingException;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    87
    protected abstract NamingEnumeration<NameClassPair> p_list(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Continuation cont) throws NamingException;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    89
    protected abstract NamingEnumeration<Binding> p_listBindings(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        Continuation cont) throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected abstract void p_bind(Name name, Object obj, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected abstract void p_rebind(Name name, Object obj, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected abstract void p_unbind(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected abstract void p_destroySubcontext(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected abstract Context p_createSubcontext(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected abstract void p_rename(Name oldname, Name newname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                     Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected abstract NameParser p_getNameParser(Name name, Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
// ------ should be overridden by subclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
// ------ not abstract only for backward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * A cheap way of getting the environment.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 10324
diff changeset
   112
     * Default implementation is NOT cheap because it simply calls
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * getEnvironment(), which most implementations clone before returning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Subclass should ALWAYS override this with the cheapest possible way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * The toolkit knows to clone when necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return The possibly null environment of the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   118
    protected Hashtable<?,?> p_getEnvironment() throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return getEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
// ------ implementations of methods in Resolver and Context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
// ------ using corresponding p_ methods provided by subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /* implementations for method in Resolver interface using p_ method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public ResolveResult resolveToClass(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                        Class<? extends Context> contextType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return resolveToClass(new CompositeName(name), contextType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public ResolveResult resolveToClass(Name name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                        Class<? extends Context> contextType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        PartialCompositeContext ctx = this;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   140
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ResolveResult answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        Name nm = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            answer = ctx.p_resolveToClass(nm, contextType, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                answer = ctx.p_resolveToClass(nm, contextType, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if (!(cctx instanceof Resolver)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            answer = ((Resolver)cctx).resolveToClass(e.getRemainingName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                                     contextType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /* implementations for methods in Context interface using p_ methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return lookup(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public Object lookup(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        PartialCompositeContext ctx = this;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   171
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Object answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        Name nm = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            answer = ctx.p_lookup(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                answer = ctx.p_lookup(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            answer = cctx.lookup(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public void bind(String name, Object newObj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        bind(new CompositeName(name), newObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public void bind(Name name, Object newObj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   197
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            ctx.p_bind(nm, newObj, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                ctx.p_bind(nm, newObj, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            cctx.bind(e.getRemainingName(), newObj);
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 void rebind(String name, Object newObj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        rebind(new CompositeName(name), newObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void rebind(Name name, Object newObj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   219
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            ctx.p_rebind(nm, newObj, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                ctx.p_rebind(nm, newObj, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            cctx.rebind(e.getRemainingName(), newObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void unbind(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        unbind(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public void unbind(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   241
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            ctx.p_unbind(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                ctx.p_unbind(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            cctx.unbind(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public void rename(String oldName, String newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        rename(new CompositeName(oldName), new CompositeName(newName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void rename(Name oldName, Name newName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        Name nm = oldName;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   265
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        Continuation cont = new Continuation(oldName, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            ctx.p_rename(nm, newName, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                ctx.p_rename(nm, newName, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (e.getRemainingNewName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                // %%% e.getRemainingNewName() should never be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                newName = e.getRemainingNewName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            cctx.rename(e.getRemainingName(), newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public NamingEnumeration<NameClassPair> list(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return list(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public NamingEnumeration<NameClassPair> list(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   296
        NamingEnumeration<NameClassPair> answer;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   297
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            answer = ctx.p_list(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                answer = ctx.p_list(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            answer = cctx.list(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public NamingEnumeration<Binding> listBindings(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return listBindings(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public NamingEnumeration<Binding> listBindings(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        throws NamingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   325
        NamingEnumeration<Binding> answer;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   326
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            answer = ctx.p_listBindings(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                answer = ctx.p_listBindings(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            answer = cctx.listBindings(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public void destroySubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        destroySubcontext(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public void destroySubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        Name nm = name;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   350
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            ctx.p_destroySubcontext(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                ctx.p_destroySubcontext(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            cctx.destroySubcontext(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public Context createSubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return createSubcontext(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public Context createSubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        Name nm = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        Context answer;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   374
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            answer = ctx.p_createSubcontext(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                answer = ctx.p_createSubcontext(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            answer = cctx.createSubcontext(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public Object lookupLink(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return lookupLink(new CompositeName(name));
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 Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        PartialCompositeContext ctx = this;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   397
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        Object answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        Name nm = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            answer = ctx.p_lookupLink(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                answer = ctx.p_lookupLink(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            answer = cctx.lookupLink(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return answer;
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 NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return getNameParser(new CompositeName(name));
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 NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        PartialCompositeContext ctx = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        Name nm = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        NameParser answer;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   424
        Hashtable<?,?> env = p_getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        Continuation cont = new Continuation(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            answer = ctx.p_getNameParser(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            while (cont.isContinue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                nm = cont.getRemainingName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                ctx = getPCContext(cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                answer = ctx.p_getNameParser(nm, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            Context cctx = NamingManager.getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            answer = cctx.getNameParser(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return answer;
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 String composeName(String name, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        Name fullName = composeName(new CompositeName(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                    new CompositeName(prefix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return fullName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * This default implementation simply concatenates the two names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * There's one twist when the "java.naming.provider.compose.elideEmpty"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * environment setting is set to "true":  if each name contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * nonempty component, and if 'prefix' ends with an empty component or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * 'name' starts with one, then one empty component is dropped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * For example:
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   455
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *                            elideEmpty=false     elideEmpty=true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * {"a"} + {"b"}          =>  {"a", "b"}           {"a", "b"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * {"a"} + {""}           =>  {"a", ""}            {"a", ""}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * {"a"} + {"", "b"}      =>  {"a", "", "b"}       {"a", "b"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * {"a", ""} + {"b", ""}  =>  {"a", "", "b", ""}   {"a", "b", ""}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * {"a", ""} + {"", "b"}  =>  {"a", "", "", "b"}   {"a", "", "b"}
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   462
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public Name composeName(Name name, Name prefix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Name res = (Name)prefix.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        res.addAll(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String elide = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            p_getEnvironment().get("java.naming.provider.compose.elideEmpty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (elide == null || !elide.equalsIgnoreCase("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        int len = prefix.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (!allEmpty(prefix) && !allEmpty(name)) {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   480
            if (res.get(len - 1).isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                res.remove(len - 1);
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   482
            } else if (res.get(len).isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                res.remove(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
// ------ internal methods used by PartialCompositeContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Tests whether a name contains a nonempty component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    protected static boolean allEmpty(Name name) {
3227
a3484e08f2bc 6453837: PartialCompositeContext.allEmpty is buggy
xuelei
parents: 2
diff changeset
   496
        Enumeration<String> enum_ = name.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        while (enum_.hasMoreElements()) {
3227
a3484e08f2bc 6453837: PartialCompositeContext.allEmpty is buggy
xuelei
parents: 2
diff changeset
   498
            if (!enum_.nextElement().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Retrieves a PartialCompositeContext for the resolved object in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * cont.  Throws CannotProceedException if not successful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    protected static PartialCompositeContext getPCContext(Continuation cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        Object obj = cont.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        PartialCompositeContext pctx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (obj instanceof PartialCompositeContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // Just cast if octx already is PartialCompositeContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // %%% ignoring environment for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return (PartialCompositeContext)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            throw cont.fillInException(new CannotProceedException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
};