src/java.naming/share/classes/javax/naming/spi/ObjectFactory.java
author herrick
Tue, 24 Sep 2019 13:41:16 -0400
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 36511
diff changeset
     2
 * Copyright (c) 1999, 2017, 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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * This interface represents a factory for creating an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  * The JNDI framework allows for object implementations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * be loaded in dynamically via <em>object factories</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * For example, when looking up a printer bound in the name space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * if the print service binds printer names to References, the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * Reference could be used to create a printer object, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * the caller of lookup can directly operate on the printer object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * after the lookup.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    42
  * <p>An {@code ObjectFactory} is responsible
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * for creating objects of a specific type.  In the above example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * you may have a PrinterObjectFactory for creating Printer objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    46
  * An object factory must implement the {@code ObjectFactory} interface.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * In addition, the factory class must be public and must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * public constructor that accepts no parameters.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32029
diff changeset
    49
  * Note that in cases where the factory is in a named module then it must be
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32029
diff changeset
    50
  * in a package which is exported by that module to the {@code java.naming}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32029
diff changeset
    51
  * module.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    53
  * The {@code getObjectInstance()} method of an object factory may
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * be invoked multiple times, possibly using different parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  * The implementation is thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * The mention of URL in the documentation for this class refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * a URL string as defined by RFC 1738 and its related RFCs. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  * any string that conforms to the syntax described therein, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * may not always have corresponding support in the java.net.URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * class or Web browsers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * @see NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * @see NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  * @see ObjectFactoryBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  * @see StateFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public interface ObjectFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Creates an object using the location or reference information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Special requirements of this object are supplied
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    79
 * using {@code environment}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * An example of such an environment property is user identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    83
 * {@code NamingManager.getObjectInstance()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * successively loads in object factories and invokes this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * on them until one produces a non-null answer.  When an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * is thrown by an object factory, the exception is passed on to the caller
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    87
 * of {@code NamingManager.getObjectInstance()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * (and no search is made for other factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * that may produce a non-null answer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * An object factory should only throw an exception if it is sure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * it is the only intended factory and that no other object factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * should be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * If this factory cannot create an object using the arguments supplied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * it should return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * A <em>URL context factory</em> is a special ObjectFactory that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * creates contexts for resolving URLs or objects whose locations
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    98
 * are specified by URLs.  The {@code getObjectInstance()} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * of a URL context factory will obey the following rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <ol>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   101
 * <li>If {@code obj} is null, create a context for resolving URLs of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * scheme associated with this factory. The resulting context is not tied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * to a specific URL:  it is able to handle arbitrary URLs with this factory's
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   104
 * scheme id.  For example, invoking {@code getObjectInstance()} with
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   105
 * {@code obj} set to null on an LDAP URL context factory would return a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * context that can resolve LDAP URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * such as "ldap://ldap.wiz.com/o=wiz,c=us" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * "ldap://ldap.umich.edu/o=umich,c=us".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <li>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   110
 * If {@code obj} is a URL string, create an object (typically a context)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * identified by the URL.  For example, suppose this is an LDAP URL context
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   112
 * factory.  If {@code obj} is "ldap://ldap.wiz.com/o=wiz,c=us",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * getObjectInstance() would return the context named by the distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * name "o=wiz, c=us" at the LDAP server ldap.wiz.com.  This context can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * then be used to resolve LDAP names (such as "cn=George")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * relative to that context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <li>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   118
 * If {@code obj} is an array of URL strings, the assumption is that the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * URLs are equivalent in terms of the context to which they refer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * Verification of whether the URLs are, or need to be, equivalent is up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * to the context factory. The order of the URLs in the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * not significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * The object returned by getObjectInstance() is like that of the single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * URL case.  It is the object named by the URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <li>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   126
 * If {@code obj} is of any other type, the behavior of
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   127
 * {@code getObjectInstance()} is determined by the context factory
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   132
 * The {@code name} and {@code environment} parameters
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * are owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * The implementation will not modify these objects or keep references
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * to them, although it may keep references to clones or copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <b>Name and Context Parameters.</b> &nbsp;&nbsp;&nbsp;
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 36511
diff changeset
   139
 * <a id=NAMECTX></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   141
 * The {@code name} and {@code nameCtx} parameters may
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * optionally be used to specify the name of the object being created.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   143
 * {@code name} is the name of the object, relative to context
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   144
 * {@code nameCtx}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * If there are several possible contexts from which the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * could be named -- as will often be the case -- it is up to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * the caller to select one.  A good rule of thumb is to select the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * "deepest" context available.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   149
 * If {@code nameCtx} is null, {@code name} is relative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * to the default initial context.  If no name is being specified, the
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   151
 * {@code name} parameter should be null.
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   152
 * If a factory uses {@code nameCtx} it should synchronize its use
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * against concurrent access, since context implementations are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * @param obj The possibly null object containing location or reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *              information that can be used in creating an object.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   158
 * @param name The name of this object relative to {@code nameCtx},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *              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
   160
 * @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
   161
 *              parameter is specified, or null if {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *              relative to the default initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @param environment The possibly null environment that is used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *              creating the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * @return The object created; null if an object cannot be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * @exception Exception if this object factory encountered an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * while attempting to create an object, and no other object factories are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * to be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * @see NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * @see NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                    Hashtable<?,?> environment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}