1. /*
  2. * @(#)DirObjectFactory.java 1.11 04/07/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.naming.spi;
  8. import java.util.Hashtable;
  9. import javax.naming.*;
  10. import javax.naming.directory.Attributes;
  11. /**
  12. * This interface represents a factory for creating an object given
  13. * an object and attributes about the object.
  14. *<p>
  15. * The JNDI framework allows for object implementations to
  16. * be loaded in dynamically via <em>object factories</em>. See
  17. * <tt>ObjectFactory</tt> for details.
  18. * <p>
  19. * A <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt> by allowing
  20. * an <tt>Attributes</tt> instance
  21. * to be supplied to the <tt>getObjectInstance()</tt> method.
  22. * <tt>DirObjectFactory</tt> implementations are intended to be used by <tt>DirContext</tt>
  23. * service providers. The service provider, in addition reading an
  24. * object from the directory, might already have attributes that
  25. * are useful for the object factory to check to see whether the
  26. * factory is supposed to process the object. For instance, an LDAP-style
  27. * service provider might have read the "objectclass" of the object.
  28. * A CORBA object factory might be interested only in LDAP entries
  29. * with "objectclass=corbaObject". By using the attributes supplied by
  30. * the LDAP service provider, the CORBA object factory can quickly
  31. * eliminate objects that it need not worry about, and non-CORBA object
  32. * factories can quickly eliminate CORBA-related LDAP entries.
  33. *
  34. * @author Rosanna Lee
  35. * @author Scott Seligman
  36. * @version 1.11 04/07/16
  37. *
  38. * @see NamingManager#getObjectInstance
  39. * @see DirectoryManager#getObjectInstance
  40. * @see ObjectFactory
  41. * @since 1.3
  42. */
  43. public interface DirObjectFactory extends ObjectFactory {
  44. /**
  45. * Creates an object using the location or reference information, and attributes
  46. * specified.
  47. * <p>
  48. * Special requirements of this object are supplied
  49. * using <code>environment</code>.
  50. * An example of such an environment property is user identity
  51. * information.
  52. *<p>
  53. * <tt>DirectoryManager.getObjectInstance()</tt>
  54. * successively loads in object factories. If it encounters a <tt>DirObjectFactory</tt>,
  55. * it will invoke <tt>DirObjectFactory.getObjectInstance()</tt>
  56. * otherwise, it invokes
  57. * <tt>ObjectFactory.getObjectInstance()</tt>. It does this until a factory
  58. * produces a non-null answer.
  59. * <p> When an exception
  60. * is thrown by an object factory, the exception is passed on to the caller
  61. * of <tt>DirectoryManager.getObjectInstance()</tt>. The search for other factories
  62. * that may produce a non-null answer is halted.
  63. * An object factory should only throw an exception if it is sure that
  64. * it is the only intended factory and that no other object factories
  65. * should be tried.
  66. * If this factory cannot create an object using the arguments supplied,
  67. * it should return null.
  68. *<p>Since <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt>, it
  69. * effectively
  70. * has two <tt>getObjectInstance()</tt> methods, where one differs from the other by
  71. * the attributes argument. Given a factory that implements <tt>DirObjectFactory</tt>,
  72. * <tt>DirectoryManager.getObjectInstance()</tt> will only
  73. * use the method that accepts the attributes argument, while
  74. * <tt>NamingManager.getObjectInstance()</tt> will only use the one that does not accept
  75. * the attributes argument.
  76. *<p>
  77. * See <tt>ObjectFactory</tt> for a description URL context factories and other
  78. * properties of object factories that apply equally to <tt>DirObjectFactory</tt>.
  79. *<p>
  80. * The <tt>name</tt>, <tt>attrs</tt>, and <tt>environment</tt> parameters
  81. * are owned by the caller.
  82. * The implementation will not modify these objects or keep references
  83. * to them, although it may keep references to clones or copies.
  84. *
  85. * @param obj The possibly null object containing location or reference
  86. * information that can be used in creating an object.
  87. * @param name The name of this object relative to <code>nameCtx</code>,
  88. * or null if no name is specified.
  89. * @param nameCtx The context relative to which the <code>name</code>
  90. * parameter is specified, or null if <code>name</code> is
  91. * relative to the default initial context.
  92. * @param environment The possibly null environment that is used in
  93. * creating the object.
  94. * @param attrs The possibly null attributes containing some of <tt>obj</tt>'s
  95. * attributes. <tt>attrs</tt> might not necessarily have all of <tt>obj</tt>'s
  96. * attributes. If the object factory requires more attributes, it needs
  97. * to get it, either using <tt>obj</tt>, or <tt>name</tt> and <tt>nameCtx</tt>.
  98. * The factory must not modify attrs.
  99. * @return The object created; null if an object cannot be created.
  100. * @exception Exception If this object factory encountered an exception
  101. * while attempting to create an object, and no other object factories are
  102. * to be tried.
  103. *
  104. * @see DirectoryManager#getObjectInstance
  105. * @see NamingManager#getURLContext
  106. */
  107. public Object getObjectInstance(Object obj, Name name, Context nameCtx,
  108. Hashtable<?,?> environment,
  109. Attributes attrs)
  110. throws Exception;
  111. }