jdk/src/share/classes/javax/naming/spi/ObjectFactory.java
author yan
Thu, 03 Apr 2014 16:10:40 +0400
changeset 23712 d46a902c1aed
parent 5506 202f599c92aa
permissions -rw-r--r--
8039041: Tidy warnings cleanup for javax.naming Reviewed-by: alanb, lancea Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, 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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * <p>An <tt>ObjectFactory</tt> is responsible
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * An object factory must implement the <tt>ObjectFactory</tt> interface.
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * The <tt>getObjectInstance()</tt> method of an object factory may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * be invoked multiple times, possibly using different parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  * The implementation is thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * The mention of URL in the documentation for this class refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  * a URL string as defined by RFC 1738 and its related RFCs. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * any string that conforms to the syntax described therein, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * may not always have corresponding support in the java.net.URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * class or Web browsers.
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 NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * @see NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * @see ObjectFactoryBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * @see StateFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public interface ObjectFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Creates an object using the location or reference information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Special requirements of this object are supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * using <code>environment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * An example of such an environment property is user identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <tt>NamingManager.getObjectInstance()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * successively loads in object factories and invokes this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * on them until one produces a non-null answer.  When an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * is thrown by an object factory, the exception is passed on to the caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * of <tt>NamingManager.getObjectInstance()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * (and no search is made for other factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * that may produce a non-null answer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * An object factory should only throw an exception if it is sure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * it is the only intended factory and that no other object factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * should be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * If this factory cannot create an object using the arguments supplied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * it should return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * A <em>URL context factory</em> is a special ObjectFactory that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * creates contexts for resolving URLs or objects whose locations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * are specified by URLs.  The <tt>getObjectInstance()</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * of a URL context factory will obey the following rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <li>If <code>obj</code> is null, create a context for resolving URLs of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * scheme associated with this factory. The resulting context is not tied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * to a specific URL:  it is able to handle arbitrary URLs with this factory's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * scheme id.  For example, invoking <tt>getObjectInstance()</tt> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <code>obj</code> set to null on an LDAP URL context factory would return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * context that can resolve LDAP URLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * such as "ldap://ldap.wiz.com/o=wiz,c=us" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * "ldap://ldap.umich.edu/o=umich,c=us".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * If <code>obj</code> is a URL string, create an object (typically a context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * identified by the URL.  For example, suppose this is an LDAP URL context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * factory.  If <code>obj</code> is "ldap://ldap.wiz.com/o=wiz,c=us",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * getObjectInstance() would return the context named by the distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * name "o=wiz, c=us" at the LDAP server ldap.wiz.com.  This context can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * then be used to resolve LDAP names (such as "cn=George")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * relative to that context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * If <code>obj</code> is an array of URL strings, the assumption is that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * URLs are equivalent in terms of the context to which they refer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * Verification of whether the URLs are, or need to be, equivalent is up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * to the context factory. The order of the URLs in the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * not significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * The object returned by getObjectInstance() is like that of the single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * URL case.  It is the object named by the URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * If <code>obj</code> is of any other type, the behavior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <tt>getObjectInstance()</tt> is determined by the context factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * The <tt>name</tt> and <tt>environment</tt> parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * are owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * The implementation will not modify these objects or keep references
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * to them, although it may keep references to clones or copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <b>Name and Context Parameters.</b> &nbsp;&nbsp;&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <a name=NAMECTX></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * The <code>name</code> and <code>nameCtx</code> parameters may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * optionally be used to specify the name of the object being created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <code>name</code> is the name of the object, relative to context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <code>nameCtx</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * If there are several possible contexts from which the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * could be named -- as will often be the case -- it is up to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * the caller to select one.  A good rule of thumb is to select the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * "deepest" context available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * If <code>nameCtx</code> is null, <code>name</code> is relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * to the default initial context.  If no name is being specified, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>name</code> parameter should be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * If a factory uses <code>nameCtx</code> it should synchronize its use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * against concurrent access, since context implementations are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * @param obj The possibly null object containing location or reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *              information that can be used in creating an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * @param name The name of this object relative to <code>nameCtx</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *              or null if no name is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * @param nameCtx The context relative to which the <code>name</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *              parameter is specified, or null if <code>name</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *              relative to the default initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * @param environment The possibly null environment that is used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *              creating the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @return The object created; null if an object cannot be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @exception Exception if this object factory encountered an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * while attempting to create an object, and no other object factories are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * to be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * @see NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * @see NamingManager#getURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                    Hashtable<?,?> environment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}