All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.vt.middleware.ldap.bean.LdapBeanProvider Maven / Gradle / Ivy

There is a newer version: 3.3.9
Show newest version
/*
  $Id: LdapBeanProvider.java 1330 2010-05-23 22:10:53Z dfisher $

  Copyright (C) 2003-2010 Virginia Tech.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware Services
  Email:   [email protected]
  Version: $Revision: 1330 $
  Updated: $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
*/
package edu.vt.middleware.ldap.bean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * LdapBeanProvider provides a single source for ldap bean types
 * and configuration.
 *
 * @author  Middleware Services
 * @version  $Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
 */
public final class LdapBeanProvider
{

  /** bean factory class name. */
  public static final String BEAN_FACTORY =
    "edu.vt.middleware.ldap.beanFactory";

  /** Log for this class. */
  private static final Log LOG = LogFactory.getLog(LdapBeanProvider.class);

  /** single instance of the ldap bean provider. */
  private static final LdapBeanProvider INSTANCE = new LdapBeanProvider();

  /** factory used to create ldap beans. */
  private static LdapBeanFactory beanFactory;


  /** Default constructor. */
  private LdapBeanProvider()
  {
    final String beanFactoryClass = System.getProperty(BEAN_FACTORY);
    if (beanFactoryClass != null) {
      try {
        beanFactory = (LdapBeanFactory) Class.forName(beanFactoryClass)
            .newInstance();
        if (LOG.isInfoEnabled()) {
          LOG.info("Set provider bean factory to " + beanFactoryClass);
        }
      } catch (ClassNotFoundException e) {
        if (LOG.isErrorEnabled()) {
          LOG.error("Error instantiating " + beanFactoryClass, e);
        }
      } catch (InstantiationException e) {
        if (LOG.isErrorEnabled()) {
          LOG.error("Error instantiating " + beanFactoryClass, e);
        }
      } catch (IllegalAccessException e) {
        if (LOG.isErrorEnabled()) {
          LOG.error("Error instantiating " + beanFactoryClass, e);
        }
      }
    } else {
      // set default ldap bean factory to unordered
      beanFactory = new UnorderedLdapBeanFactory();
    }
  }


  /**
   * Returns the instance of this LdapBeanProvider.
   *
   * @return  LdapBeanProvider
   */
  public static LdapBeanProvider getInstance()
  {
    return INSTANCE;
  }


  /**
   * Returns the factory for creating ldap beans.
   *
   * @return  LdapBeanFactory
   */
  public static LdapBeanFactory getLdapBeanFactory()
  {
    return beanFactory;
  }


  /**
   * Sets the factory for creating ldap beans.
   *
   * @param  lbf  LdapBeanFactory
   */
  public static void setLdapBeanFactory(final LdapBeanFactory lbf)
  {
    if (lbf != null) {
      beanFactory = lbf;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy