Save This Page
Home » openjdk-7 » javax » naming » spi » [javadoc | source]
    1   /*
    2    * Copyright 1999-2004 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   package javax.naming.spi;
   26   
   27   import javax.naming;
   28   import javax.naming.directory.Attributes;
   29   import java.util.Hashtable;
   30   
   31   /**
   32     * This interface represents a factory for obtaining the state of an
   33     * object and corresponding attributes for binding.
   34     *<p>
   35     * The JNDI framework allows for object implementations to
   36     * be loaded in dynamically via <tt>object factories</tt>.
   37     * <p>
   38     * A <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>
   39     * by allowing an <tt>Attributes</tt> instance
   40     * to be supplied to and be returned by the <tt>getStateToBind()</tt> method.
   41     * <tt>DirStateFactory</tt> implementations are intended to be used by
   42     * <tt>DirContext</tt> service providers.
   43     * When a caller binds an object using <tt>DirContext.bind()</tt>,
   44     * he might also specify a set of attributes to be bound with the object.
   45     * The object and attributes to be bound are passed to
   46     * the <tt>getStateToBind()</tt> method of a factory.
   47     * If the factory processes the object and attributes, it returns
   48     * a corresponding pair of object and attributes to be bound.
   49     * If the factory does not process the object, it must return null.
   50     *<p>
   51     * For example, a caller might bind a printer object with some printer-related
   52     * attributes.
   53     *<blockquote><pre>
   54     * ctx.rebind("inky", printer, printerAttrs);
   55     *</pre></blockquote>
   56     * An LDAP service provider for <tt>ctx</tt> uses a <tt>DirStateFactory</tt>
   57     * (indirectly via <tt>DirectoryManager.getStateToBind()</tt>)
   58     * and gives it <tt>printer</tt> and <tt>printerAttrs</tt>. A factory for
   59     * an LDAP directory might turn <tt>printer</tt> into a set of attributes
   60     * and merge that with <tt>printerAttrs</tt>. The service provider then
   61     * uses the resulting attributes to create an LDAP entry and updates
   62     * the directory.
   63     *
   64     * <p> Since <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>, it
   65     * has two <tt>getStateToBind()</tt> methods, where one
   66     * differs from the other by the attributes
   67     * argument. <tt>DirectoryManager.getStateToBind()</tt> will only use
   68     * the form that accepts the attributes argument, while
   69     * <tt>NamingManager.getStateToBind()</tt> will only use the form that
   70     * does not accept the attributes argument.
   71     *
   72     * <p> Either form of the <tt>getStateToBind()</tt> method of a
   73     * DirStateFactory may be invoked multiple times, possibly using different
   74     * parameters.  The implementation is thread-safe.
   75     *
   76     * @author Rosanna Lee
   77     * @author Scott Seligman
   78     *
   79     * @see DirectoryManager#getStateToBind
   80     * @see DirObjectFactory
   81     * @since 1.3
   82     */
   83   public interface DirStateFactory extends StateFactory {
   84   /**
   85    * Retrieves the state of an object for binding given the object and attributes
   86    * to be transformed.
   87    *<p>
   88    * <tt>DirectoryManager.getStateToBind()</tt>
   89    * successively loads in state factories. If a factory implements
   90    * <tt>DirStateFactory</tt>, <tt>DirectoryManager</tt> invokes this method;
   91    * otherwise, it invokes <tt>StateFactory.getStateToBind()</tt>.
   92    * It does this until a factory produces a non-null answer.
   93    *<p>
   94    * When an exception is thrown by a factory,
   95    * the exception is passed on to the caller
   96    * of <tt>DirectoryManager.getStateToBind()</tt>. The search for other factories
   97    * that may produce a non-null answer is halted.
   98    * A factory should only throw an exception if it is sure that
   99    * it is the only intended factory and that no other factories
  100    * should be tried.
  101    * If this factory cannot create an object using the arguments supplied,
  102    * it should return null.
  103    * <p>
  104    * The <code>name</code> and <code>nameCtx</code> parameters may
  105    * optionally be used to specify the name of the object being created.
  106    * See the description of "Name and Context Parameters" in
  107    * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
  108    * for details.
  109    * If a factory uses <code>nameCtx</code> it should synchronize its use
  110    * against concurrent access, since context implementations are not
  111    * guaranteed to be thread-safe.
  112    *<p>
  113    * The <tt>name</tt>, <tt>inAttrs</tt>, and <tt>environment</tt> parameters
  114    * are owned by the caller.
  115    * The implementation will not modify these objects or keep references
  116    * to them, although it may keep references to clones or copies.
  117    * The object returned by this method is owned by the caller.
  118    * The implementation will not subsequently modify it.
  119    * It will contain either a new <tt>Attributes</tt> object that is
  120    * likewise owned by the caller, or a reference to the original
  121    * <tt>inAttrs</tt> parameter.
  122    *
  123    * @param obj A possibly null object whose state is to be retrieved.
  124    * @param name The name of this object relative to <code>nameCtx</code>,
  125    *              or null if no name is specified.
  126    * @param nameCtx The context relative to which the <code>name</code>
  127    *              parameter is specified, or null if <code>name</code> is
  128    *              relative to the default initial context.
  129    * @param environment The possibly null environment to
  130    *              be used in the creation of the object's state.
  131    * @param inAttrs The possibly null attributes to be bound with the object.
  132    *      The factory must not modify <tt>inAttrs</tt>.
  133    * @return A <tt>Result</tt> containing the object's state for binding
  134    * and the corresponding
  135    * attributes to be bound; null if the object don't use this factory.
  136    * @exception NamingException If this factory encountered an exception
  137    * while attempting to get the object's state, and no other factories are
  138    * to be tried.
  139    *
  140    * @see DirectoryManager#getStateToBind
  141    */
  142       public Result getStateToBind(Object obj, Name name, Context nameCtx,
  143                                    Hashtable<?,?> environment,
  144                                    Attributes inAttrs)
  145           throws NamingException;
  146   
  147   
  148           /**
  149            * An object/attributes pair for returning the result of
  150            * DirStateFactory.getStateToBind().
  151            */
  152       public static class Result {
  153           /**
  154            * The possibly null object to be bound.
  155            */
  156           private Object obj;
  157   
  158   
  159           /**
  160            * The possibly null attributes to be bound.
  161            */
  162           private Attributes attrs;
  163   
  164           /**
  165             * Constructs an instance of Result.
  166             *
  167             * @param obj The possibly null object to be bound.
  168             * @param outAttrs The possibly null attributes to be bound.
  169             */
  170           public Result(Object obj, Attributes outAttrs) {
  171               this.obj = obj;
  172               this.attrs = outAttrs;
  173           }
  174   
  175           /**
  176            * Retrieves the object to be bound.
  177            * @return The possibly null object to be bound.
  178            */
  179           public Object getObject() { return obj; };
  180   
  181           /**
  182            * Retrieves the attributes to be bound.
  183            * @return The possibly null attributes to be bound.
  184            */
  185           public Attributes getAttributes() { return attrs; };
  186   
  187       }
  188   }

Save This Page
Home » openjdk-7 » javax » naming » spi » [javadoc | source]