Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/naming/spi/ObjectFactory.java
38918 views
/*1* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.spi;2627import java.util.Hashtable;2829import javax.naming.*;3031/**32* This interface represents a factory for creating an object.33*<p>34* The JNDI framework allows for object implementations to35* be loaded in dynamically via <em>object factories</em>.36* For example, when looking up a printer bound in the name space,37* if the print service binds printer names to References, the printer38* Reference could be used to create a printer object, so that39* the caller of lookup can directly operate on the printer object40* after the lookup.41* <p>An <tt>ObjectFactory</tt> is responsible42* for creating objects of a specific type. In the above example,43* you may have a PrinterObjectFactory for creating Printer objects.44*<p>45* An object factory must implement the <tt>ObjectFactory</tt> interface.46* In addition, the factory class must be public and must have a47* public constructor that accepts no parameters.48*<p>49* The <tt>getObjectInstance()</tt> method of an object factory may50* be invoked multiple times, possibly using different parameters.51* The implementation is thread-safe.52*<p>53* The mention of URL in the documentation for this class refers to54* a URL string as defined by RFC 1738 and its related RFCs. It is55* any string that conforms to the syntax described therein, and56* may not always have corresponding support in the java.net.URL57* class or Web browsers.58*59* @author Rosanna Lee60* @author Scott Seligman61*62* @see NamingManager#getObjectInstance63* @see NamingManager#getURLContext64* @see ObjectFactoryBuilder65* @see StateFactory66* @since 1.367*/6869public interface ObjectFactory {70/**71* Creates an object using the location or reference information72* specified.73* <p>74* Special requirements of this object are supplied75* using <code>environment</code>.76* An example of such an environment property is user identity77* information.78*<p>79* <tt>NamingManager.getObjectInstance()</tt>80* successively loads in object factories and invokes this method81* on them until one produces a non-null answer. When an exception82* is thrown by an object factory, the exception is passed on to the caller83* of <tt>NamingManager.getObjectInstance()</tt>84* (and no search is made for other factories85* that may produce a non-null answer).86* An object factory should only throw an exception if it is sure that87* it is the only intended factory and that no other object factories88* should be tried.89* If this factory cannot create an object using the arguments supplied,90* it should return null.91*<p>92* A <em>URL context factory</em> is a special ObjectFactory that93* creates contexts for resolving URLs or objects whose locations94* are specified by URLs. The <tt>getObjectInstance()</tt> method95* of a URL context factory will obey the following rules.96* <ol>97* <li>If <code>obj</code> is null, create a context for resolving URLs of the98* scheme associated with this factory. The resulting context is not tied99* to a specific URL: it is able to handle arbitrary URLs with this factory's100* scheme id. For example, invoking <tt>getObjectInstance()</tt> with101* <code>obj</code> set to null on an LDAP URL context factory would return a102* context that can resolve LDAP URLs103* such as "ldap://ldap.wiz.com/o=wiz,c=us" and104* "ldap://ldap.umich.edu/o=umich,c=us".105* <li>106* If <code>obj</code> is a URL string, create an object (typically a context)107* identified by the URL. For example, suppose this is an LDAP URL context108* factory. If <code>obj</code> is "ldap://ldap.wiz.com/o=wiz,c=us",109* getObjectInstance() would return the context named by the distinguished110* name "o=wiz, c=us" at the LDAP server ldap.wiz.com. This context can111* then be used to resolve LDAP names (such as "cn=George")112* relative to that context.113* <li>114* If <code>obj</code> is an array of URL strings, the assumption is that the115* URLs are equivalent in terms of the context to which they refer.116* Verification of whether the URLs are, or need to be, equivalent is up117* to the context factory. The order of the URLs in the array is118* not significant.119* The object returned by getObjectInstance() is like that of the single120* URL case. It is the object named by the URLs.121* <li>122* If <code>obj</code> is of any other type, the behavior of123* <tt>getObjectInstance()</tt> is determined by the context factory124* implementation.125* </ol>126*127* <p>128* The <tt>name</tt> and <tt>environment</tt> parameters129* are owned by the caller.130* The implementation will not modify these objects or keep references131* to them, although it may keep references to clones or copies.132*133* <p>134* <b>Name and Context Parameters.</b> 135* <a name=NAMECTX></a>136*137* The <code>name</code> and <code>nameCtx</code> parameters may138* optionally be used to specify the name of the object being created.139* <code>name</code> is the name of the object, relative to context140* <code>nameCtx</code>.141* If there are several possible contexts from which the object142* could be named -- as will often be the case -- it is up to143* the caller to select one. A good rule of thumb is to select the144* "deepest" context available.145* If <code>nameCtx</code> is null, <code>name</code> is relative146* to the default initial context. If no name is being specified, the147* <code>name</code> parameter should be null.148* If a factory uses <code>nameCtx</code> it should synchronize its use149* against concurrent access, since context implementations are not150* guaranteed to be thread-safe.151* <p>152*153* @param obj The possibly null object containing location or reference154* information that can be used in creating an object.155* @param name The name of this object relative to <code>nameCtx</code>,156* or null if no name is specified.157* @param nameCtx The context relative to which the <code>name</code>158* parameter is specified, or null if <code>name</code> is159* relative to the default initial context.160* @param environment The possibly null environment that is used in161* creating the object.162* @return The object created; null if an object cannot be created.163* @exception Exception if this object factory encountered an exception164* while attempting to create an object, and no other object factories are165* to be tried.166*167* @see NamingManager#getObjectInstance168* @see NamingManager#getURLContext169*/170public Object getObjectInstance(Object obj, Name name, Context nameCtx,171Hashtable<?,?> environment)172throws Exception;173}174175176