jdk/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8172 3f25c3770191
child 10324 e28265130e4f
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8172
diff changeset
     2
 * Copyright (c) 1999, 2011, 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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected Hashtable environment = null;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *          calculate the "resolved name" when filling  in a NamingException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param environment The environment used by the caller. It is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * when setting the "environment" of a CannotProceedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public Continuation(Name top, Hashtable environment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        starter = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.environment = environment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Determines whether this Continuation contains data that should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * used to continue the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return true if operation should continue; false if operation has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * completed (successfully or unsuccessfully).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public boolean isContinue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return continuing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Sets this Continuation to indicate successful completion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Subsequent calls to isContinue() will return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * This method is different from the setError() methods only from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the standpoint that this method does not set any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * fields such as resolved object or resolved context. This is because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * this method is typically called when the context recognizes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the operation has successfully completed and that the continuation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * already contains the appropriately set fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see setError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see setErrorNNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void setSuccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        continuing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Fills in an exception's fields using data from this Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The resolved name is set by subtracting remainingName from starter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * %%% This might not not always produce the correct answer wrt trailing "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * If the exception is a CannotProceedException, its environment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * altName, and altNameCtx fields are set using this continuation's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * environment, relativeResolvedName, and resolvedContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param e The non-null naming exception to fill.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return The non-null naming exception with its fields set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * data from this Continuation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public NamingException fillInException(NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        e.setRemainingName(remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        e.setResolvedObj(resolvedObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
8172
3f25c3770191 6997561: A request for better error handling in JNDI
vinnie
parents: 5506
diff changeset
   146
        if (starter == null || starter.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            e.setResolvedName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        else if (remainingName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            e.setResolvedName(starter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            e.setResolvedName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                starter.getPrefix(starter.size() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                  remainingName.size()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if ((e instanceof CannotProceedException)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            CannotProceedException cpe = (CannotProceedException)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            Hashtable env = (environment == null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                new Hashtable(11) : (Hashtable)environment.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            cpe.setEnvironment(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            cpe.setAltNameCtx(resolvedContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            cpe.setAltName(relativeResolvedName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Sets this Continuation to indicated that an error has occurred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * and that the remaining name is rename + "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * This method is typically called by _nns methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * given a name to process. It might process part of that name but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * encountered some error. Consequenetly, it would call setErrorNNS()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * with the remaining name. Since the _nns method was expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * operate upon the "nns" of the original name, the remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * must include the "nns". That's why this method adds a trailing "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * After this method is called, isContinuing() returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void setErrorNNS(Object resObj, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Name nm = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            nm.add("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // ignore; can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        setErrorAux(resObj, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Form that accepts a String name instead of a Name name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param remain The possibly String remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #setErrorNNS(java.lang.Object, javax.naming.Name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public void setErrorNNS(Object resObj, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (remain != null && !remain.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            rname.add("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // ignore, can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        setErrorAux(resObj, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Sets this Continuation to indicated that an error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * and supply resolved information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * This method is typically called by methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * given a name to process. It might process part of that name but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * encountered some error. Consequenetly, it would call setError()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * with the resolved object and the remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * After this method is called, isContinuing() returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param remain The possibly null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public void setError(Object resObj, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (remain != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            remainingName = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            remainingName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        setErrorAux(resObj, remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Form that accepts a String name instead of a Name name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param resObj The possibly null object that was resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param remain The possibly String remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see #setError(java.lang.Object, javax.naming.Name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void setError(Object resObj, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (remain != null && !remain.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                // ignore; can't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        setErrorAux(resObj, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private void setErrorAux(Object resObj, Name rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        remainingName = rname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        resolvedObj = resObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        continuing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private void setContinueAux(Object resObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        Name relResName, Context currCtx,  Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (resObj instanceof LinkRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            setContinueLink(resObj, relResName, currCtx, remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            remainingName = remain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            resolvedObj = resObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            relativeResolvedName = relResName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            resolvedContext = currCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            continuing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Sets this Continuation with the supplied data, and set remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * to be "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * This method is typically called by _nns methods that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * given a name to process. It might the name (without the nns) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * continue process of the nns elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Consequently, it would call this form of the setContinueNNS().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * This method supplies "/" as the remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public void setContinueNNS(Object resObj, Name relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        setContinue(resObj, relResName, currCtx, PartialCompositeContext._NNS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Overloaded form that accesses String names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #setContinueNNS(java.lang.Object, javax.naming.Name, javax.naming.Context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public void setContinueNNS(Object resObj, String relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        CompositeName relname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            relname.add(relResName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } catch (NamingException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        setContinue(resObj, relname, currCtx, PartialCompositeContext._NNS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Sets this Continuation with the supplied data, and set remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * to be the empty name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * This method is typically called by list-style methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * in which the target context implementing list() expects an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * empty name. For example when c_list() is given a non-empty name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * process, it would resolve that name, and then call setContinue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * with the resolved object so that the target context to be listed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * would be called with the empty name (i.e. list the target context itself).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public void setContinue(Object obj, Name relResName, Context currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        setContinueAux(obj, relResName, currCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            (Name)PartialCompositeContext._EMPTY_NAME.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Sets this Continuation with the supplied data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * This method is typically called by a method that has been asked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * to operate on a name. The method resolves part of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * (relResName) to obj and sets the unprocessed part to rename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * It calls setContinue() so that the operation can be continued
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * using this data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * After this method is called, isContinuing() returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public void setContinue(Object obj, Name relResName, Context currCtx, Name remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (remain != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            this.remainingName = (Name)(remain.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            this.remainingName = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        setContinueAux(obj, relResName, currCtx, remainingName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * String overload.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param resObj The possibly null resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param relResName The non-null resolved name relative to currCtx.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param currCtx The non-null context from which relResName is to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param remain The non-null remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see #setContinue(java.lang.Object, java.lang.String, javax.naming.Context, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public void setContinue(Object obj, String relResName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Context currCtx, String remain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        CompositeName relname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (!relResName.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                relname.add(relResName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            } catch (NamingException e){}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (!remain.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                rname.add(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        setContinueAux(obj, relname, currCtx, rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * %%% This method is kept only for backward compatibility. Delete when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * old implementations updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Replaced by setContinue(obj, relResName, (Context)currCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @deprecated
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
    public void setContinue(Object obj, Object currCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        setContinue(obj, null, (Context)currCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Sets this Continuation to process a linkRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * %%% Not working yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private void setContinueLink(Object linkRef, Name relResName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Context resolvedCtx, Name rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        this.followingLink = linkRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        this.remainingName = rname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        this.resolvedObj = resolvedCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        this.relativeResolvedName = PartialCompositeContext._EMPTY_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        this.resolvedContext = resolvedCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        this.continuing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (remainingName != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return starter.toString() + "; remainingName: '" + remainingName + "'";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return starter.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public String toString(boolean detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (!detail || this.resolvedObj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                return this.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return this.toString() + "; resolvedObj: " + this.resolvedObj +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            "; relativeResolvedName: " + relativeResolvedName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            "; resolvedContext: " + resolvedContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private static final long serialVersionUID = 8162530656132624308L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}