1. /*
  2. * @(#)StateFactory.java 1.5 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming.spi;
  11. import javax.naming.*;
  12. import java.util.Hashtable;
  13. /**
  14. * This interface represents a factory for obtaining the state of an
  15. * object for binding.
  16. *<p>
  17. * The JNDI framework allows for object implementations to
  18. * be loaded in dynamically via <em>object factories</em>.
  19. * For example, when looking up a printer bound in the name space,
  20. * if the print service binds printer names to <tt>Reference</tt>s, the printer
  21. * <tt>Reference</tt> could be used to create a printer object, so that
  22. * the caller of lookup can directly operate on the printer object
  23. * after the lookup.
  24. * <p>An <tt>ObjectFactory</tt> is responsible
  25. * for creating objects of a specific type. In the above example,
  26. * you may have a <tt>PrinterObjectFactory</tt> for creating
  27. * <tt>Printer</tt> objects.
  28. * <p>
  29. * For the reverse process, when an object is bound into the namespace,
  30. * JNDI provides <em>state factories</em>.
  31. * Continuing with the printer example, suppose the printer object is
  32. * updated and rebound:
  33. * <blockquote><pre>
  34. * ctx.rebind("inky", printer);
  35. * </pre></blockquote>
  36. * The service provider for <tt>ctx</tt> uses a state factory
  37. * to obtain the state of <tt>printer</tt> for binding into its namespace.
  38. * A state factory for the <tt>Printer</tt> type object might return
  39. * a more compact object for storage in the naming system.
  40. *<p>
  41. * A state factory must implement the <tt>StateFactory</tt> interface.
  42. * In addition, the factory class must be public and must have a
  43. * public constructor that accepts no parameters.
  44. *<p>
  45. * The <tt>getStateToBind()</tt> method of a state factory may
  46. * be invoked multiple times, possibly using different parameters.
  47. * The implementation is thread-safe.
  48. *<p>
  49. * <tt>StateFactory</tt> is intended for use with service providers
  50. * that implement only the <tt>Context</tt> interface.
  51. * <tt>DirStateFactory</tt> is intended for use with service providers
  52. * that implement the <tt>DirContext</tt> interface.
  53. *
  54. * @author Rosanna Lee
  55. * @author Scott Seligman
  56. * @version 1.5 00/02/02
  57. *
  58. * @see NamingManager#getStateToBind
  59. * @see DirectoryManager#getStateToBind
  60. * @see ObjectFactory
  61. * @see DirStateFactory
  62. * @since 1.3
  63. */
  64. public interface StateFactory {
  65. /**
  66. * Retrieves the state of an object for binding.
  67. *<p>
  68. * <tt>NamingManager.getStateToBind()</tt>
  69. * successively loads in state factories and invokes this method
  70. * on them until one produces a non-null answer.
  71. * <tt>DirectoryManager.getStateToBind()</tt>
  72. * successively loads in state factories. If a factory implements
  73. * <tt>DirStateFactory</tt>, then <tt>DirectoryManager</tt>
  74. * invokes <tt>DirStateFactory.getStateToBind()</tt> otherwise
  75. * it invokes <tt>StateFactory.getStateToBind()</tt>.
  76. *<p> When an exception
  77. * is thrown by a factory, the exception is passed on to the caller
  78. * of <tt>NamingManager.getStateToBind()</tt> and
  79. * <tt>DirectoryManager.getStateToBind()</tt>.
  80. * The search for other factories
  81. * that may produce a non-null answer is halted.
  82. * A factory should only throw an exception if it is sure that
  83. * it is the only intended factory and that no other factories
  84. * should be tried.
  85. * If this factory cannot create an object using the arguments supplied,
  86. * it should return null.
  87. * <p>
  88. * The <code>name</code> and <code>nameCtx</code> parameters may
  89. * optionally be used to specify the name of the object being created.
  90. * See the description of "Name and Context Parameters" in
  91. * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
  92. * for details.
  93. * If a factory uses <code>nameCtx</code> it should synchronize its use
  94. * against concurrent access, since context implementations are not
  95. * guaranteed to be thread-safe.
  96. * <p>
  97. * The <tt>name</tt> and <tt>environment</tt> parameters
  98. * are owned by the caller.
  99. * The implementation will not modify these objects or keep references
  100. * to them, although it may keep references to clones or copies.
  101. *
  102. * @param obj A non-null object whose state is to be retrieved.
  103. * @param name The name of this object relative to <code>nameCtx</code>,
  104. * or null if no name is specified.
  105. * @param nameCtx The context relative to which the <code>name</code>
  106. * parameter is specified, or null if <code>name</code> is
  107. * relative to the default initial context.
  108. * @param environment The possibly null environment to
  109. * be used in the creation of the object's state.
  110. * @return The object's state for binding;
  111. * null if the factory is not returning any changes.
  112. * @exception NamingException if this factory encountered an exception
  113. * while attempting to get the object's state, and no other factories are
  114. * to be tried.
  115. *
  116. * @see NamingManager#getStateToBind
  117. * @see DirectoryManager#getStateToBind
  118. */
  119. public Object getStateToBind(Object obj, Name name, Context nameCtx,
  120. Hashtable environment)
  121. throws NamingException;
  122. }