edu.vt.middleware.ldap.handler.AbstractResultHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vt-ldap Show documentation
Show all versions of vt-ldap Show documentation
Library for performing common LDAP operations
/*
$Id: AbstractResultHandler.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 java.util.ArrayList;
import java.util.List;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* AbstractResultHandler
implements common handler functionality.
*
* @param type of result
* @param type of output
*
* @author Middleware Services
* @version $Revision: 1330 $ $Date: 2010-05-23 18:10:53 -0400 (Sun, 23 May 2010) $
*/
public abstract class AbstractResultHandler implements ResultHandler
{
/** Log for this class. */
protected final Log logger = LogFactory.getLog(this.getClass());
/**
* This will enumerate through the supplied NamingEnumeration
and
* return a List of those results. The results are unaltered and the dn is
* ignored.
*
* @param sc SearchCriteria
used to find enumeration
* @param en NamingEnumeration
LDAP results
*
* @return List
- LDAP results
*
* @throws NamingException if the LDAP returns an error
*/
public List process(
final SearchCriteria sc,
final NamingEnumeration extends R> en)
throws NamingException
{
return this.process(sc, en, null);
}
/**
* This will enumerate through the supplied NamingEnumeration
and
* return a List of those results. The results are unaltered and the dn is
* ignored. 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 enumeration
* @param en NamingEnumeration
LDAP results
* @param ignore Class[]
of exception types to ignore
*
* @return List
- LDAP results
*
* @throws NamingException if the LDAP returns an error
*/
public List process(
final SearchCriteria sc,
final NamingEnumeration extends R> en,
final Class>[] ignore)
throws NamingException
{
final List results = new ArrayList();
if (en != null) {
try {
while (en.hasMore()) {
final O o = processResult(sc, en.next());
if (o != null) {
results.add(o);
}
}
} catch (NamingException e) {
boolean ignoreException = false;
if (ignore != null && ignore.length > 0) {
for (Class> ne : ignore) {
if (ne.isInstance(e)) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Ignoring naming exception", e);
}
ignoreException = true;
break;
}
}
}
if (!ignoreException) {
throw e;
}
}
}
return results;
}
/**
* This will enumerate through the supplied List
and return a
* List of those results. The results are unaltered and the dn is ignored.
*
* @param sc SearchCriteria
used to find enumeration
* @param l List
LDAP results
*
* @return List
- LDAP results
*
* @throws NamingException if the LDAP returns an error
*/
public List process(final SearchCriteria sc, final List extends R> l)
throws NamingException
{
final List results = new ArrayList();
if (l != null) {
for (R r : l) {
final O o = processResult(sc, r);
if (o != null) {
results.add(o);
}
}
}
return results;
}
/**
* Processes the supplied result.
*
* @param sc SearchCriteria
used to retrieve the result
* @param r R
result to process
*
* @return O
processed result
*
* @throws NamingException if the supplied result cannot be read
*/
protected abstract O processResult(final SearchCriteria sc, final R r)
throws NamingException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy