jdk/src/share/classes/com/sun/jndi/cosnaming/CNCtx.java
author prappo
Fri, 01 Aug 2014 22:32:51 +0100
changeset 25808 e113d0a0fde0
parent 13153 338ae0f48371
permissions -rw-r--r--
8054158: Fix typos in JNDI-related packages Reviewed-by: rriggs, vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
     2
 * Copyright (c) 1999, 2012, 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.cosnaming;
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.NamingManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.spi.ResolveResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.omg.CosNaming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.omg.CosNaming.NamingContextPackage.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.jndi.toolkit.corba.CorbaUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// Needed for creating default ORB
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * Provides a bridge to the CosNaming server provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * JavaIDL. This class provides the InitialContext from CosNaming.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  * @author Raj Krishnamurthy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class CNCtx implements javax.naming.Context {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    61
    /*
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    62
     * Implement one shared ORB among all CNCtx.  However, there is a public constructor
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    63
     * accepting an ORB, so we need the option of using a given ORB.
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    64
     */
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    65
    private static ORB _defaultOrb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    ORB _orb;                   // used by ExceptionMapper and RMI/IIOP factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public NamingContext _nc;   // public for accessing underlying NamingContext
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    68
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    69
    private synchronized static ORB getDefaultOrb() {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    70
        if (_defaultOrb == null) {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    71
            _defaultOrb = CorbaUtils.getOrb(null, -1,
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    72
               new Hashtable<String, java.lang.Object>());
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    73
        }
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    74
        return _defaultOrb;
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    75
    }
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
    76
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private NameComponent[] _name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    79
    Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static final CNNameParser parser = new CNNameParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    boolean federation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // Reference counter for tracking _orb references
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    OrbReuseTracker orbTracker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    int enumCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    boolean isCloseCalled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      * Create a CNCtx object. Gets the initial naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * reference for the COS Naming Service from the ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * The ORB can be passed in via the java.naming.corba.orb property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      * or be created using properties in the environment properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      * @param env Environment properties for initializing name service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
      * @exception NamingException Cannot initialize ORB or naming context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    98
    @SuppressWarnings("unchecked")
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    99
    CNCtx(Hashtable<?,?> env) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (env != null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   101
            env = (Hashtable<?,?>)env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   103
        _env = (Hashtable<String, java.lang.Object>)env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        federation = "true".equals(env != null ? env.get(FED_PROP) : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        initOrbAndRootContext(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private CNCtx() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * This method is used by the iiop and iiopname URL Context factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   114
    @SuppressWarnings("unchecked")
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   115
    public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        CNCtx ctx = new CNCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (env != null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   119
            env = (Hashtable<?,?>) env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   121
        ctx._env = (Hashtable<String, java.lang.Object>)env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String rest = ctx.initUsingUrl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            env != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                : null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            url, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // rest is the INS name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // Return the parsed form to prevent subsequent lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // from parsing the string as a composite name
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   131
        // The caller should be aware that a toString() of the name,
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   132
        // which came from the environment will yield its INS syntax,
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   133
        // rather than a composite syntax
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return new ResolveResult(ctx, parser.parse(rest));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      * Creates a CNCtx object which supports the javax.naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      * apis given a COS Naming Context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      * @param orb The ORB used by this context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      * @param tracker The ORB reuse tracker for tracking references to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      *  orb object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      * @param nctx The COS NamingContext object associated with this context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      * @param name The name of this context relative to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   147
    CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   148
          Hashtable<String, java.lang.Object> env, NameComponent[]name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (orb == null || nctx == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    "Must supply ORB or NamingContext");
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   153
            if (orb != null) {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   154
                _orb = orb;
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   155
            } else {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   156
                _orb = getDefaultOrb();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            _nc = nctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            _env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            _name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            federation = "true".equals(env != null ? env.get(FED_PROP) : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    NameComponent[] makeFullName(NameComponent[] child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (_name == null || _name.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            return child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        NameComponent[] answer = new NameComponent[_name.length+child.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        // parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        System.arraycopy(_name, 0, answer, 0, _name.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        System.arraycopy(child, 0, answer, _name.length, child.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public String getNameInNamespace() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (_name == null || _name.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return CNNameParser.cosNameToInsString(_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * These are the URL schemes that need to be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * IOR and corbaloc URLs can be passed directly to ORB.string_to_object()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static boolean isCorbaUrl(String url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return url.startsWith("iiop://")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            || url.startsWith("iiopname://")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            || url.startsWith("corbaname:")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
      * Initializes the COS Naming Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      * This method initializes the three instance fields:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      * _nc : The root naming context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      * _orb: The ORB to use for connecting RMI/IIOP stubs and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      *       getting the naming context (_nc) if one was not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      *       explicitly via PROVIDER_URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      * _name: The name of the root naming context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      * _orb is obtained from java.naming.corba.orb if it has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      * Otherwise, _orb is created using the host/port from PROVIDER_URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      * (if it contains an "iiop" or "iiopname" URL), or from initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      * properties specified in env.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      * _nc is obtained from the IOR stored in PROVIDER_URL if it has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      * set and does not contain an "iiop" or "iiopname" URL. It can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      * a stringified IOR, "corbaloc" URL, "corbaname" URL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      * or a URL (such as file/http/ftp) to a location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      * containing a stringified IOR. If PROVIDER_URL has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      * set in this way, it is obtained from the result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      *     ORB.resolve_initial_reference("NameService");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      * _name is obtained from the "iiop", "iiopname", or "corbaname" URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      * It is the empty name by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      * @param env Environment The possibly null environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      * @exception NamingException When an error occurs while initializing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      * ORB or the naming context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   226
    private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        org.omg.CORBA.ORB inOrb = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        String ncIor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   230
        if (inOrb == null && env != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   234
        if (inOrb == null)
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   235
            inOrb = getDefaultOrb(); // will create a default ORB if none exists
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // Extract PROVIDER_URL from environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        String provUrl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (env != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            provUrl = (String)env.get(javax.naming.Context.PROVIDER_URL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (provUrl != null && !isCorbaUrl(provUrl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            // Initialize the root naming context by using the IOR supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            // in the PROVIDER_URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            ncIor = getStringifiedIor(provUrl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            setOrbAndRootContext(inOrb, ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else if (provUrl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // Initialize the root naming context by using the URL supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            // in the PROVIDER_URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            String insName = initUsingUrl(inOrb, provUrl, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            // If name supplied in URL, resolve it to a NamingContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (insName.length() > 0) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   255
                _name = CNNameParser.nameToCosName(parser.parse(insName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    org.omg.CORBA.Object obj = _nc.resolve(_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    _nc = NamingContextHelper.narrow(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    if (_nc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        throw new ConfigurationException(insName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            " does not name a NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                } catch (org.omg.CORBA.BAD_PARAM e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    throw new ConfigurationException(insName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        " does not name a NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    throw ExceptionMapper.mapException(e, this, _name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // No PROVIDER_URL supplied; initialize using defaults
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   272
            if (debug) {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   273
                System.err.println("Getting default ORB: " + inOrb + env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            setOrbAndRootContext(inOrb, (String)null);
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
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   280
    private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return initUsingIiopUrl(orb, url, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return initUsingCorbanameUrl(orb, url, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Handles "iiop" and "iiopname" URLs (INS 98-10-11)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   292
    private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        throws NamingException {
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   294
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   295
        if (defOrb == null)
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   296
            defOrb = getDefaultOrb();
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   297
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            IiopUrl parsedUrl = new IiopUrl(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            NamingException savedException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   303
            for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                try {
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   306
                    try {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   307
                        String tmpUrl = "corbaloc:iiop:" + addr.host
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   308
                            + ":" + addr.port + "/NameService";
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   309
                        if (debug) {
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   310
                            System.err.println("Using url: " + tmpUrl);
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   311
                        }
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   312
                        org.omg.CORBA.Object rootCtx =
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   313
                            defOrb.string_to_object(tmpUrl);
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   314
                        setOrbAndRootContext(defOrb, rootCtx);
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   315
                        return parsedUrl.getStringName();
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   316
                    } catch (Exception e) {} // keep going
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    // Get ORB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        System.err.println("Getting ORB for " + addr.host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            + " and port " + addr.port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    // Assign to fields
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   325
                    setOrbAndRootContext(defOrb, (String)null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    return parsedUrl.getStringName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    savedException = ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (savedException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                throw savedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                throw new ConfigurationException("Problem with URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            throw new ConfigurationException(e.getMessage());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Initializes using "corbaname" URL (INS 99-12-03)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   345
    private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        throws NamingException {
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   347
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   348
        if (orb == null)
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   349
                orb = getDefaultOrb();
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
   350
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            CorbanameUrl parsedUrl = new CorbanameUrl(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            String corbaloc = parsedUrl.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            String cosName = parsedUrl.getStringName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            setOrbAndRootContext(orb, corbaloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return parsedUrl.getStringName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw new ConfigurationException(e.getMessage());
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
    private void setOrbAndRootContext(ORB orb, String ncIor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        _orb = orb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            org.omg.CORBA.Object ncRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (ncIor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    System.err.println("Passing to string_to_object: " + ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                ncRef = _orb.string_to_object(ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                ncRef = _orb.resolve_initial_references("NameService");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                System.err.println("Naming Context Ref: " + ncRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            _nc = NamingContextHelper.narrow(ncRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            if (_nc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (ncIor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        "Cannot convert IOR to a NamingContext: " + ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
"ORB.resolve_initial_references(\"NameService\") does not return a NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
"COS Name Service not registered with ORB under the name 'NameService'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            ne.setRootCause(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } catch (org.omg.CORBA.COMM_FAILURE e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                new CommunicationException("Cannot connect to ORB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } catch (org.omg.CORBA.BAD_PARAM e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            NamingException ne = new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                "Invalid URL or IOR: " + ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } catch (org.omg.CORBA.INV_OBJREF e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            NamingException ne = new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                "Invalid object reference: " + ncIor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private void setOrbAndRootContext(ORB orb, org.omg.CORBA.Object ncRef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        _orb = orb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            _nc = NamingContextHelper.narrow(ncRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            if (_nc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    "Cannot convert object reference to NamingContext: " + ncRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        } catch (org.omg.CORBA.COMM_FAILURE e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                new CommunicationException("Cannot connect to ORB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    private String getStringifiedIor(String url) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (url.startsWith("IOR:") || url.startsWith("corbaloc:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            InputStream in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                URL u = new URL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                in = u.openStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    BufferedReader bufin =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        new BufferedReader(new InputStreamReader(in, "8859_1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    String str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    while ((str = bufin.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        if (str.startsWith("IOR:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    new ConfigurationException("Invalid URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        new ConfigurationException("Invalid URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            throw new ConfigurationException(url + " does not contain an IOR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      * Does the job of calling the COS Naming API,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      * resolve, and performs the exception mapping. If the resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      * object is a COS Naming Context (sub-context), then this function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      * returns a new JNDI naming context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      * @param path the NameComponent[] object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      * @exception NotFound No objects under the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      * @exception CannotProceed Unable to obtain a continuation context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      * @exception InvalidName Name not understood.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
      * @return Resolved object returned by the COS Name Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    java.lang.Object callResolve(NameComponent[] path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                org.omg.CORBA.Object obj = _nc.resolve(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    NamingContext nc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        NamingContextHelper.narrow(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    if (nc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        return new CNCtx(_orb, orbTracker, nc, _env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                        makeFullName(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                } catch (org.omg.CORBA.SystemException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                throw ExceptionMapper.mapException(e, this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      * Converts the "String" name into a CompositeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
      * returns the object resolved by the COS Naming api,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
      * resolve. Returns the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      * Returns either an org.omg.CORBA.Object or javax.naming.Context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
      * @param name string used to resolve the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
      * @exception NamingException See callResolve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      * @return the resolved object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public java.lang.Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            System.out.println("Looking up: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return lookup(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
      * Converts the "Name" name into a NameComponent[] object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      * returns the object resolved by the COS Naming api,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      * resolve. Returns the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
      * Returns either an org.omg.CORBA.Object or javax.naming.Context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      * @param name JNDI Name used to resolve the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
      * @exception NamingException See callResolve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      * @return the resolved object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public java.lang.Object lookup(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if (name.size() == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return this; // %%% should clone() so that env can be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                java.lang.Object answer = callResolve(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    return NamingManager.getObjectInstance(answer, name, this, _env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    NamingException ne = new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        "problem generating object using object factory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            } catch (CannotProceedException cpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                javax.naming.Context cctx = getContinuationContext(cpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                return cctx.lookup(cpe.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      * Performs bind or rebind in the context depending on whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      * flag rebind is set. The only objects allowed to be bound are of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
      * types org.omg.CORBA.Object, org.omg.CosNaming.NamingContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      * You can use a state factory to turn other objects (such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
      * Remote) into these acceptable forms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
      * Uses the COS Naming apis bind/rebind or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
      * bind_context/rebind_context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
      * @param pth NameComponent[] object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
      * @param obj Object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
      * @param rebind perform rebind ? if true performs a rebind.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
      * @exception NotFound No objects under the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
      * @exception CannotProceed Unable to obtain a continuation context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
      * @exception AlreadyBound An object is already bound to this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    private void callBindOrRebind(NameComponent[] pth, Name name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        java.lang.Object obj, boolean rebind) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                // Call state factories to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                obj = NamingManager.getStateToBind(obj, name, this, _env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (obj instanceof CNCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    // Use naming context object reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    obj = ((CNCtx)obj)._nc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if ( obj instanceof org.omg.CosNaming.NamingContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    NamingContext nobj =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        NamingContextHelper.narrow((org.omg.CORBA.Object)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    if (rebind)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        _nc.rebind_context(pth,nobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        _nc.bind_context(pth,nobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                } else if (obj instanceof org.omg.CORBA.Object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    if (rebind)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        _nc.rebind(pth,(org.omg.CORBA.Object)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        _nc.bind(pth,(org.omg.CORBA.Object)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                "Only instances of org.omg.CORBA.Object can be bound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            } catch (BAD_PARAM e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                // probably narrow() failed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                NamingException ne = new NotContextException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                throw ExceptionMapper.mapException(e, this, pth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
      * Converts the "Name" name into a NameComponent[] object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
      * performs the bind operation. Uses callBindOrRebind. Throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
      * invalid name exception if the name is empty. We need a name to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
      * bind the object even when we work within the current context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
      * @param name JNDI Name object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
      * @param obj Object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
      * @exception NamingException See callBindOrRebind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    public  void bind(Name name, java.lang.Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            if (name.size() == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                throw new InvalidNameException("Name is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                System.out.println("Bind: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                callBindOrRebind(path, name, obj, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                javax.naming.Context cctx = getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                cctx.bind(e.getRemainingName(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    static private javax.naming.Context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        getContinuationContext(CannotProceedException cpe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            return NamingManager.getContinuationContext(cpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            java.lang.Object resObj = e.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            if (resObj instanceof Reference) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                Reference ref = (Reference)resObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                RefAddr addr = ref.get("nns");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                if (addr.getContent() instanceof javax.naming.Context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    NamingException ne = new NameNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        "No object reference bound for specified name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    ne.setRootCause(cpe.getRootCause());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    ne.setRemainingName(cpe.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
      * Converts the "String" name into a CompositeName object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
      * performs the bind operation. Uses callBindOrRebind. Throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
      * invalid name exception if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
      * @param obj Object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
      * @exception NamingException See callBindOrRebind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public void bind(String name, java.lang.Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        bind(new CompositeName(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      * Converts the "Name" name into a NameComponent[] object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
      * performs the rebind operation. Uses callBindOrRebind. Throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      * invalid name exception if the name is empty. We must have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      * to rebind the object to even if we are working within the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
      * context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      * @param obj Object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
      * @exception NamingException See callBindOrRebind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public  void rebind(Name name, java.lang.Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            if (name.size() == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                throw new InvalidNameException("Name is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                callBindOrRebind(path, name, obj, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                javax.naming.Context cctx = getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                cctx.rebind(e.getRemainingName(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
      * Converts the "String" name into a CompositeName object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      * performs the rebind operation. Uses callBindOrRebind. Throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
      * invalid name exception if the name is an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
      * @param obj Object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
      * @exception NamingException See callBindOrRebind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public  void rebind(String name, java.lang.Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            rebind(new CompositeName(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
      * Calls the unbind api of COS Naming and uses the exception mapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
      * class  to map the exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
      * @param path NameComponent[] object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
      * @exception NotFound No objects under the name. If leaf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      * is not found, that's OK according to the JNDI spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
      * @exception CannotProceed Unable to obtain a continuation context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
      * @exception InvalidName Name not understood.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    private void callUnbind(NameComponent[] path) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                _nc.unbind(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            } catch (NotFound e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                // If leaf is the one missing, return success
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                // as per JNDI spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                if (leafNotFound(e, path[path.length-1])) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   733
                    // do nothing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    throw ExceptionMapper.mapException(e, this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                throw ExceptionMapper.mapException(e, this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    private boolean leafNotFound(NotFound e, NameComponent leaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // This test is not foolproof because some name servers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        // always just return one component in rest_of_name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        // so you might not be able to tell whether that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        // the leaf (e.g. aa/aa/aa, which one is missing?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        NameComponent rest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return e.why.value() == NotFoundReason._missing_node &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            e.rest_of_name.length == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            (rest=e.rest_of_name[0]).id.equals(leaf.id) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            (rest.kind == leaf.kind ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
             (rest.kind != null && rest.kind.equals(leaf.kind)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
      * Converts the "String" name into a CompositeName object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
      * performs the unbind operation. Uses callUnbind. If the name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
      * empty, throws an invalid name exception. Do we unbind the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
      * current context (JNDI spec says work with the current context if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
      * the name is empty) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      * @exception NamingException See callUnbind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public  void unbind(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        unbind(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
      * Converts the "Name" name into a NameComponent[] object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
      * performs the unbind operation. Uses callUnbind. Throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
      * invalid name exception if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
      * @exception NamingException See callUnbind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    public  void unbind(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            if (name.size() == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                throw new InvalidNameException("Name is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                callUnbind(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                javax.naming.Context cctx = getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                cctx.unbind(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      * Renames an object. Since COS Naming does not support a rename
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      * api, this method unbinds the object with the "oldName" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
      * creates a new binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
      * @param oldName string, existing name for the binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
      * @param newName string, name used to replace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
      * @exception NamingException See bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public  void rename(String oldName,String newName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            rename(new CompositeName(oldName), new CompositeName(newName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
      * Renames an object. Since COS Naming does not support a rename
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
      * api, this method unbinds the object with the "oldName" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
      * creates a new binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      * @param oldName JNDI Name, existing name for the binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      * @param newName JNDI Name, name used to replace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
      * @exception NamingException See bind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public  void rename(Name oldName,Name newName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            if (oldName.size() == 0 || newName.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                throw new InvalidNameException("One or both names empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            java.lang.Object obj = lookup(oldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            bind(newName,obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            unbind(oldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
      * Returns a NameClassEnumeration object which has a list of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      * class pairs. Lists the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
      * @exception NamingException All exceptions thrown by lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
      * with a non-null argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      * @return a list of name-class objects as a NameClassEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   831
    public  NamingEnumeration<NameClassPair> list(String name) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            return list(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
      * Returns a NameClassEnumeration object which has a list of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
      * class pairs. Lists the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
      * @param name JNDI Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
      * @exception NamingException All exceptions thrown by lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
      * @return a list of name-class objects as a NameClassEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   842
    @SuppressWarnings("unchecked")
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   843
    public  NamingEnumeration<NameClassPair> list(Name name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        throws NamingException {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   845
            return (NamingEnumeration)listBindings(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
      * Returns a BindingEnumeration object which has a list of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
      * object pairs. Lists the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
      * @exception NamingException all exceptions returned by lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
      * @return a list of bindings as a BindingEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   855
    public  NamingEnumeration<javax.naming.Binding> listBindings(String name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            return listBindings(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
      * Returns a BindingEnumeration object which has a list of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
      * class pairs. Lists the current context if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
      * @param name JNDI Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
      * @exception NamingException all exceptions returned by lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
      * @return a list of bindings as a BindingEnumeration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   867
    public  NamingEnumeration<javax.naming.Binding> listBindings(Name name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (name.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    java.lang.Object obj = lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    if (obj instanceof CNCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        return new CNBindingEnumeration(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                                        (CNCtx) obj, true, _env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                        throw new NotContextException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                } catch (BAD_PARAM e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    NamingException ne =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                        new NotContextException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                    ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            return new CNBindingEnumeration(this, false, _env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
      * Calls the destroy on the COS Naming Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
      * @param nc The NamingContext object to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
      * @exception NotEmpty when the context is not empty and cannot be destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    private void callDestroy(NamingContext nc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                nc.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                throw ExceptionMapper.mapException(e, this, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
      * Uses the callDestroy function to destroy the context. If name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
      * empty destroys the current context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
      * @exception OperationNotSupportedException when list is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
      * with a non-null argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public  void destroySubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        destroySubcontext(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
      * Uses the callDestroy function to destroy the context. Destroys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
      * the current context if name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
      * @param name JNDI Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
      * @exception OperationNotSupportedException when list is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      * with a non-null argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public  void destroySubcontext(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            NamingContext the_nc = _nc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            if ( name.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    javax.naming.Context ctx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                        (javax.naming.Context) callResolve(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    CNCtx cnc = (CNCtx)ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    the_nc = cnc._nc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                    cnc.close(); //remove the reference to the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    throw new NotContextException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    javax.naming.Context cctx = getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    cctx.destroySubcontext(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                } catch (NameNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                    // If leaf is the one missing, return success
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                    // as per JNDI spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    if (e.getRootCause() instanceof NotFound &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                        leafNotFound((NotFound)e.getRootCause(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                            path[path.length-1])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                        return; // leaf missing OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            callDestroy(the_nc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            callUnbind(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
      * Calls the bind_new_context COS naming api to create a new subcontext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
      * @param path NameComponent[] object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
      * @exception NotFound No objects under the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
      * @exception CannotProceed Unable to obtain a continuation context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
      * @exception InvalidName Name not understood.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
      * @exception AlreadyBound An object is already bound to this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
      * @return the new context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    private javax.naming.Context callBindNewContext(NameComponent[] path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            if (_nc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                throw new ConfigurationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    "Context does not have a corresponding NamingContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                NamingContext nctx = _nc.bind_new_context(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                return new CNCtx(_orb, orbTracker, nctx, _env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                        makeFullName(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                throw ExceptionMapper.mapException(e, this, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
      * Uses the callBindNewContext convenience function to create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
      * context. Throws an invalid name exception if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
      * @exception NamingException See callBindNewContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
      * @return the new context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    public  javax.naming.Context createSubcontext(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            return createSubcontext(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
      * Uses the callBindNewContext convenience function to create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
      * context. Throws an invalid name exception if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
      * @exception NamingException See callBindNewContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
      * @return the new context object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    public  javax.naming.Context createSubcontext(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            if (name.size() == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                throw new InvalidNameException("Name is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            NameComponent[] path = CNNameParser.nameToCosName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                return callBindNewContext(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            } catch (CannotProceedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                javax.naming.Context cctx = getContinuationContext(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                return cctx.createSubcontext(e.getRemainingName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
      * Is mapped to resolve in the COS Naming api.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
      * @exception NamingException See lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
      * @return the resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public  java.lang.Object lookupLink(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            return lookupLink(new CompositeName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
      * Is mapped to resolve in the COS Naming api.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
      * @param name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
      * @exception NamingException See lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
      * @return the resolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    public  java.lang.Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
      * Allow access to the name parser object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
      * @param String JNDI name, is ignored since there is only one Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
      * Parser object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
      * @exception NamingException --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
      * @return NameParser object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    public  NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        return parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
      * Allow access to the name parser object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
      * @param Name JNDI name, is ignored since there is only one Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
      * Parser object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
      * @exception NamingException --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
      * @return NameParser object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public  NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        return parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
      * Returns the current environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
      * @return Environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1067
    @SuppressWarnings("unchecked")
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1068
    public  Hashtable<String, java.lang.Object> getEnvironment() throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        if (_env == null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1070
            return new Hashtable<>(5, 0.75f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        } else {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1072
            return (Hashtable<String, java.lang.Object>)_env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    public String composeName(String name, String prefix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        return composeName(new CompositeName(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            new CompositeName(prefix)).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    public Name composeName(Name name, Name prefix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        Name result = (Name)prefix.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        return result.addAll(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
      * Adds to the environment for the current context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
      * Record change but do not reinitialize ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
      * @param propName The property name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
      * @param propVal  The ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
      * @return the previous value of this property if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1094
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    public java.lang.Object addToEnvironment(String propName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        java.lang.Object propValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            if (_env == null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1099
                _env = new Hashtable<>(7, 0.75f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                // copy-on-write
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1102
                _env = (Hashtable<String, java.lang.Object>)_env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            return _env.put(propName, propValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    // Record change but do not reinitialize ORB
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1109
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    public java.lang.Object removeFromEnvironment(String propName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            if (_env != null  && _env.get(propName) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                // copy-on-write
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1114
                _env = (Hashtable<String, java.lang.Object>)_env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                return _env.remove(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    synchronized public void incEnumCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        enumCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            System.out.println("incEnumCount, new count:" + enumCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    synchronized public void decEnumCount()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        enumCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            System.out.println("decEnumCount, new count:" + enumCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                        "    isCloseCalled:" + isCloseCalled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        if ((enumCount == 0) && isCloseCalled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    synchronized public void close() throws NamingException {
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
  1140
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        if (enumCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            isCloseCalled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
13153
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
  1145
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
  1146
        // Never destroy an orb in CNCtx.
338ae0f48371 6893617: JDK 6 CNCtx always uses the default ORB
coffeys
parents: 10324
diff changeset
  1147
        // The orb we have is either the shared/default orb, or one passed in to a constructor
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 13153
diff changeset
  1148
        // from elsewhere, so that orb is somebody else's responsibility.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            // ignore failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
}