1. /*
  2. * @(#)DirStateFactory.java 1.6 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 javax.naming.directory.Attributes;
  13. import java.util.Hashtable;
  14. /**
  15. * This interface represents a factory for obtaining the state of an
  16. * object and corresponding attributes for binding.
  17. *<p>
  18. * The JNDI framework allows for object implementations to
  19. * be loaded in dynamically via <tt>object factories</tt>.
  20. * <p>
  21. * A <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>
  22. * by allowing an <tt>Attributes</tt> instance
  23. * to be supplied to and be returned by the <tt>getStateToBind()</tt> method.
  24. * <tt>DirStateFactory</tt> implementations are intended to be used by
  25. * <tt>DirContext</tt> service providers.
  26. * When a caller binds an object using <tt>DirContext.bind()</tt>,
  27. * he might also specify a set of attributes to be bound with the object.
  28. * The object and attributes to be bound are passed to
  29. * the <tt>getStateToBind()</tt> method of a factory.
  30. * If the factory processes the object and attributes, it returns
  31. * a corresponding pair of object and attributes to be bound.
  32. * If the factory does not process the object, it must return null.
  33. *<p>
  34. * For example, a caller might bind a printer object with some printer-related
  35. * attributes.
  36. *<blockquote><pre>
  37. * ctx.rebind("inky", printer, printerAttrs);
  38. *</pre></blockquote>
  39. * An LDAP service provider for <tt>ctx</tt> uses a <tt>DirStateFactory</tt>
  40. * (indirectly via <tt>DirectoryManager.getStateToBind()</tt>)
  41. * and gives it <tt>printer</tt> and <tt>printerAttrs</tt>. A factory for
  42. * an LDAP directory might turn <tt>printer</tt> into a set of attributes
  43. * and merge that with <tt>printerAttrs</tt>. The service provider then
  44. * uses the resulting attributes to create an LDAP entry and updates
  45. * the directory.
  46. *
  47. * <p> Since <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>, it
  48. * has two <tt>getStateToBind()</tt> methods, where one
  49. * differs from the other by the attributes
  50. * argument. <tt>DirectoryManager.getStateToBind()</tt> will only use
  51. * the form that accepts the attributes argument, while
  52. * <tt>NamingManager.getStateToBind()</tt> will only use the form that
  53. * does not accept the attributes argument.
  54. *
  55. * <p> Either form of the <tt>getStateToBind()</tt> method of a
  56. * DirStateFactory may be invoked multiple times, possibly using different
  57. * parameters. The implementation is thread-safe.
  58. *
  59. * @author Rosanna Lee
  60. * @author Scott Seligman
  61. * @version 1.6 00/02/02
  62. *
  63. * @see DirectoryManager#getStateToBind
  64. * @see DirObjectFactory
  65. * @since 1.3
  66. */
  67. public interface DirStateFactory extends StateFactory {
  68. /**
  69. * Retrieves the state of an object for binding given the object and attributes
  70. * to be transformed.
  71. *<p>
  72. * <tt>DirectoryManager.getStateToBind()</tt>
  73. * successively loads in state factories. If a factory implements
  74. * <tt>DirStateFactory</tt>, <tt>DirectoryManager</tt> invokes this method;
  75. * otherwise, it invokes <tt>StateFactory.getStateToBind()</tt>.
  76. * It does this until a factory produces a non-null answer.
  77. *<p>
  78. * When an exception is thrown by a factory,
  79. * the exception is passed on to the caller
  80. * of <tt>DirectoryManager.getStateToBind()</tt>. 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>, <tt>inAttrs</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. * The object returned by this method is owned by the caller.
  102. * The implementation will not subsequently modify it.
  103. * It will contain either a new <tt>Attributes</tt> object that is
  104. * likewise owned by the caller, or a reference to the original
  105. * <tt>inAttrs</tt> parameter.
  106. *
  107. * @param obj A possibly null object whose state is to be retrieved.
  108. * @param name The name of this object relative to <code>nameCtx</code>,
  109. * or null if no name is specified.
  110. * @param nameCtx The context relative to which the <code>name</code>
  111. * parameter is specified, or null if <code>name</code> is
  112. * relative to the default initial context.
  113. * @param environment The possibly null environment to
  114. * be used in the creation of the object's state.
  115. * @param inAttrs The possibly null attributes to be bound with the object.
  116. * The factory must not modify <tt>inAttrs</tt>.
  117. * @return A <tt>Result</tt> containing the object's state for binding
  118. * and the corresponding
  119. * attributes to be bound; null if the object don't use this factory.
  120. * @exception NamingException If this factory encountered an exception
  121. * while attempting to get the object's state, and no other factories are
  122. * to be tried.
  123. *
  124. * @see DirectoryManager#getStateToBind
  125. */
  126. public Result getStateToBind(Object obj, Name name, Context nameCtx,
  127. Hashtable environment, Attributes inAttrs)
  128. throws NamingException;
  129. /**
  130. * An object/attributes pair for returning the result of
  131. * DirStateFactory.getStateToBind().
  132. */
  133. public static class Result {
  134. /**
  135. * The possibly null object to be bound.
  136. */
  137. private Object obj;
  138. /**
  139. * The possibly null attributes to be bound.
  140. */
  141. private Attributes attrs;
  142. /**
  143. * Constructs an instance of Result.
  144. *
  145. * @param obj The possibly null object to be bound.
  146. * @param outAttrs The possibly null attributes to be bound.
  147. */
  148. public Result(Object obj, Attributes outAttrs) {
  149. this.obj = obj;
  150. this.attrs = outAttrs;
  151. }
  152. /**
  153. * Retrieves the object to be bound.
  154. * @return The possibly null object to be bound.
  155. */
  156. public Object getObject() { return obj; };
  157. /**
  158. * Retrieves the attributes to be bound.
  159. * @return The possibly null attributes to be bound.
  160. */
  161. public Attributes getAttributes() { return attrs; };
  162. }
  163. }