J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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 java.util.Hashtable; |
| 29 | |
| 30 | /** |
| 31 | * This interface represents a factory for obtaining the state of an |
| 32 | * object for binding. |
| 33 | *<p> |
| 34 | * The JNDI framework allows for object implementations to |
| 35 | * be loaded in dynamically via <em>object factories</em>. |
| 36 | * For example, when looking up a printer bound in the name space, |
| 37 | * if the print service binds printer names to <tt>Reference</tt>s, the printer |
| 38 | * <tt>Reference</tt> could be used to create a printer object, so that |
| 39 | * the caller of lookup can directly operate on the printer object |
| 40 | * after the lookup. |
| 41 | * <p>An <tt>ObjectFactory</tt> is responsible |
| 42 | * for creating objects of a specific type. In the above example, |
| 43 | * you may have a <tt>PrinterObjectFactory</tt> for creating |
| 44 | * <tt>Printer</tt> objects. |
| 45 | * <p> |
| 46 | * For the reverse process, when an object is bound into the namespace, |
| 47 | * JNDI provides <em>state factories</em>. |
| 48 | * Continuing with the printer example, suppose the printer object is |
| 49 | * updated and rebound: |
| 50 | * <blockquote><pre> |
| 51 | * ctx.rebind("inky", printer); |
| 52 | * </pre></blockquote> |
| 53 | * The service provider for <tt>ctx</tt> uses a state factory |
| 54 | * to obtain the state of <tt>printer</tt> for binding into its namespace. |
| 55 | * A state factory for the <tt>Printer</tt> type object might return |
| 56 | * a more compact object for storage in the naming system. |
| 57 | *<p> |
| 58 | * A state factory must implement the <tt>StateFactory</tt> interface. |
| 59 | * In addition, the factory class must be public and must have a |
| 60 | * public constructor that accepts no parameters. |
| 61 | *<p> |
| 62 | * The <tt>getStateToBind()</tt> method of a state factory may |
| 63 | * be invoked multiple times, possibly using different parameters. |
| 64 | * The implementation is thread-safe. |
| 65 | *<p> |
| 66 | * <tt>StateFactory</tt> is intended for use with service providers |
| 67 | * that implement only the <tt>Context</tt> interface. |
| 68 | * <tt>DirStateFactory</tt> is intended for use with service providers |
| 69 | * that implement the <tt>DirContext</tt> interface. |
| 70 | * |
| 71 | * @author Rosanna Lee |
| 72 | * @author Scott Seligman |
| 73 | * |
| 74 | * @see NamingManager#getStateToBind |
| 75 | * @see DirectoryManager#getStateToBind |
| 76 | * @see ObjectFactory |
| 77 | * @see DirStateFactory |
| 78 | * @since 1.3 |
| 79 | */ |
| 80 | public interface StateFactory { |
| 81 | /** |
| 82 | * Retrieves the state of an object for binding. |
| 83 | *<p> |
| 84 | * <tt>NamingManager.getStateToBind()</tt> |
| 85 | * successively loads in state factories and invokes this method |
| 86 | * on them until one produces a non-null answer. |
| 87 | * <tt>DirectoryManager.getStateToBind()</tt> |
| 88 | * successively loads in state factories. If a factory implements |
| 89 | * <tt>DirStateFactory</tt>, then <tt>DirectoryManager</tt> |
| 90 | * invokes <tt>DirStateFactory.getStateToBind()</tt>; otherwise |
| 91 | * it invokes <tt>StateFactory.getStateToBind()</tt>. |
| 92 | *<p> When an exception |
| 93 | * is thrown by a factory, the exception is passed on to the caller |
| 94 | * of <tt>NamingManager.getStateToBind()</tt> and |
| 95 | * <tt>DirectoryManager.getStateToBind()</tt>. |
| 96 | * 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> 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 | * |
| 118 | * @param obj A non-null object whose state is to be retrieved. |
| 119 | * @param name The name of this object relative to <code>nameCtx</code>, |
| 120 | * or null if no name is specified. |
| 121 | * @param nameCtx The context relative to which the <code>name</code> |
| 122 | * parameter is specified, or null if <code>name</code> is |
| 123 | * relative to the default initial context. |
| 124 | * @param environment The possibly null environment to |
| 125 | * be used in the creation of the object's state. |
| 126 | * @return The object's state for binding; |
| 127 | * null if the factory is not returning any changes. |
| 128 | * @exception NamingException if this factory encountered an exception |
| 129 | * while attempting to get the object's state, and no other factories are |
| 130 | * to be tried. |
| 131 | * |
| 132 | * @see NamingManager#getStateToBind |
| 133 | * @see DirectoryManager#getStateToBind |
| 134 | */ |
| 135 | public Object getStateToBind(Object obj, Name name, Context nameCtx, |
| 136 | Hashtable<?,?> environment) |
| 137 | throws NamingException; |
| 138 | } |