001 /*
002 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.naming.spi;
026
027 import javax.naming.*;
028 import java.util.Hashtable;
029
030 /**
031 * This interface represents a factory for obtaining the state of an
032 * object for binding.
033 *<p>
034 * The JNDI framework allows for object implementations to
035 * be loaded in dynamically via <em>object factories</em>.
036 * For example, when looking up a printer bound in the name space,
037 * if the print service binds printer names to <tt>Reference</tt>s, the printer
038 * <tt>Reference</tt> could be used to create a printer object, so that
039 * the caller of lookup can directly operate on the printer object
040 * after the lookup.
041 * <p>An <tt>ObjectFactory</tt> is responsible
042 * for creating objects of a specific type. In the above example,
043 * you may have a <tt>PrinterObjectFactory</tt> for creating
044 * <tt>Printer</tt> objects.
045 * <p>
046 * For the reverse process, when an object is bound into the namespace,
047 * JNDI provides <em>state factories</em>.
048 * Continuing with the printer example, suppose the printer object is
049 * updated and rebound:
050 * <blockquote><pre>
051 * ctx.rebind("inky", printer);
052 * </pre></blockquote>
053 * The service provider for <tt>ctx</tt> uses a state factory
054 * to obtain the state of <tt>printer</tt> for binding into its namespace.
055 * A state factory for the <tt>Printer</tt> type object might return
056 * a more compact object for storage in the naming system.
057 *<p>
058 * A state factory must implement the <tt>StateFactory</tt> interface.
059 * In addition, the factory class must be public and must have a
060 * public constructor that accepts no parameters.
061 *<p>
062 * The <tt>getStateToBind()</tt> method of a state factory may
063 * be invoked multiple times, possibly using different parameters.
064 * The implementation is thread-safe.
065 *<p>
066 * <tt>StateFactory</tt> is intended for use with service providers
067 * that implement only the <tt>Context</tt> interface.
068 * <tt>DirStateFactory</tt> is intended for use with service providers
069 * that implement the <tt>DirContext</tt> interface.
070 *
071 * @author Rosanna Lee
072 * @author Scott Seligman
073 * @version 1.17 07/05/05
074 *
075 * @see NamingManager#getStateToBind
076 * @see DirectoryManager#getStateToBind
077 * @see ObjectFactory
078 * @see DirStateFactory
079 * @since 1.3
080 */
081 public interface StateFactory {
082 /**
083 * Retrieves the state of an object for binding.
084 *<p>
085 * <tt>NamingManager.getStateToBind()</tt>
086 * successively loads in state factories and invokes this method
087 * on them until one produces a non-null answer.
088 * <tt>DirectoryManager.getStateToBind()</tt>
089 * successively loads in state factories. If a factory implements
090 * <tt>DirStateFactory</tt>, then <tt>DirectoryManager</tt>
091 * invokes <tt>DirStateFactory.getStateToBind()</tt>; otherwise
092 * it invokes <tt>StateFactory.getStateToBind()</tt>.
093 *<p> When an exception
094 * is thrown by a factory, the exception is passed on to the caller
095 * of <tt>NamingManager.getStateToBind()</tt> and
096 * <tt>DirectoryManager.getStateToBind()</tt>.
097 * The search for other factories
098 * that may produce a non-null answer is halted.
099 * A factory should only throw an exception if it is sure that
100 * it is the only intended factory and that no other factories
101 * should be tried.
102 * If this factory cannot create an object using the arguments supplied,
103 * it should return null.
104 * <p>
105 * The <code>name</code> and <code>nameCtx</code> parameters may
106 * optionally be used to specify the name of the object being created.
107 * See the description of "Name and Context Parameters" in
108 * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
109 * for details.
110 * If a factory uses <code>nameCtx</code> it should synchronize its use
111 * against concurrent access, since context implementations are not
112 * guaranteed to be thread-safe.
113 * <p>
114 * The <tt>name</tt> and <tt>environment</tt> parameters
115 * are owned by the caller.
116 * The implementation will not modify these objects or keep references
117 * to them, although it may keep references to clones or copies.
118 *
119 * @param obj A non-null object whose state is to be retrieved.
120 * @param name The name of this object relative to <code>nameCtx</code>,
121 * or null if no name is specified.
122 * @param nameCtx The context relative to which the <code>name</code>
123 * parameter is specified, or null if <code>name</code> is
124 * relative to the default initial context.
125 * @param environment The possibly null environment to
126 * be used in the creation of the object's state.
127 * @return The object's state for binding;
128 * null if the factory is not returning any changes.
129 * @exception NamingException if this factory encountered an exception
130 * while attempting to get the object's state, and no other factories are
131 * to be tried.
132 *
133 * @see NamingManager#getStateToBind
134 * @see DirectoryManager#getStateToBind
135 */
136 public Object getStateToBind(Object obj, Name name,
137 Context nameCtx, Hashtable<?, ?> environment)
138 throws NamingException;
139 }
|