Path: blob/master/src/java.naming/share/classes/javax/naming/spi/DirObjectFactory.java
41159 views
/*1* Copyright (c) 1999, 2020, 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;28import javax.naming.*;29import javax.naming.directory.Attributes;3031/**32* This interface represents a factory for creating an object given33* an object and attributes about the object.34*<p>35* The JNDI framework allows for object implementations to36* be loaded in dynamically via <em>object factories</em>. See37* {@code ObjectFactory} for details.38* <p>39* A {@code DirObjectFactory} extends {@code ObjectFactory} by allowing40* an {@code Attributes} instance41* to be supplied to the {@code getObjectInstance()} method.42* {@code DirObjectFactory} implementations are intended to be used by {@code DirContext}43* service providers. The service provider, in addition reading an44* object from the directory, might already have attributes that45* are useful for the object factory to check to see whether the46* factory is supposed to process the object. For instance, an LDAP-style47* service provider might have read the "objectclass" of the object.48* A CORBA object factory might be interested only in LDAP entries49* with "objectclass=corbaObject". By using the attributes supplied by50* the LDAP service provider, the CORBA object factory can quickly51* eliminate objects that it need not worry about, and non-CORBA object52* factories can quickly eliminate CORBA-related LDAP entries.53*54* @author Rosanna Lee55* @author Scott Seligman56*57* @see NamingManager#getObjectInstance58* @see DirectoryManager#getObjectInstance59* @see ObjectFactory60* @since 1.361*/6263public interface DirObjectFactory extends ObjectFactory {64/**65* Creates an object using the location or reference information, and attributes66* specified.67* <p>68* Special requirements of this object are supplied69* using <code>environment</code>.70* An example of such an environment property is user identity71* information.72*<p>73* {@code DirectoryManager.getObjectInstance()}74* successively loads in object factories. If it encounters a {@code DirObjectFactory},75* it will invoke {@code DirObjectFactory.getObjectInstance()};76* otherwise, it invokes77* {@code ObjectFactory.getObjectInstance()}. It does this until a factory78* produces a non-null answer.79* <p> When an exception80* is thrown by an object factory, the exception is passed on to the caller81* of {@code DirectoryManager.getObjectInstance()}. The search for other factories82* that may produce a non-null answer is halted.83* An object factory should only throw an exception if it is sure that84* it is the only intended factory and that no other object factories85* should be tried.86* If this factory cannot create an object using the arguments supplied,87* it should return null.88*<p>Since {@code DirObjectFactory} extends {@code ObjectFactory}, it89* effectively90* has two {@code getObjectInstance()} methods, where one differs from the other by91* the attributes argument. Given a factory that implements {@code DirObjectFactory},92* {@code DirectoryManager.getObjectInstance()} will only93* use the method that accepts the attributes argument, while94* {@code NamingManager.getObjectInstance()} will only use the one that does not accept95* the attributes argument.96*<p>97* See {@code ObjectFactory} for a description URL context factories and other98* properties of object factories that apply equally to {@code DirObjectFactory}.99*<p>100* The {@code name}, {@code attrs}, and {@code environment} parameters101* are owned by the caller.102* The implementation will not modify these objects or keep references103* to them, although it may keep references to clones or copies.104*105* @param obj The possibly null object containing location or reference106* information that can be used in creating an object.107* @param name The name of this object relative to <code>nameCtx</code>,108* or null if no name is specified.109* @param nameCtx The context relative to which the <code>name</code>110* parameter is specified, or null if <code>name</code> is111* relative to the default initial context.112* @param environment The possibly null environment that is used in113* creating the object.114* @param attrs The possibly null attributes containing some of {@code obj}'s115* attributes. {@code attrs} might not necessarily have all of {@code obj}'s116* attributes. If the object factory requires more attributes, it needs117* to get it, either using {@code obj}, or {@code name} and {@code nameCtx}.118* The factory must not modify attrs.119* @return The object created; null if an object cannot be created.120* @throws Exception If this object factory encountered an exception121* while attempting to create an object, and no other object factories are122* to be tried.123*124* @see DirectoryManager#getObjectInstance125* @see NamingManager#getURLContext126*/127public Object getObjectInstance(Object obj, Name name, Context nameCtx,128Hashtable<?,?> environment,129Attributes attrs)130throws Exception;131}132133134