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