Path: blob/master/src/java.naming/share/classes/javax/naming/spi/DirStateFactory.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 javax.naming.directory.Attributes;28import java.util.Hashtable;2930/**31* This interface represents a factory for obtaining the state of an32* object and corresponding attributes for binding.33*<p>34* The JNDI framework allows for object implementations to35* be loaded in dynamically via {@code object factories}.36* <p>37* A {@code DirStateFactory} extends {@code StateFactory}38* by allowing an {@code Attributes} instance39* to be supplied to and be returned by the {@code getStateToBind()} method.40* {@code DirStateFactory} implementations are intended to be used by41* {@code DirContext} service providers.42* When a caller binds an object using {@code DirContext.bind()},43* he might also specify a set of attributes to be bound with the object.44* The object and attributes to be bound are passed to45* the {@code getStateToBind()} method of a factory.46* If the factory processes the object and attributes, it returns47* a corresponding pair of object and attributes to be bound.48* If the factory does not process the object, it must return null.49*<p>50* For example, a caller might bind a printer object with some printer-related51* attributes.52*<blockquote><pre>53* ctx.rebind("inky", printer, printerAttrs);54*</pre></blockquote>55* An LDAP service provider for {@code ctx} uses a {@code DirStateFactory}56* (indirectly via {@code DirectoryManager.getStateToBind()})57* and gives it {@code printer} and {@code printerAttrs}. A factory for58* an LDAP directory might turn {@code printer} into a set of attributes59* and merge that with {@code printerAttrs}. The service provider then60* uses the resulting attributes to create an LDAP entry and updates61* the directory.62*63* <p> Since {@code DirStateFactory} extends {@code StateFactory}, it64* has two {@code getStateToBind()} methods, where one65* differs from the other by the attributes66* argument. {@code DirectoryManager.getStateToBind()} will only use67* the form that accepts the attributes argument, while68* {@code NamingManager.getStateToBind()} will only use the form that69* does not accept the attributes argument.70*71* <p> Either form of the {@code getStateToBind()} method of a72* DirStateFactory may be invoked multiple times, possibly using different73* parameters. The implementation is thread-safe.74*75* @author Rosanna Lee76* @author Scott Seligman77*78* @see DirectoryManager#getStateToBind79* @see DirObjectFactory80* @since 1.381*/82public interface DirStateFactory extends StateFactory {83/**84* Retrieves the state of an object for binding given the object and attributes85* to be transformed.86*<p>87* {@code DirectoryManager.getStateToBind()}88* successively loads in state factories. If a factory implements89* {@code DirStateFactory}, {@code DirectoryManager} invokes this method;90* otherwise, it invokes {@code StateFactory.getStateToBind()}.91* It does this until a factory produces a non-null answer.92*<p>93* When an exception is thrown by a factory,94* the exception is passed on to the caller95* of {@code DirectoryManager.getStateToBind()}. 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} and {@code nameCtx} 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} it should synchronize its use109* against concurrent access, since context implementations are not110* guaranteed to be thread-safe.111*<p>112* The {@code name}, {@code inAttrs}, and {@code environment} 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* The object returned by this method is owned by the caller.117* The implementation will not subsequently modify it.118* It will contain either a new {@code Attributes} object that is119* likewise owned by the caller, or a reference to the original120* {@code inAttrs} parameter.121*122* @param obj A possibly null object whose state is to be retrieved.123* @param name The name of this object relative to {@code nameCtx},124* or null if no name is specified.125* @param nameCtx The context relative to which the {@code name}126* parameter is specified, or null if {@code name} is127* relative to the default initial context.128* @param environment The possibly null environment to129* be used in the creation of the object's state.130* @param inAttrs The possibly null attributes to be bound with the object.131* The factory must not modify {@code inAttrs}.132* @return A {@code Result} containing the object's state for binding133* and the corresponding134* attributes to be bound; null if the object don't use this factory.135* @throws NamingException If this factory encountered an exception136* while attempting to get the object's state, and no other factories are137* to be tried.138*139* @see DirectoryManager#getStateToBind140*/141public Result getStateToBind(Object obj, Name name, Context nameCtx,142Hashtable<?,?> environment,143Attributes inAttrs)144throws NamingException;145146147/**148* An object/attributes pair for returning the result of149* DirStateFactory.getStateToBind().150*/151public static class Result {152/**153* The possibly null object to be bound.154*/155private Object obj;156157158/**159* The possibly null attributes to be bound.160*/161private Attributes attrs;162163/**164* Constructs an instance of Result.165*166* @param obj The possibly null object to be bound.167* @param outAttrs The possibly null attributes to be bound.168*/169public Result(Object obj, Attributes outAttrs) {170this.obj = obj;171this.attrs = outAttrs;172}173174/**175* Retrieves the object to be bound.176* @return The possibly null object to be bound.177*/178public Object getObject() { return obj; };179180/**181* Retrieves the attributes to be bound.182* @return The possibly null attributes to be bound.183*/184public Attributes getAttributes() { return attrs; };185186}187}188189190