0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming.spi;
0N/A
0N/Aimport java.util.Hashtable;
0N/A
0N/Aimport javax.naming.*;
0N/A
0N/A/**
0N/A * This interface represents a factory for creating an object.
0N/A *<p>
0N/A * The JNDI framework allows for object implementations to
0N/A * be loaded in dynamically via <em>object factories</em>.
0N/A * For example, when looking up a printer bound in the name space,
0N/A * if the print service binds printer names to References, the printer
0N/A * Reference could be used to create a printer object, so that
0N/A * the caller of lookup can directly operate on the printer object
0N/A * after the lookup.
0N/A * <p>An <tt>ObjectFactory</tt> is responsible
0N/A * for creating objects of a specific type. In the above example,
0N/A * you may have a PrinterObjectFactory for creating Printer objects.
0N/A *<p>
0N/A * An object factory must implement the <tt>ObjectFactory</tt> interface.
0N/A * In addition, the factory class must be public and must have a
0N/A * public constructor that accepts no parameters.
0N/A *<p>
0N/A * The <tt>getObjectInstance()</tt> method of an object factory may
0N/A * be invoked multiple times, possibly using different parameters.
0N/A * The implementation is thread-safe.
0N/A *<p>
0N/A * The mention of URL in the documentation for this class refers to
0N/A * a URL string as defined by RFC 1738 and its related RFCs. It is
0N/A * any string that conforms to the syntax described therein, and
0N/A * may not always have corresponding support in the java.net.URL
0N/A * class or Web browsers.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A *
0N/A * @see NamingManager#getObjectInstance
0N/A * @see NamingManager#getURLContext
0N/A * @see ObjectFactoryBuilder
0N/A * @see StateFactory
0N/A * @since 1.3
0N/A */
0N/A
0N/Apublic interface ObjectFactory {
0N/A/**
0N/A * Creates an object using the location or reference information
0N/A * specified.
0N/A * <p>
0N/A * Special requirements of this object are supplied
0N/A * using <code>environment</code>.
0N/A * An example of such an environment property is user identity
0N/A * information.
0N/A *<p>
0N/A * <tt>NamingManager.getObjectInstance()</tt>
0N/A * successively loads in object factories and invokes this method
0N/A * on them until one produces a non-null answer. When an exception
0N/A * is thrown by an object factory, the exception is passed on to the caller
0N/A * of <tt>NamingManager.getObjectInstance()</tt>
0N/A * (and no search is made for other factories
0N/A * that may produce a non-null answer).
0N/A * An object factory should only throw an exception if it is sure that
0N/A * it is the only intended factory and that no other object factories
0N/A * should be tried.
0N/A * If this factory cannot create an object using the arguments supplied,
0N/A * it should return null.
0N/A *<p>
0N/A * A <em>URL context factory</em> is a special ObjectFactory that
0N/A * creates contexts for resolving URLs or objects whose locations
0N/A * are specified by URLs. The <tt>getObjectInstance()</tt> method
0N/A * of a URL context factory will obey the following rules.
0N/A * <ol>
0N/A * <li>If <code>obj</code> is null, create a context for resolving URLs of the
0N/A * scheme associated with this factory. The resulting context is not tied
0N/A * to a specific URL: it is able to handle arbitrary URLs with this factory's
0N/A * scheme id. For example, invoking <tt>getObjectInstance()</tt> with
0N/A * <code>obj</code> set to null on an LDAP URL context factory would return a
0N/A * context that can resolve LDAP URLs
0N/A * such as "ldap://ldap.wiz.com/o=wiz,c=us" and
0N/A * "ldap://ldap.umich.edu/o=umich,c=us".
0N/A * <li>
0N/A * If <code>obj</code> is a URL string, create an object (typically a context)
0N/A * identified by the URL. For example, suppose this is an LDAP URL context
0N/A * factory. If <code>obj</code> is "ldap://ldap.wiz.com/o=wiz,c=us",
0N/A * getObjectInstance() would return the context named by the distinguished
0N/A * name "o=wiz, c=us" at the LDAP server ldap.wiz.com. This context can
0N/A * then be used to resolve LDAP names (such as "cn=George")
0N/A * relative to that context.
0N/A * <li>
0N/A * If <code>obj</code> is an array of URL strings, the assumption is that the
0N/A * URLs are equivalent in terms of the context to which they refer.
0N/A * Verification of whether the URLs are, or need to be, equivalent is up
0N/A * to the context factory. The order of the URLs in the array is
0N/A * not significant.
0N/A * The object returned by getObjectInstance() is like that of the single
0N/A * URL case. It is the object named by the URLs.
0N/A * <li>
0N/A * If <code>obj</code> is of any other type, the behavior of
0N/A * <tt>getObjectInstance()</tt> is determined by the context factory
0N/A * implementation.
0N/A * </ol>
0N/A *
0N/A * <p>
0N/A * The <tt>name</tt> and <tt>environment</tt> parameters
0N/A * are owned by the caller.
0N/A * The implementation will not modify these objects or keep references
0N/A * to them, although it may keep references to clones or copies.
0N/A *
0N/A * <p>
0N/A * <b>Name and Context Parameters.</b> &nbsp;&nbsp;&nbsp;
0N/A * <a name=NAMECTX></a>
0N/A *
0N/A * The <code>name</code> and <code>nameCtx</code> parameters may
0N/A * optionally be used to specify the name of the object being created.
0N/A * <code>name</code> is the name of the object, relative to context
0N/A * <code>nameCtx</code>.
0N/A * If there are several possible contexts from which the object
0N/A * could be named -- as will often be the case -- it is up to
0N/A * the caller to select one. A good rule of thumb is to select the
0N/A * "deepest" context available.
0N/A * If <code>nameCtx</code> is null, <code>name</code> is relative
0N/A * to the default initial context. If no name is being specified, the
0N/A * <code>name</code> parameter should be null.
0N/A * If a factory uses <code>nameCtx</code> it should synchronize its use
0N/A * against concurrent access, since context implementations are not
0N/A * guaranteed to be thread-safe.
0N/A * <p>
0N/A *
0N/A * @param obj The possibly null object containing location or reference
0N/A * information that can be used in creating an object.
0N/A * @param name The name of this object relative to <code>nameCtx</code>,
0N/A * or null if no name is specified.
0N/A * @param nameCtx The context relative to which the <code>name</code>
0N/A * parameter is specified, or null if <code>name</code> is
0N/A * relative to the default initial context.
0N/A * @param environment The possibly null environment that is used in
0N/A * creating the object.
0N/A * @return The object created; null if an object cannot be created.
0N/A * @exception Exception if this object factory encountered an exception
0N/A * while attempting to create an object, and no other object factories are
0N/A * to be tried.
0N/A *
0N/A * @see NamingManager#getObjectInstance
0N/A * @see NamingManager#getURLContext
0N/A */
0N/A public Object getObjectInstance(Object obj, Name name, Context nameCtx,
0N/A Hashtable<?,?> environment)
0N/A throws Exception;
0N/A}