alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (DirObjectFactory.java)

This example Java source code file (DirObjectFactory.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

attributes, context, dirobjectfactory, exception, hashtable, name, naming, objectfactory, util

The DirObjectFactory.java Java example source code

/*
 * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package javax.naming.spi;

import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.Attributes;

/**
  * This interface represents a factory for creating an object given
  * an object and attributes about the object.
  *<p>
  * The JNDI framework allows for object implementations to
  * be loaded in dynamically via <em>object factories. See
  * <tt>ObjectFactory for details.
  * <p>
  * A <tt>DirObjectFactory extends ObjectFactory by allowing
  * an <tt>Attributes instance
  * to be supplied to the <tt>getObjectInstance() method.
  * <tt>DirObjectFactory implementations are intended to be used by DirContext
  * service providers. The service provider, in addition reading an
  * object from the directory, might already have attributes that
  * are useful for the object factory to check to see whether the
  * factory is supposed to process the object. For instance, an LDAP-style
  * service provider might have read the "objectclass" of the object.
  * A CORBA object factory might be interested only in LDAP entries
  * with "objectclass=corbaObject". By using the attributes supplied by
  * the LDAP service provider, the CORBA object factory can quickly
  * eliminate objects that it need not worry about, and non-CORBA object
  * factories can quickly eliminate CORBA-related LDAP entries.
  *
  * @author Rosanna Lee
  * @author Scott Seligman
  *
  * @see NamingManager#getObjectInstance
  * @see DirectoryManager#getObjectInstance
  * @see ObjectFactory
  * @since 1.3
  */

public interface DirObjectFactory extends ObjectFactory {
/**
 * Creates an object using the location or reference information, and attributes
 * specified.
 * <p>
 * Special requirements of this object are supplied
 * using <code>environment.
 * An example of such an environment property is user identity
 * information.
 *<p>
 * <tt>DirectoryManager.getObjectInstance()
 * successively loads in object factories. If it encounters a <tt>DirObjectFactory,
 * it will invoke <tt>DirObjectFactory.getObjectInstance();
 * otherwise, it invokes
 * <tt>ObjectFactory.getObjectInstance(). It does this until a factory
 * produces a non-null answer.
 * <p> When an exception
 * is thrown by an object factory, the exception is passed on to the caller
 * of <tt>DirectoryManager.getObjectInstance(). The search for other factories
 * that may produce a non-null answer is halted.
 * An object factory should only throw an exception if it is sure that
 * it is the only intended factory and that no other object factories
 * should be tried.
 * If this factory cannot create an object using the arguments supplied,
 * it should return null.
  *<p>Since DirObjectFactory extends ObjectFactory, it
  * effectively
  * has two <tt>getObjectInstance() methods, where one differs from the other by
  * the attributes argument. Given a factory that implements <tt>DirObjectFactory,
  * <tt>DirectoryManager.getObjectInstance() will only
  * use the method that accepts the attributes argument, while
  * <tt>NamingManager.getObjectInstance() will only use the one that does not accept
  * the attributes argument.
 *<p>
 * See <tt>ObjectFactory for a description URL context factories and other
 * properties of object factories that apply equally to <tt>DirObjectFactory.
 *<p>
 * The <tt>name, attrs, and environment parameters
 * are owned by the caller.
 * The implementation will not modify these objects or keep references
 * to them, although it may keep references to clones or copies.
 *
 * @param obj The possibly null object containing location or reference
 *              information that can be used in creating an object.
 * @param name The name of this object relative to <code>nameCtx,
 *              or null if no name is specified.
 * @param nameCtx The context relative to which the <code>name
 *              parameter is specified, or null if <code>name is
 *              relative to the default initial context.
 * @param environment The possibly null environment that is used in
 *              creating the object.
 * @param attrs The possibly null attributes containing some of <tt>obj's
 * attributes. <tt>attrs might not necessarily have all of obj's
 * attributes. If the object factory requires more attributes, it needs
 * to get it, either using <tt>obj, or name and nameCtx.
 *      The factory must not modify attrs.
 * @return The object created; null if an object cannot be created.
 * @exception Exception If this object factory encountered an exception
 * while attempting to create an object, and no other object factories are
 * to be tried.
 *
 * @see DirectoryManager#getObjectInstance
 * @see NamingManager#getURLContext
 */
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                    Hashtable<?,?> environment,
                                    Attributes attrs)
        throws Exception;
}

Other Java examples (source code examples)

Here is a short list of links related to this Java DirObjectFactory.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.