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

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

There is a newer version: 3.3.9
Show newest version
/*
  $Id: CopyAttributeHandler.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.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;

/**
 * CopyAttributeHandler converts a NamingEnumeration of attribute
 * into a List of attribute.
 *
 * @author  Middleware Services
 * @version  $Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
 */
public class CopyAttributeHandler extends CopyResultHandler
  implements AttributeHandler
{


  /**
   * This will return a deep copy of the supplied Attribute.
   *
   * @param  sc  SearchCriteria used to find enumeration
   * @param  attr  Attribute to copy
   *
   * @return  Attribute
   *
   * @throws  NamingException  if the attribute values cannot be read
   */
  protected Attribute processResult(
    final SearchCriteria sc,
    final Attribute attr)
    throws NamingException
  {
    Attribute newAttr = null;
    if (attr != null) {
      newAttr = new BasicAttribute(attr.getID(), attr.isOrdered());

      final NamingEnumeration en = attr.getAll();
      while (en.hasMore()) {
        newAttr.add(this.processValue(sc, en.next()));
      }
    }
    return newAttr;
  }


  /**
   * This returns the supplied value unaltered.
   *
   * @param  sc  LdapSearchCritieria used to find enumeration
   * @param  value  Object to process
   *
   * @return  Object
   */
  protected Object processValue(final SearchCriteria sc, final Object value)
  {
    return value;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy