src/java.naming/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
child 58531 9b40d05c9f66
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.ctx;
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 java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * This class contains information required to continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * the method (place where it left off, and remaining name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  * continue).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class Continuation extends ResolveResult {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * The name that we started out with. It is initialized by the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * and used to calculate to "resolved name" in NamingException in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * fillInException().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * %%% Note that this approach does not always do the calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * correctly with respect to absence or presence of the trailing slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * for resolved name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected Name starter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Whether links were encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected Object followingLink = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * The environment used by the caller. Initialized by constructor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * used when filling out a CannotProceedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 9035
diff changeset
    60
    protected Hashtable<?,?> environment = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Indicates whether the Continuation instance indicates that the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * should be continued using the data in the Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Typically, this is only false if an error has been encountered or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * the operation has succeeded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected boolean continuing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * The last resolved context. Used to set the "AltNameCtx" in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * CannotProceedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected Context resolvedContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * The resolved name relative to resolvedContext. Used to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * "AltName" in a CannotProceedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected Name relativeResolvedName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Constructs a new instance of Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Used as dummy for contexts that do not do federation (e.g. for schema ops)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public Continuation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructs a new instance of Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param top The name of the object that is to be resolved/operated upon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *          This becomes the Continuation's 'starter' and is used to
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
    93
     *          calculate the "resolved name" when filling in a NamingException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param environment The environment used by the caller. It is used
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
    95
     *          when setting the "environment" of a CannotProceedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
    97
    @SuppressWarnings("unchecked")  // For Hashtable clone: environment.clone()
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 9035
diff changeset
    98
    public Continuation(Name top, Hashtable<?,?> environment) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        starter = top;
17725
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
   101
        this.environment = (Hashtable<?,?>)
5d515b9ffbbe 8010815: some constructors issues in com.sun.jndi.toolkit
xuelei
parents: 10324
diff changeset
   102
                ((environment == null) ? null : environment.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Determines whether this Continuation contains data that should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * used to continue the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return true if operation should continue; false if operation has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * completed (successfully or unsuccessfully).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public boolean isContinue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return continuing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Sets this Continuation to indicate successful completion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Subsequent calls to isContinue() will return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * This method is different from the setError() methods only from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * the standpoint that this method does not set any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * fields such as resolved object or resolved context. This is because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * this method is typically called when the context recognizes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * the operation has successfully completed and that the continuation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * already contains the appropriately set fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see setError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see setErrorNNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void setSuccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        continuing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Fills in an exception's fields using data from this Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The resolved name is set by subtracting remainingName from starter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * %%% This might not not always produce the correct answer wrt trailing "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * If the exception is a CannotProceedException, its environment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * altName, and altNameCtx fields are set using this continuation's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * environment, relativeResolvedName, and resolvedContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param e The non-null naming exception to fill.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @return The non-null naming exception with its fields set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * data from this Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public NamingException fillInException(NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        e.setRemainingName(remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        e.setResolvedObj(resolvedObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
8172
3f25c3770191 6997561: A request for better error handling in JNDI
vinnie
parents: 5506
diff changeset
   148
        if (starter == null || starter.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            e.setResolvedName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        else if (remainingName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            e.setResolvedName(starter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            e.setResolvedName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                starter.getPrefix(starter.size() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                  remainingName.size()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if ((e instanceof CannotProceedException)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            CannotProceedException cpe = (CannotProceedException)e;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 9035
diff changeset
   159
            Hashtable<?,?> env = (environment == null ?
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 9035
diff changeset
   160
                new Hashtable<>(11) : (Hashtable<?,?>)environment.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            cpe.setEnvironment(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            cpe.setAltNameCtx(resolvedContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            cpe.setAltName(relativeResolvedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Sets this Continuation to indicated that an error has occurred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * and that the remaining name is rename + "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * This method is typically called by _nns methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * given a name to process. It might process part of that name but
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 17725
diff changeset
   175
     * encountered some error. Consequently, it would call setErrorNNS()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * with the remaining name. Since the _nns method was expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * operate upon the "nns" of the original name, the remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * must include the "nns". That's why this method adds a trailing "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * After this method is called, isContinuing() returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void setErrorNNS(Object resObj, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Name nm = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            nm.add("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            // ignore; can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        setErrorAux(resObj, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Form that accepts a String name instead of a Name name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param remain The possibly String remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #setErrorNNS(java.lang.Object, javax.naming.Name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public void setErrorNNS(Object resObj, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   206
            if (remain != null && !remain.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            rname.add("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // ignore, can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        setErrorAux(resObj, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Sets this Continuation to indicated that an error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * and supply resolved information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * This method is typically called by methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * given a name to process. It might process part of that name but
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 17725
diff changeset
   222
     * encountered some error. Consequently, it would call setError()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * with the resolved object and the remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * After this method is called, isContinuing() returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param remain The possibly null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void setError(Object resObj, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (remain != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            remainingName = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            remainingName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        setErrorAux(resObj, remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Form that accepts a String name instead of a Name name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param remain The possibly String remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see #setError(java.lang.Object, javax.naming.Name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public void setError(Object resObj, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        CompositeName rname = new CompositeName();
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   250
        if (remain != null && !remain.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                // ignore; can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        setErrorAux(resObj, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private void setErrorAux(Object resObj, Name rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        remainingName = rname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        resolvedObj = resObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        continuing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private void setContinueAux(Object resObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        Name relResName, Context currCtx,  Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (resObj instanceof LinkRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            setContinueLink(resObj, relResName, currCtx, remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            remainingName = remain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            resolvedObj = resObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            relativeResolvedName = relResName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            resolvedContext = currCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            continuing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
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
     * Sets this Continuation with the supplied data, and set remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * to be "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * This method is typically called by _nns methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * given a name to process. It might the name (without the nns) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * continue process of the nns elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Consequently, it would call this form of the setContinueNNS().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * This method supplies "/" as the remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public void setContinueNNS(Object resObj, Name relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        setContinue(resObj, relResName, currCtx, PartialCompositeContext._NNS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Overloaded form that accesses String names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #setContinueNNS(java.lang.Object, javax.naming.Name, javax.naming.Context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public void setContinueNNS(Object resObj, String relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        CompositeName relname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            relname.add(relResName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        } catch (NamingException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        setContinue(resObj, relname, currCtx, PartialCompositeContext._NNS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Sets this Continuation with the supplied data, and set remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * to be the empty name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This method is typically called by list-style methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * in which the target context implementing list() expects an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * empty name. For example when c_list() is given a non-empty name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * process, it would resolve that name, and then call setContinue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * with the resolved object so that the target context to be listed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * would be called with the empty name (i.e. list the target context itself).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   332
     * @param obj The possibly null resolved object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public void setContinue(Object obj, Name relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        setContinueAux(obj, relResName, currCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            (Name)PartialCompositeContext._EMPTY_NAME.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Sets this Continuation with the supplied data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * This method is typically called by a method that has been asked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * to operate on a name. The method resolves part of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * (relResName) to obj and sets the unprocessed part to rename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * It calls setContinue() so that the operation can be continued
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * using this data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   352
     * @param obj The possibly null resolved object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public void setContinue(Object obj, Name relResName, Context currCtx, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (remain != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            this.remainingName = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            this.remainingName = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        setContinueAux(obj, relResName, currCtx, remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * String overload.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 25859
diff changeset
   369
     * @param obj The possibly null resolved object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see #setContinue(java.lang.Object, java.lang.String, javax.naming.Context, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public void setContinue(Object obj, String relResName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Context currCtx, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        CompositeName relname = new CompositeName();
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   378
        if (!relResName.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                relname.add(relResName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            } catch (NamingException e){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        CompositeName rname = new CompositeName();
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   385
        if (!remain.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        setContinueAux(obj, relname, currCtx, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * %%% This method is kept only for backward compatibility. Delete when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * old implementations updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Replaced by setContinue(obj, relResName, (Context)currCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void setContinue(Object obj, Object currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        setContinue(obj, null, (Context)currCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Sets this Continuation to process a linkRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * %%% Not working yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private void setContinueLink(Object linkRef, Name relResName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        Context resolvedCtx, Name rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        this.followingLink = linkRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        this.remainingName = rname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        this.resolvedObj = resolvedCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        this.relativeResolvedName = PartialCompositeContext._EMPTY_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        this.resolvedContext = resolvedCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        this.continuing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (remainingName != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return starter.toString() + "; remainingName: '" + remainingName + "'";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            return starter.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public String toString(boolean detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (!detail || this.resolvedObj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return this.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return this.toString() + "; resolvedObj: " + this.resolvedObj +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            "; relativeResolvedName: " + relativeResolvedName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            "; resolvedContext: " + resolvedContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    private static final long serialVersionUID = 8162530656132624308L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
}