0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.naming.spi;
0N/A
0N/Aimport javax.naming.*;
0N/Aimport javax.naming.directory.Attributes;
0N/Aimport java.util.Hashtable;
0N/A
0N/A/**
0N/A * This interface represents a factory for obtaining the state of an
0N/A * object and corresponding attributes for binding.
0N/A *<p>
0N/A * The JNDI framework allows for object implementations to
0N/A * be loaded in dynamically via <tt>object factories</tt>.
0N/A * <p>
0N/A * A <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>
0N/A * by allowing an <tt>Attributes</tt> instance
0N/A * to be supplied to and be returned by the <tt>getStateToBind()</tt> method.
0N/A * <tt>DirStateFactory</tt> implementations are intended to be used by
0N/A * <tt>DirContext</tt> service providers.
0N/A * When a caller binds an object using <tt>DirContext.bind()</tt>,
0N/A * he might also specify a set of attributes to be bound with the object.
0N/A * The object and attributes to be bound are passed to
0N/A * the <tt>getStateToBind()</tt> method of a factory.
0N/A * If the factory processes the object and attributes, it returns
0N/A * a corresponding pair of object and attributes to be bound.
0N/A * If the factory does not process the object, it must return null.
0N/A *<p>
0N/A * For example, a caller might bind a printer object with some printer-related
0N/A * attributes.
0N/A *<blockquote><pre>
0N/A * ctx.rebind("inky", printer, printerAttrs);
0N/A *</pre></blockquote>
0N/A * An LDAP service provider for <tt>ctx</tt> uses a <tt>DirStateFactory</tt>
0N/A * (indirectly via <tt>DirectoryManager.getStateToBind()</tt>)
0N/A * and gives it <tt>printer</tt> and <tt>printerAttrs</tt>. A factory for
0N/A * an LDAP directory might turn <tt>printer</tt> into a set of attributes
0N/A * and merge that with <tt>printerAttrs</tt>. The service provider then
0N/A * uses the resulting attributes to create an LDAP entry and updates
0N/A * the directory.
0N/A *
0N/A * <p> Since <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>, it
0N/A * has two <tt>getStateToBind()</tt> methods, where one
0N/A * differs from the other by the attributes
0N/A * argument. <tt>DirectoryManager.getStateToBind()</tt> will only use
0N/A * the form that accepts the attributes argument, while
0N/A * <tt>NamingManager.getStateToBind()</tt> will only use the form that
0N/A * does not accept the attributes argument.
0N/A *
0N/A * <p> Either form of the <tt>getStateToBind()</tt> method of a
0N/A * DirStateFactory may be invoked multiple times, possibly using different
0N/A * parameters. The implementation is thread-safe.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A *
0N/A * @see DirectoryManager#getStateToBind
0N/A * @see DirObjectFactory
0N/A * @since 1.3
0N/A */
0N/Apublic interface DirStateFactory extends StateFactory {
0N/A/**
0N/A * Retrieves the state of an object for binding given the object and attributes
0N/A * to be transformed.
0N/A *<p>
0N/A * <tt>DirectoryManager.getStateToBind()</tt>
0N/A * successively loads in state factories. If a factory implements
0N/A * <tt>DirStateFactory</tt>, <tt>DirectoryManager</tt> invokes this method;
0N/A * otherwise, it invokes <tt>StateFactory.getStateToBind()</tt>.
0N/A * It does this until a factory produces a non-null answer.
0N/A *<p>
0N/A * When an exception is thrown by a factory,
0N/A * the exception is passed on to the caller
0N/A * of <tt>DirectoryManager.getStateToBind()</tt>. The search for other factories
0N/A * that may produce a non-null answer is halted.
0N/A * A factory should only throw an exception if it is sure that
0N/A * it is the only intended factory and that no other factories
0N/A * should be tried.
0N/A * If this factory cannot create an object using the arguments supplied,
0N/A * it should return null.
0N/A * <p>
0N/A * The <code>name</code> and <code>nameCtx</code> parameters may
0N/A * optionally be used to specify the name of the object being created.
0N/A * See the description of "Name and Context Parameters" in
0N/A * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
0N/A * for details.
0N/A * If a factory uses <code>nameCtx</code> it should synchronize its use
0N/A * against concurrent access, since context implementations are not
0N/A * guaranteed to be thread-safe.
0N/A *<p>
0N/A * The <tt>name</tt>, <tt>inAttrs</tt>, and <tt>environment</tt> parameters
0N/A * are owned by the caller.
0N/A * The implementation will not modify these objects or keep references
0N/A * to them, although it may keep references to clones or copies.
0N/A * The object returned by this method is owned by the caller.
0N/A * The implementation will not subsequently modify it.
0N/A * It will contain either a new <tt>Attributes</tt> object that is
0N/A * likewise owned by the caller, or a reference to the original
0N/A * <tt>inAttrs</tt> parameter.
0N/A *
0N/A * @param obj A possibly null object whose state is to be retrieved.
0N/A * @param name The name of this object relative to <code>nameCtx</code>,
0N/A * or null if no name is specified.
0N/A * @param nameCtx The context relative to which the <code>name</code>
0N/A * parameter is specified, or null if <code>name</code> is
0N/A * relative to the default initial context.
0N/A * @param environment The possibly null environment to
0N/A * be used in the creation of the object's state.
0N/A * @param inAttrs The possibly null attributes to be bound with the object.
0N/A * The factory must not modify <tt>inAttrs</tt>.
0N/A * @return A <tt>Result</tt> containing the object's state for binding
0N/A * and the corresponding
0N/A * attributes to be bound; null if the object don't use this factory.
0N/A * @exception NamingException If this factory encountered an exception
0N/A * while attempting to get the object's state, and no other factories are
0N/A * to be tried.
0N/A *
0N/A * @see DirectoryManager#getStateToBind
0N/A */
0N/A public Result getStateToBind(Object obj, Name name, Context nameCtx,
0N/A Hashtable<?,?> environment,
0N/A Attributes inAttrs)
0N/A throws NamingException;
0N/A
0N/A
0N/A /**
0N/A * An object/attributes pair for returning the result of
0N/A * DirStateFactory.getStateToBind().
0N/A */
0N/A public static class Result {
0N/A /**
0N/A * The possibly null object to be bound.
0N/A */
0N/A private Object obj;
0N/A
0N/A
0N/A /**
0N/A * The possibly null attributes to be bound.
0N/A */
0N/A private Attributes attrs;
0N/A
0N/A /**
0N/A * Constructs an instance of Result.
0N/A *
0N/A * @param obj The possibly null object to be bound.
0N/A * @param outAttrs The possibly null attributes to be bound.
0N/A */
0N/A public Result(Object obj, Attributes outAttrs) {
0N/A this.obj = obj;
0N/A this.attrs = outAttrs;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the object to be bound.
0N/A * @return The possibly null object to be bound.
0N/A */
0N/A public Object getObject() { return obj; };
0N/A
0N/A /**
0N/A * Retrieves the attributes to be bound.
0N/A * @return The possibly null attributes to be bound.
0N/A */
0N/A public Attributes getAttributes() { return attrs; };
0N/A
0N/A }
0N/A}