< prev index next >

src/java.naming/share/classes/javax/naming/spi/StateFactory.java

Print this page




  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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


  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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 {@code Reference}s, the printer
  38   * {@code Reference} 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 {@code ObjectFactory} is responsible
  42   * for creating objects of a specific type.  In the above example,
  43   * you may have a {@code PrinterObjectFactory} for creating
  44   * {@code Printer} 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 {@code ctx} uses a state factory
  54   * to obtain the state of {@code printer} for binding into its namespace.
  55   * A state factory for the {@code Printer} type object might return
  56   * a more compact object for storage in the naming system.
  57   *<p>
  58   * A state factory must implement the {@code StateFactory} 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 {@code getStateToBind()} method of a state factory may
  63   * be invoked multiple times, possibly using different parameters.
  64   * The implementation is thread-safe.
  65   *<p>
  66   * {@code StateFactory} is intended for use with service providers
  67   * that implement only the {@code Context} interface.
  68   * {@code DirStateFactory} is intended for use with service providers
  69   * that implement the {@code DirContext} 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  * {@code NamingManager.getStateToBind()}
  85  * successively loads in state factories and invokes this method
  86  * on them until one produces a non-null answer.
  87  * {@code DirectoryManager.getStateToBind()}
  88  * successively loads in state factories.  If a factory implements
  89  * {@code DirStateFactory}, then {@code DirectoryManager}
  90  * invokes {@code DirStateFactory.getStateToBind()}; otherwise
  91  * it invokes {@code StateFactory.getStateToBind()}.
  92  *<p> When an exception
  93  * is thrown by a factory, the exception is passed on to the caller
  94  * of {@code NamingManager.getStateToBind()} and
  95  * {@code DirectoryManager.getStateToBind()}.
  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 {@code name} and {@code environment} 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
< prev index next >