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

edu.vt.middleware.ldap.handler.AttributesProcessor Maven / Gradle / Ivy

There is a newer version: 3.3.9
Show newest version
/*
  $Id: AttributesProcessor.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.handler;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;

/**
 * AttributesProcessor provides methods to help with the processing
 * of Attributes objects using an AttributeHandler.
 *
 * @author  Middleware Services
 * @version  $Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
 */
public final class AttributesProcessor
{


  /** Default constructor. */
  private AttributesProcessor() {}


  /**
   * Process the attributes of an ldap search search.
   *
   * @param  sc  SearchCriteria used to find search result
   * @param  attrs  Attributes to pass to the handler
   * @param  handler  AttributeHandler to process attributes
   *
   * @return  Attributes handler processed attributes
   *
   * @throws  NamingException  if the LDAP returns an error
   */
  public static Attributes executeHandler(
    final SearchCriteria sc,
    final Attributes attrs,
    final AttributeHandler handler)
    throws NamingException
  {
    return executeHandler(sc, attrs, handler, null);
  }


  /**
   * Process the attributes of an ldap search search. Any exceptions passed into
   * this method will be ignored and results will be returned as if no exception
   * occurred.
   *
   * @param  sc  SearchCriteria used to find search result
   * @param  attrs  Attributes to pass to the handler
   * @param  handler  AttributeHandler to process attributes
   * @param  ignore  Class[] of exception types to ignore
   *
   * @return  Attributes handler processed attributes
   *
   * @throws  NamingException  if the LDAP returns an error
   */
  public static Attributes executeHandler(
    final SearchCriteria sc,
    final Attributes attrs,
    final AttributeHandler handler,
    final Class[] ignore)
    throws NamingException
  {
    Attributes newAttrs = null;
    if (handler != null) {
      newAttrs = new BasicAttributes(attrs.isCaseIgnored());
      for (Attribute attr : handler.process(sc, attrs.getAll(), ignore)) {
        newAttrs.put(attr);
      }
    } else {
      newAttrs = attrs;
    }
    return newAttrs;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy