jdk/src/java.naming/share/classes/javax/naming/spi/DirectoryManager.java
author sspitsyn
Wed, 07 Sep 2016 03:35:45 +0000
changeset 40963 c7c990c4ec68
parent 32029 a5538163e144
permissions -rw-r--r--
Merge
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.Context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.naming.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.naming.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.naming.Referenceable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.naming.NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.naming.CannotProceedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.naming.directory.DirContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.naming.directory.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.naming.internal.ResourceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.naming.internal.FactoryEnumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    44
  * This class contains methods for supporting {@code DirContext}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    47
  * This class is an extension of {@code NamingManager}.  It contains methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * for use by service providers for accessing object factories and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * state factories, and for getting continuation contexts for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * supporting federation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    52
  * {@code DirectoryManager} is safe for concurrent access by multiple threads.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * Except as otherwise noted,
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    55
  * a {@code Name}, {@code Attributes}, or environment parameter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * passed to any method is owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * The implementation will not modify the object or keep a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * to it, although it may keep a reference to a clone or copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  * @see DirObjectFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * @see DirStateFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class DirectoryManager extends NamingManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Disallow anyone from creating one of these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    DirectoryManager() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    76
      * Creates a context in which to continue a {@code DirContext} operation.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    77
      * Operates just like {@code NamingManager.getContinuationContext()},
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    78
      * only the continuation context returned is a {@code DirContext}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
      * @param cpe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      *         The non-null exception that triggered this continuation.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    82
      * @return A non-null {@code DirContext} object for continuing the operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      * @exception NamingException If a naming exception occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      * @see NamingManager#getContinuationContext(CannotProceedException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    87
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static DirContext getContinuationDirContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            CannotProceedException cpe) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    91
        Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (env == null) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    93
            env = new Hashtable<>(7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            // Make a (shallow) copy of the environment.
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    96
            env = (Hashtable<Object,Object>) env.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        env.put(CPE, cpe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return (new ContinuationDirContext(cpe, env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      * Creates an instance of an object for the specified object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      * attributes, and environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      * <p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   107
      * This method is the same as {@code NamingManager.getObjectInstance}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      * except for the following differences:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      *<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      *<li>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   111
      * It accepts an {@code Attributes} parameter that contains attributes
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   112
      * associated with the object. The {@code DirObjectFactory} might use these
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      * attributes to save having to look them up from the directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * The object factories tried must implement either
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   116
      * {@code ObjectFactory} or {@code DirObjectFactory}.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   117
      * If it implements {@code DirObjectFactory},
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   118
      * {@code DirObjectFactory.getObjectInstance()} is used, otherwise,
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   119
      * {@code ObjectFactory.getObjectInstance()} is used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      *</ul>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   121
      * Service providers that implement the {@code DirContext} interface
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   122
      * should use this method, not {@code NamingManager.getObjectInstance()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      * @param refInfo The possibly null object for which to create an object.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   125
      * @param name The name of this object relative to {@code nameCtx}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      *         Specifying a name is optional; if it is
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   127
      *         omitted, {@code name} should be null.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   128
      * @param nameCtx The context relative to which the {@code name}
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   129
      *         parameter is specified.  If null, {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      *         relative to the default initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      * @param environment The possibly null environment to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      *         be used in the creation of the object factory and the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * @param attrs The possibly null attributes associated with refInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      *         This might not be the complete set of attributes for refInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      *         you might be able to read more attributes from the directory.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   136
      * @return An object created using {@code refInfo} and {@code attrs}; or
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   137
      *         {@code refInfo} if an object cannot be created by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      *         a factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      * @exception NamingException If a naming exception was encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      *         while attempting to get a URL context, or if one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      *         factories accessed throws a NamingException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      * @exception Exception If one of the factories accessed throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      *         exception, or if an error was encountered while loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      *         and instantiating the factory and object classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      *         A factory should only throw an exception if it does not want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      *         other factories to be used in an attempt to create an object.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   147
      *         See {@code DirObjectFactory.getObjectInstance()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      * @see NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      * @see DirObjectFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      * @see DirObjectFactory#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        getObjectInstance(Object refInfo, Name name, Context nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                          Hashtable<?,?> environment, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            ObjectFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            ObjectFactoryBuilder builder = getObjectFactoryBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (builder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // builder must return non-null factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                factory = builder.createObjectFactory(refInfo, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                if (factory instanceof DirObjectFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    return ((DirObjectFactory)factory).getObjectInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        refInfo, name, nameCtx, environment, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    return factory.getObjectInstance(refInfo, name, nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // use reference if possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Reference ref = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (refInfo instanceof Reference) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                ref = (Reference) refInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            } else if (refInfo instanceof Referenceable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                ref = ((Referenceable)(refInfo)).getReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            Object answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (ref != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                String f = ref.getFactoryClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    // if reference identifies a factory, use exclusively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    factory = getObjectFactoryFromReference(ref, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    if (factory instanceof DirObjectFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        return ((DirObjectFactory)factory).getObjectInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                            ref, name, nameCtx, environment, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    } else if (factory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        return factory.getObjectInstance(ref, name, nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                                         environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    // No factory found, so return original refInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    // Will reach this point if factory class is not in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    // class path and reference does not contain a URL for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    return refInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    // if reference has no factory, check for addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    // containing URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    // ignore name & attrs params; not used in URL factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    answer = processURLAddrs(ref, name, nameCtx, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    if (answer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            // try using any specified factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            answer = createObjectFromFactories(refInfo, name, nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                               environment, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return (answer != null) ? answer : refInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private static Object createObjectFromFactories(Object obj, Name name,
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   220
            Context nameCtx, Hashtable<?,?> environment, Attributes attrs)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        FactoryEnumeration factories = ResourceManager.getFactories(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            Context.OBJECT_FACTORIES, environment, nameCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (factories == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        ObjectFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        Object answer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // Try each factory until one succeeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        while (answer == null && factories.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            factory = (ObjectFactory)factories.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (factory instanceof DirObjectFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                answer = ((DirObjectFactory)factory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    getObjectInstance(obj, name, nameCtx, environment, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                answer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    factory.getObjectInstance(obj, name, nameCtx, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      * Retrieves the state of an object for binding when given the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      * object and its attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      * <p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   249
      * This method is like {@code NamingManager.getStateToBind} except
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * for the following differences:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      *<ul>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   252
      *<li>It accepts an {@code Attributes} parameter containing attributes
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   253
      *    that were passed to the {@code DirContext.bind()} method.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   254
      *<li>It returns a non-null {@code DirStateFactory.Result} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      *    containing the object to be bound, and the attributes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      *    accompany the binding. Either the object or the attributes may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      * The state factories tried must each implement either
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   259
      * {@code StateFactory} or {@code DirStateFactory}.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   260
      * If it implements {@code DirStateFactory}, then
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   261
      * {@code DirStateFactory.getStateToBind()} is called; otherwise,
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   262
      * {@code StateFactory.getStateToBind()} is called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      *</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      *
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   265
      * Service providers that implement the {@code DirContext} interface
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   266
      * should use this method, not {@code NamingManager.getStateToBind()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      * See NamingManager.getStateToBind() for a description of how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * the list of state factories to be tried is determined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * The object returned by this method is owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      * The implementation will not subsequently modify it.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   273
      * It will contain either a new {@code Attributes} object that is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      * likewise owned by the caller, or a reference to the original
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   275
      * {@code attrs} parameter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      * @param obj The non-null object for which to get state to bind.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   278
      * @param name The name of this object relative to {@code nameCtx},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      *         or null if no name is specified.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   280
      * @param nameCtx The context relative to which the {@code name}
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   281
      *         parameter is specified, or null if {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      *         relative to the default initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      * @param environment The possibly null environment to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      *         be used in the creation of the state factory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      *         the object's state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      * @param attrs The possibly null Attributes that is to be bound with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      *         object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * @return A non-null DirStateFactory.Result containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      *  the object and attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      *  If no state factory returns a non-null answer, the result will contain
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   291
      *  the object ({@code obj}) itself with the original attributes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      * @exception NamingException If a naming exception was encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      *         while using the factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      *         A factory should only throw an exception if it does not want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      *         other factories to be used in an attempt to create an object.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   296
      *         See {@code DirStateFactory.getStateToBind()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      * @see DirStateFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      * @see DirStateFactory#getStateToBind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      * @see NamingManager#getStateToBind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public static DirStateFactory.Result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        getStateToBind(Object obj, Name name, Context nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                       Hashtable<?,?> environment, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // Get list of state factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        FactoryEnumeration factories = ResourceManager.getFactories(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            Context.STATE_FACTORIES, environment, nameCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (factories == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            // no factories to try; just return originals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return new DirStateFactory.Result(obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // Try each factory until one succeeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        StateFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        Object objanswer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        DirStateFactory.Result answer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        while (answer == null && factories.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            factory = (StateFactory)factories.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (factory instanceof DirStateFactory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                answer = ((DirStateFactory)factory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    getStateToBind(obj, name, nameCtx, environment, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                objanswer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    factory.getStateToBind(obj, name, nameCtx, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                if (objanswer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    answer = new DirStateFactory.Result(objanswer, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return (answer != null) ? answer :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            new DirStateFactory.Result(obj, attrs); // nothing new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}