Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/naming/spi/StateFactory.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*/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 <tt>Reference</tt>s, the printer37* <tt>Reference</tt> 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 <tt>ObjectFactory</tt> is responsible41* for creating objects of a specific type. In the above example,42* you may have a <tt>PrinterObjectFactory</tt> for creating43* <tt>Printer</tt> 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 <tt>ctx</tt> uses a state factory53* to obtain the state of <tt>printer</tt> for binding into its namespace.54* A state factory for the <tt>Printer</tt> type object might return55* a more compact object for storage in the naming system.56*<p>57* A state factory must implement the <tt>StateFactory</tt> interface.58* In addition, the factory class must be public and must have a59* public constructor that accepts no parameters.60*<p>61* The <tt>getStateToBind()</tt> method of a state factory may62* be invoked multiple times, possibly using different parameters.63* The implementation is thread-safe.64*<p>65* <tt>StateFactory</tt> is intended for use with service providers66* that implement only the <tt>Context</tt> interface.67* <tt>DirStateFactory</tt> is intended for use with service providers68* that implement the <tt>DirContext</tt> interface.69*70* @author Rosanna Lee71* @author Scott Seligman72*73* @see NamingManager#getStateToBind74* @see DirectoryManager#getStateToBind75* @see ObjectFactory76* @see DirStateFactory77* @since 1.378*/79public interface StateFactory {80/**81* Retrieves the state of an object for binding.82*<p>83* <tt>NamingManager.getStateToBind()</tt>84* successively loads in state factories and invokes this method85* on them until one produces a non-null answer.86* <tt>DirectoryManager.getStateToBind()</tt>87* successively loads in state factories. If a factory implements88* <tt>DirStateFactory</tt>, then <tt>DirectoryManager</tt>89* invokes <tt>DirStateFactory.getStateToBind()</tt>; otherwise90* it invokes <tt>StateFactory.getStateToBind()</tt>.91*<p> When an exception92* is thrown by a factory, the exception is passed on to the caller93* of <tt>NamingManager.getStateToBind()</tt> and94* <tt>DirectoryManager.getStateToBind()</tt>.95* The search for other factories96* that may produce a non-null answer is halted.97* A factory should only throw an exception if it is sure that98* it is the only intended factory and that no other factories99* should be tried.100* If this factory cannot create an object using the arguments supplied,101* it should return null.102* <p>103* The <code>name</code> and <code>nameCtx</code> parameters may104* optionally be used to specify the name of the object being created.105* See the description of "Name and Context Parameters" in106* {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}107* for details.108* If a factory uses <code>nameCtx</code> it should synchronize its use109* against concurrent access, since context implementations are not110* guaranteed to be thread-safe.111* <p>112* The <tt>name</tt> and <tt>environment</tt> parameters113* are owned by the caller.114* The implementation will not modify these objects or keep references115* to them, although it may keep references to clones or copies.116*117* @param obj A non-null object whose state is to be retrieved.118* @param name The name of this object relative to <code>nameCtx</code>,119* or null if no name is specified.120* @param nameCtx The context relative to which the <code>name</code>121* parameter is specified, or null if <code>name</code> is122* relative to the default initial context.123* @param environment The possibly null environment to124* be used in the creation of the object's state.125* @return The object's state for binding;126* null if the factory is not returning any changes.127* @exception NamingException if this factory encountered an exception128* while attempting to get the object's state, and no other factories are129* to be tried.130*131* @see NamingManager#getStateToBind132* @see DirectoryManager#getStateToBind133*/134public Object getStateToBind(Object obj, Name name, Context nameCtx,135Hashtable<?,?> environment)136throws NamingException;137}138139140