001 /*
002 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.naming.spi;
027
028 import java.util.Hashtable;
029 import javax.naming.*;
030 import javax.naming.directory.Attributes;
031
032 /**
033 * This interface represents a factory for creating an object given
034 * an object and attributes about the object.
035 *<p>
036 * The JNDI framework allows for object implementations to
037 * be loaded in dynamically via <em>object factories</em>. See
038 * <tt>ObjectFactory</tt> for details.
039 * <p>
040 * A <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt> by allowing
041 * an <tt>Attributes</tt> instance
042 * to be supplied to the <tt>getObjectInstance()</tt> method.
043 * <tt>DirObjectFactory</tt> implementations are intended to be used by <tt>DirContext</tt>
044 * service providers. The service provider, in addition reading an
045 * object from the directory, might already have attributes that
046 * are useful for the object factory to check to see whether the
047 * factory is supposed to process the object. For instance, an LDAP-style
048 * service provider might have read the "objectclass" of the object.
049 * A CORBA object factory might be interested only in LDAP entries
050 * with "objectclass=corbaObject". By using the attributes supplied by
051 * the LDAP service provider, the CORBA object factory can quickly
052 * eliminate objects that it need not worry about, and non-CORBA object
053 * factories can quickly eliminate CORBA-related LDAP entries.
054 *
055 * @author Rosanna Lee
056 * @author Scott Seligman
057 * @version 1.18 07/05/05
058 *
059 * @see NamingManager#getObjectInstance
060 * @see DirectoryManager#getObjectInstance
061 * @see ObjectFactory
062 * @since 1.3
063 */
064
065 public interface DirObjectFactory extends ObjectFactory {
066 /**
067 * Creates an object using the location or reference information, and attributes
068 * specified.
069 * <p>
070 * Special requirements of this object are supplied
071 * using <code>environment</code>.
072 * An example of such an environment property is user identity
073 * information.
074 *<p>
075 * <tt>DirectoryManager.getObjectInstance()</tt>
076 * successively loads in object factories. If it encounters a <tt>DirObjectFactory</tt>,
077 * it will invoke <tt>DirObjectFactory.getObjectInstance()</tt>;
078 * otherwise, it invokes
079 * <tt>ObjectFactory.getObjectInstance()</tt>. It does this until a factory
080 * produces a non-null answer.
081 * <p> When an exception
082 * is thrown by an object factory, the exception is passed on to the caller
083 * of <tt>DirectoryManager.getObjectInstance()</tt>. The search for other factories
084 * that may produce a non-null answer is halted.
085 * An object factory should only throw an exception if it is sure that
086 * it is the only intended factory and that no other object factories
087 * should be tried.
088 * If this factory cannot create an object using the arguments supplied,
089 * it should return null.
090 *<p>Since <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt>, it
091 * effectively
092 * has two <tt>getObjectInstance()</tt> methods, where one differs from the other by
093 * the attributes argument. Given a factory that implements <tt>DirObjectFactory</tt>,
094 * <tt>DirectoryManager.getObjectInstance()</tt> will only
095 * use the method that accepts the attributes argument, while
096 * <tt>NamingManager.getObjectInstance()</tt> will only use the one that does not accept
097 * the attributes argument.
098 *<p>
099 * See <tt>ObjectFactory</tt> for a description URL context factories and other
100 * properties of object factories that apply equally to <tt>DirObjectFactory</tt>.
101 *<p>
102 * The <tt>name</tt>, <tt>attrs</tt>, and <tt>environment</tt> parameters
103 * are owned by the caller.
104 * The implementation will not modify these objects or keep references
105 * to them, although it may keep references to clones or copies.
106 *
107 * @param obj The possibly null object containing location or reference
108 * information that can be used in creating an object.
109 * @param name The name of this object relative to <code>nameCtx</code>,
110 * or null if no name is specified.
111 * @param nameCtx The context relative to which the <code>name</code>
112 * parameter is specified, or null if <code>name</code> is
113 * relative to the default initial context.
114 * @param environment The possibly null environment that is used in
115 * creating the object.
116 * @param attrs The possibly null attributes containing some of <tt>obj</tt>'s
117 * attributes. <tt>attrs</tt> might not necessarily have all of <tt>obj</tt>'s
118 * attributes. If the object factory requires more attributes, it needs
119 * to get it, either using <tt>obj</tt>, or <tt>name</tt> and <tt>nameCtx</tt>.
120 * The factory must not modify attrs.
121 * @return The object created; null if an object cannot be created.
122 * @exception Exception If this object factory encountered an exception
123 * while attempting to create an object, and no other object factories are
124 * to be tried.
125 *
126 * @see DirectoryManager#getObjectInstance
127 * @see NamingManager#getURLContext
128 */
129 public Object getObjectInstance(Object obj, Name name,
130 Context nameCtx, Hashtable<?, ?> environment,
131 Attributes attrs) throws Exception;
132 }
|