jdk/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java
author prappo
Fri, 01 Aug 2014 22:32:51 +0100
changeset 25808 e113d0a0fde0
parent 10369 e9d2e59e53f0
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
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.jndi.toolkit.dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.directory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A sample service provider that implements a hierarchical directory in memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Every operation begins by doing a lookup on the name passed to it and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * calls a corresponding "do<OperationName>" on the result of the lookup. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * "do<OperationName>" does the work without any further resolution (it assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * that it is the target context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class HierMemDirCtx implements DirContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static private final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final NameParser defaultParser = new HierarchicalNameParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    45
    protected Hashtable<String, Object> myEnv;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    46
    protected Hashtable<Name, Object> bindings;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    protected Attributes attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected boolean ignoreCase = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected NamingException readOnlyEx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected NameParser myParser = defaultParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private boolean alwaysUseFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public void close() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        myEnv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        bindings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        attrs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public String getNameInNamespace() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        throw new OperationNotSupportedException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            "Cannot determine full name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public HierMemDirCtx() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this(null, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public HierMemDirCtx(boolean ignoreCase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this(null, ignoreCase, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    73
    public HierMemDirCtx(Hashtable<String, Object> environment, boolean ignoreCase) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this(environment, ignoreCase, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    77
    protected HierMemDirCtx(Hashtable<String, Object> environment,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    78
        boolean ignoreCase, boolean useFac) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        myEnv = environment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.ignoreCase = ignoreCase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this.alwaysUseFactory = useFac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        attrs = new BasicAttributes(ignoreCase);
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    87
        bindings = new Hashtable<>(11, 0.75f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return lookup(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public Object lookup(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return doLookup(name, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public Object doLookup(Name name, boolean useFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Object target = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        name = canonizeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        switch(name.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            // name is empty, caller wants this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            target = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // name is atomic, caller wants one of this object's bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            target = bindings.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // name is compound, delegate to child context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            HierMemDirCtx ctx = (HierMemDirCtx)bindings.get(name.getPrefix(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if(ctx == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                target = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                target = ctx.doLookup(name.getSuffix(1), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if(target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            throw new NameNotFoundException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (useFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return DirectoryManager.getObjectInstance(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    name, this, myEnv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    (target instanceof HierMemDirCtx) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    ((HierMemDirCtx)target).attrs : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                NamingException e2 = new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    "Problem calling getObjectInstance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                e2.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                throw e2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void bind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        bind(myParser.parse(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void bind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        doBind(name, obj, null, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void bind(String name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        bind(myParser.parse(name), obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void bind(Name name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        doBind(name, obj, attrs, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected void doBind(Name name, Object obj, Attributes attrs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        boolean useFactory) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (name.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new InvalidNameException("Cannot bind empty name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (useFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            DirStateFactory.Result res = DirectoryManager.getStateToBind(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                obj, name, this, myEnv, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            obj = res.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            attrs = res.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        HierMemDirCtx ctx= (HierMemDirCtx) doLookup(getInternalName(name), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        ctx.doBindAux(getLeafName(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (attrs != null && attrs.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            modifyAttributes(name, ADD_ATTRIBUTE, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected void doBindAux(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (bindings.get(name) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new NameAlreadyBoundException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if(obj instanceof HierMemDirCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            bindings.put(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new SchemaViolationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                "This context only supports binding objects of it's own kind");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void rebind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        rebind(myParser.parse(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void rebind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        doRebind(name, obj, null, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public void rebind(String name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        rebind(myParser.parse(name), obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void rebind(Name name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        doRebind(name, obj, attrs, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected void doRebind(Name name, Object obj, Attributes attrs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        boolean useFactory) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (name.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new InvalidNameException("Cannot rebind empty name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (useFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            DirStateFactory.Result res = DirectoryManager.getStateToBind(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                obj, name, this, myEnv, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            obj = res.getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            attrs = res.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        HierMemDirCtx ctx= (HierMemDirCtx) doLookup(getInternalName(name), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        ctx.doRebindAux(getLeafName(name), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // attrs == null -> use attrs from obj
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // attrs != null -> use attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // %%% Strictly speaking, when attrs is non-null, we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        // take the explicit step of removing obj's attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // We don't do that currently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (attrs != null && attrs.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            modifyAttributes(name, ADD_ATTRIBUTE, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    protected void doRebindAux(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if(obj instanceof HierMemDirCtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            bindings.put(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new SchemaViolationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                "This context only supports binding objects of it's own kind");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public void unbind(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        unbind(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public void unbind(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (name.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new InvalidNameException("Cannot unbind empty name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            HierMemDirCtx ctx=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                (HierMemDirCtx) doLookup(getInternalName(name), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            ctx.doUnbind(getLeafName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    protected void doUnbind(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        bindings.remove(name);  // attrs will also be removed along with ctx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void rename(String oldname, String newname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         rename(myParser.parse(oldname), myParser.parse(newname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void rename(Name oldname, Name newname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if(newname.isEmpty() || oldname.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            throw new InvalidNameException("Cannot rename empty name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (!getInternalName(newname).equals(getInternalName(oldname))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throw new InvalidNameException("Cannot rename across contexts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        HierMemDirCtx ctx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            (HierMemDirCtx) doLookup(getInternalName(newname), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        ctx.doRename(getLeafName(oldname), getLeafName(newname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected void doRename(Name oldname, Name newname) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        oldname = canonizeName(oldname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        newname = canonizeName(newname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // Check if new name exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (bindings.get(newname) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            throw new NameAlreadyBoundException(newname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // Check if old name is bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        Object oldBinding = bindings.remove(oldname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (oldBinding == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            throw new NameNotFoundException(oldname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        bindings.put(newname, oldBinding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   329
    public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return list(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   333
    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return ctx.doList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   338
    protected NamingEnumeration<NameClassPair> doList () throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return new FlatNames(bindings.keys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   343
    public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return listBindings(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   347
    public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        HierMemDirCtx ctx = (HierMemDirCtx)doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return ctx.doListBindings(alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   352
    protected NamingEnumeration<Binding> doListBindings(boolean useFactory)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return new FlatBindings(bindings, myEnv, useFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public void destroySubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        destroySubcontext(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public void destroySubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        HierMemDirCtx ctx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            (HierMemDirCtx) doLookup(getInternalName(name), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        ctx.doDestroySubcontext(getLeafName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    protected void doDestroySubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        name = canonizeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        bindings.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public Context createSubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return createSubcontext(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public Context createSubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return createSubcontext(name, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public DirContext createSubcontext(String name, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return createSubcontext(myParser.parse(name), attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public DirContext createSubcontext(Name name, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        HierMemDirCtx ctx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            (HierMemDirCtx) doLookup(getInternalName(name), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return ctx.doCreateSubcontext(getLeafName(name), attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    protected DirContext doCreateSubcontext(Name name, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        name = canonizeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (bindings.get(name) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            throw new NameAlreadyBoundException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        HierMemDirCtx newCtx = createNewCtx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        bindings.put(name, newCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if(attrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            newCtx.modifyAttributes("", ADD_ATTRIBUTE, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return newCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public Object lookupLink(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // This context does not treat links specially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return lookupLink(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // Flat namespace; no federation; just call string version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return myParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return myParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public String composeName(String name, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        Name result = composeName(new CompositeName(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                  new CompositeName(prefix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public Name composeName(Name name, Name prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        name = canonizeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        prefix = canonizeName(prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        Name result = (Name)(prefix.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        result.addAll(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   450
    @SuppressWarnings("unchecked") // clone()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public Object addToEnvironment(String propName, Object propVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            throws NamingException {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   453
        myEnv = (myEnv == null)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   454
                ? new Hashtable<String, Object>(11, 0.75f)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   455
                : (Hashtable<String, Object>)myEnv.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return myEnv.put(propName, propVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   460
    @SuppressWarnings("unchecked") // clone()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public Object removeFromEnvironment(String propName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (myEnv == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   466
        myEnv = (Hashtable<String, Object>)myEnv.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return myEnv.remove(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   470
    @SuppressWarnings("unchecked") // clone()
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   471
    public Hashtable<String, Object> getEnvironment() throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (myEnv == null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   473
            return new Hashtable<>(5, 0.75f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } else {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   475
            return (Hashtable<String, Object>)myEnv.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public Attributes getAttributes(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
       throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
       return getAttributes(myParser.parse(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public Attributes getAttributes(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return ctx.doGetAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    protected Attributes doGetAttributes() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return (Attributes)attrs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public Attributes getAttributes(String name, String[] attrIds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return getAttributes(myParser.parse(name), attrIds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public Attributes getAttributes(Name name, String[] attrIds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return ctx.doGetAttributes(attrIds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    protected Attributes doGetAttributes(String[] attrIds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (attrIds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return doGetAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        Attributes attrs = new BasicAttributes(ignoreCase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        Attribute attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            for(int i=0; i<attrIds.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                attr = this.attrs.get(attrIds[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    attrs.put(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public void modifyAttributes(String name, int mod_op, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        throws NamingException   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        modifyAttributes(myParser.parse(name), mod_op, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public void modifyAttributes(Name name, int mod_op, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (attrs == null || attrs.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                "Cannot modify without an attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        // turn it into a modification Enumeration and pass it on
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   536
        NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        ModificationItem[] mods = new ModificationItem[attrs.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        for (int i = 0; i < mods.length && attrEnum.hasMoreElements(); i++) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   539
            mods[i] = new ModificationItem(mod_op, attrEnum.next());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        modifyAttributes(name, mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void modifyAttributes(String name, ModificationItem[] mods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        throws NamingException   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        modifyAttributes(myParser.parse(name), mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public void modifyAttributes(Name name, ModificationItem[] mods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        ctx.doModifyAttributes(mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    protected void doModifyAttributes(ModificationItem[] mods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (readOnlyEx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            throw (NamingException) readOnlyEx.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        applyMods(mods, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    protected static Attributes applyMods(ModificationItem[] mods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        Attributes orig) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        ModificationItem mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        Attribute existingAttr, modAttr;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   571
        NamingEnumeration<?> modVals;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        for (int i = 0; i < mods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            mod = mods[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            modAttr = mod.getAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            switch(mod.getModificationOp()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            case ADD_ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    System.out.println("HierMemDSCtx: adding " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                       mod.getAttribute().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                existingAttr = orig.get(modAttr.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if (existingAttr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    orig.put((Attribute)modAttr.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    // Add new attribute values to existing attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    modVals = modAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    while (modVals.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        existingAttr.add(modVals.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            case REPLACE_ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                if (modAttr.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    orig.remove(modAttr.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    orig.put((Attribute)modAttr.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            case REMOVE_ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                existingAttr = orig.get(modAttr.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                if (existingAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    if (modAttr.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        orig.remove(modAttr.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        // Remove attribute values from existing attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        modVals = modAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        while (modVals.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            existingAttr.remove(modVals.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        if (existingAttr.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                            orig.remove(modAttr.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                throw new AttributeModificationException("Unknown mod_op");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return orig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   626
    public NamingEnumeration<SearchResult> search(String name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   627
                                                  Attributes matchingAttributes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return search(name, matchingAttributes, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   632
    public NamingEnumeration<SearchResult> search(Name name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   633
                                                  Attributes matchingAttributes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            return search(name, matchingAttributes, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   638
     public NamingEnumeration<SearchResult> search(String name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   639
                                                   Attributes matchingAttributes,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   640
                                                   String[] attributesToReturn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        return search(myParser.parse(name), matchingAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            attributesToReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   646
     public NamingEnumeration<SearchResult> search(Name name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   647
                                                   Attributes matchingAttributes,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   648
                                                   String[] attributesToReturn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        HierMemDirCtx target = (HierMemDirCtx) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        SearchControls cons = new SearchControls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        cons.setReturningAttributes(attributesToReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return new LazySearchEnumerationImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            target.doListBindings(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            new ContainmentFilter(matchingAttributes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            cons, this, myEnv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            false); // alwaysUseFactory ignored because objReturnFlag == false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   663
    public NamingEnumeration<SearchResult> search(Name name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   664
                                                  String filter,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   665
                                                  SearchControls cons)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        DirContext target = (DirContext) doLookup(name, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        SearchFilter stringfilter = new SearchFilter(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return new LazySearchEnumerationImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            new HierContextEnumerator(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                (cons != null) ? cons.getSearchScope() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                SearchControls.ONELEVEL_SCOPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            stringfilter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            cons, this, myEnv, alwaysUseFactory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   678
     public NamingEnumeration<SearchResult> search(Name name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   679
                                                   String filterExpr,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   680
                                                   Object[] filterArgs,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   681
                                                   SearchControls cons)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        String strfilter = SearchFilter.format(filterExpr, filterArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return search(name, strfilter, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   688
    public NamingEnumeration<SearchResult> search(String name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   689
                                                  String filter,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   690
                                                  SearchControls cons)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        return search(myParser.parse(name), filter, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   695
    public NamingEnumeration<SearchResult> search(String name,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   696
                                                  String filterExpr,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   697
                                                  Object[] filterArgs,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   698
                                                  SearchControls cons)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        return search(myParser.parse(name), filterExpr, filterArgs, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    // This function is called whenever a new object needs to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    // this is used so that if anyone subclasses us, they can override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    // and return object of their own kind.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    protected HierMemDirCtx createNewCtx() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return new HierMemDirCtx(myEnv, ignoreCase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    // If the supplied name is a composite name, return the name that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    // is its first component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    protected Name canonizeName(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        Name canonicalName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if(!(name instanceof HierarchicalName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            // If name is not of the correct type, make copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            canonicalName = new HierarchicalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            int n = name.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            for(int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                canonicalName.add(i, name.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return canonicalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     protected Name getInternalName(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         return (name.getPrefix(name.size() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     protected Name getLeafName(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         return (name.getSuffix(name.size() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     public DirContext getSchema(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        throw new OperationNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     public DirContext getSchema(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        throw new OperationNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     public DirContext getSchemaClassDefinition(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        throw new OperationNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public DirContext getSchemaClassDefinition(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        throw new OperationNotSupportedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    // Set context in readonly mode; throw e when update operation attempted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public void setReadOnly(NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        readOnlyEx = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    // Set context to support case-insensitive names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public void setIgnoreCase(boolean ignoreCase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        this.ignoreCase = ignoreCase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public void setNameParser(NameParser parser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        myParser = parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   768
    /*
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   769
     * Common base class for FlatNames and FlatBindings.
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   770
     */
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   771
    private abstract class BaseFlatNames<T> implements NamingEnumeration<T> {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   772
        Enumeration<Name> names;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   774
        BaseFlatNames (Enumeration<Name> names) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            this.names = names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   778
        public final boolean hasMoreElements() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                return hasMore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   786
        public final boolean hasMore() throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            return names.hasMoreElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   790
        public final T nextElement() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                return next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                throw new NoSuchElementException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   798
        public abstract T next() throws NamingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   800
        public final void close() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   805
    // Class for enumerating name/class pairs
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   806
    private final class FlatNames extends BaseFlatNames<NameClassPair> {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   807
        FlatNames (Enumeration<Name> names) {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   808
            super(names);
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   809
        }
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   810
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   811
        @Override
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   812
        public NameClassPair next() throws NamingException {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   813
            Name name = names.nextElement();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   814
            String className = bindings.get(name).getClass().getName();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   815
            return new NameClassPair(name.toString(), className);
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   816
        }
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   817
    }
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   818
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   819
    // Class for enumerating bindings
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   820
    private final class FlatBindings extends BaseFlatNames<Binding> {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   821
        private Hashtable<Name, Object> bds;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   822
        private Hashtable<String, Object> env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        private boolean useFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   825
        FlatBindings(Hashtable<Name, Object> bindings,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   826
                     Hashtable<String, Object> env,
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   827
                     boolean useFactory) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            super(bindings.keys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            this.bds = bindings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            this.useFactory = useFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   834
        @Override
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   835
        public Binding next() throws NamingException {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   836
            Name name = names.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            HierMemDirCtx obj = (HierMemDirCtx)bds.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            Object answer = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            if (useFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                Attributes attrs = obj.getAttributes(""); // only method available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                    answer = DirectoryManager.getObjectInstance(obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                        name, HierMemDirCtx.this, env, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    NamingException e2 = new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                        "Problem calling getObjectInstance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    e2.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    throw e2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            return new Binding(name.toString(), answer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public class HierContextEnumerator extends ContextEnumerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        public HierContextEnumerator(Context context, int scope)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                super(context, scope);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        protected HierContextEnumerator(Context context, int scope,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            String contextName, boolean returnSelf) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            super(context, scope, contextName, returnSelf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   871
        protected NamingEnumeration<Binding> getImmediateChildren(Context ctx)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                return ((HierMemDirCtx)ctx).doListBindings(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        protected ContextEnumerator newEnumerator(Context ctx, int scope,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            String contextName, boolean returnSelf) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                return new HierContextEnumerator(ctx, scope, contextName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    returnSelf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 10369
diff changeset
   884
    // CompoundNames's HashCode() method isn't good enough for many strings.
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 10369
diff changeset
   885
    // The only purpose of this subclass is to have a more discerning
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    // hash function. We'll make up for the performance hit by caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    // the hash value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
final class HierarchicalName extends CompoundName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    private int hashValue = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    // Creates an empty name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    HierarchicalName() {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   894
        super(new Enumeration<String>() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   895
                  public boolean hasMoreElements() {return false;}
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   896
                  public String nextElement() {throw new NoSuchElementException();}
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   897
              },
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   898
              HierarchicalNameParser.mySyntax);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   901
    HierarchicalName(Enumeration<String> comps, Properties syntax) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        super(comps, syntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    HierarchicalName(String n, Properties syntax) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        super(n, syntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    // just like String.hashCode, only it pays no attention to length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (hashValue == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
10369
e9d2e59e53f0 7059542: JNDI name operations should be locale independent
xuelei
parents: 10324
diff changeset
   913
            String name = toString().toUpperCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            int len = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            int off = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            char val[] = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            name.getChars(0, len, val, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            for (int i = len; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                hashValue = (hashValue * 37) + val[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return hashValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public Name getPrefix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   929
        Enumeration<String> comps = super.getPrefix(posn).getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return (new HierarchicalName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public Name getSuffix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   934
        Enumeration<String> comps = super.getSuffix(posn).getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        return (new HierarchicalName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        return (new HierarchicalName(getAll(), mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    private static final long serialVersionUID = -6717336834584573168L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
// This is the default name parser (used if setNameParser is not called)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
final class HierarchicalNameParser implements NameParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    static final Properties mySyntax = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        mySyntax.put("jndi.syntax.direction", "left_to_right");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        mySyntax.put("jndi.syntax.separator", "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        mySyntax.put("jndi.syntax.ignorecase", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        mySyntax.put("jndi.syntax.escape", "\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        mySyntax.put("jndi.syntax.beginquote", "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        //mySyntax.put("jndi.syntax.separator.ava", "+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        //mySyntax.put("jndi.syntax.separator.typeval", "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        mySyntax.put("jndi.syntax.trimblanks", "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    public Name parse(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        return new HierarchicalName(name, mySyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
}