Path: blob/master/src/java.naming/share/classes/javax/naming/spi/StateFactory.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*/24package javax.naming.spi;2526import javax.naming.*;27import java.util.Hashtable;2829/**30* This interface represents a factory for obtaining the state of an31* object for binding.32*<p>33* The JNDI framework allows for object implementations to34* be loaded in dynamically via <em>object factories</em>.35* For example, when looking up a printer bound in the name space,36* if the print service binds printer names to {@code Reference}s, the printer37* {@code Reference} could be used to create a printer object, so that38* the caller of lookup can directly operate on the printer object39* after the lookup.40* <p>An {@code ObjectFactory} is responsible41* for creating objects of a specific type. In the above example,42* you may have a {@code PrinterObjectFactory} for creating43* {@code Printer} objects.44* <p>45* For the reverse process, when an object is bound into the namespace,46* JNDI provides <em>state factories</em>.47* Continuing with the printer example, suppose the printer object is48* updated and rebound:49* <blockquote><pre>50* ctx.rebind("inky", printer);51* </pre></blockquote>52* The service provider for {@code ctx} uses a state factory53* to obtain the state of {@code printer} for binding into its namespace.54* A state factory for the {@code Printer} type object might return55* a more compact object for storage in the naming system.56*<p>57* A state factory must implement the {@code StateFactory} interface.58* In addition, the factory class must be public and must have a59* public constructor that accepts no parameters.60* Note that in cases where the factory is in a named module then it must be61* in a package which is exported by that module to the {@code java.naming}62* module.63*<p>64* The {@code getStateToBind()} method of a state factory may65* be invoked multiple times, possibly using different parameters.66* The implementation is thread-safe.67*<p>68* {@code StateFactory} is intended for use with service providers69* that implement only the {@code Context} interface.70* {@code DirStateFactory} is intended for use with service providers71* that implement the {@code DirContext} interface.72*73* @author Rosanna Lee74* @author Scott Seligman75*76* @see NamingManager#getStateToBind77* @see DirectoryManager#getStateToBind78* @see ObjectFactory79* @see DirStateFactory80* @since 1.381*/82public interface StateFactory {83/**84* Retrieves the state of an object for binding.85*<p>86* {@code NamingManager.getStateToBind()}87* successively loads in state factories and invokes this method88* on them until one produces a non-null answer.89* {@code DirectoryManager.getStateToBind()}90* successively loads in state factories. If a factory implements91* {@code DirStateFactory}, then {@code DirectoryManager}92* invokes {@code DirStateFactory.getStateToBind()}; otherwise93* it invokes {@code StateFactory.getStateToBind()}.94*<p> When an exception95* is thrown by a factory, the exception is passed on to the caller96* of {@code NamingManager.getStateToBind()} and97* {@code DirectoryManager.getStateToBind()}.98* The search for other factories99* that may produce a non-null answer is halted.100* A factory should only throw an exception if it is sure that101* it is the only intended factory and that no other factories102* should be tried.103* If this factory cannot create an object using the arguments supplied,104* it should return null.105* <p>106* The <code>name</code> and <code>nameCtx</code> parameters may107* optionally be used to specify the name of the object being created.108* See the description of "Name and Context Parameters" in109* {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}110* for details.111* If a factory uses <code>nameCtx</code> it should synchronize its use112* against concurrent access, since context implementations are not113* guaranteed to be thread-safe.114* <p>115* The {@code name} and {@code environment} parameters116* are owned by the caller.117* The implementation will not modify these objects or keep references118* to them, although it may keep references to clones or copies.119*120* @param obj A non-null object whose state is to be retrieved.121* @param name The name of this object relative to <code>nameCtx</code>,122* or null if no name is specified.123* @param nameCtx The context relative to which the <code>name</code>124* parameter is specified, or null if <code>name</code> is125* relative to the default initial context.126* @param environment The possibly null environment to127* be used in the creation of the object's state.128* @return The object's state for binding;129* null if the factory is not returning any changes.130* @throws NamingException if this factory encountered an exception131* while attempting to get the object's state, and no other factories are132* to be tried.133*134* @see NamingManager#getStateToBind135* @see DirectoryManager#getStateToBind136*/137public Object getStateToBind(Object obj, Name name, Context nameCtx,138Hashtable<?,?> environment)139throws NamingException;140}141142143