A strong start, thanks.  Keep it up.  A few issues:
- Some is stale
  - LdapConnection.bind(...) returning a BindResult, which is no longer
does
  - LdapConnection.search(...) no longer returns a SearchCursor, but an
EntryCursor
- I wanted to see a inclusion of getting repeating attribute values.
- Modifying entries (and following) is absent.

Otherwise, a nice start.  If you need a hand I might be able to write up
a bit.

FWIW, I've found some issues with the EntryCursor... it's throwing
Exception, which it should not be doing.  I've made a modified class
(attached) which wraps and only throws LdapException.  Only throwing one
exception (and not a high level Exception) is a better way.

A great (great) project.


Andy

package ca.benow.security.ldap;

import java.util.Iterator;

import org.apache.directory.shared.ldap.model.cursor.ClosureMonitor;
import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
import org.apache.directory.shared.ldap.model.entry.Entry;
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.message.SearchResultDone;

/**
 * Fix to entry cursor removing blanket exception throwing
 * @author andy
 *
 */
class QuietEntryCursor implements EntryCursor {

	private final EntryCursor wrapped;

	public QuietEntryCursor(EntryCursor search) {
		this.wrapped = search;
	}

	@Override
	public void after(Entry arg0) throws LdapException {
		try {
			wrapped.after(arg0);
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public void afterLast() throws LdapException {
		try {
			wrapped.afterLast();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean available() {
		return wrapped.available();
	}

	@Override
	public void before(Entry arg0) throws LdapException {
		try {
			wrapped.before(arg0);
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public void beforeFirst() throws LdapException {
		try {
			wrapped.beforeFirst();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public void close() throws LdapException {
		try {
			wrapped.close();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public void close(Exception arg0) throws LdapException {
		try {
			wrapped.close(arg0);
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean first() throws LdapException {
		try {
			return wrapped.first();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public Entry get() throws LdapException {
		try {
			return wrapped.get();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean isAfterLast() throws LdapException {
		try {
			return wrapped.isAfterLast();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean isBeforeFirst() throws LdapException {
		try {
			return wrapped.isBeforeFirst();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean isClosed() throws LdapException {
		try {
			return wrapped.isClosed();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean isFirst() throws LdapException {
		try {
			return wrapped.isFirst();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean isLast() throws LdapException {
		try {
			return wrapped.isLast();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean last() throws LdapException {
		try {
			return wrapped.last();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean next() throws LdapException {
		try {
			return wrapped.next();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public boolean previous() throws LdapException {
		try {
			return wrapped.previous();
		} catch (LdapException e) {
			throw e;
		} catch (Exception e) {
			throw new LdapException("error", e);
		}
	}

	@Override
	public void setClosureMonitor(ClosureMonitor arg0) {
		wrapped.setClosureMonitor(arg0);
	}

	@Override
	public Iterator<Entry> iterator() {
		return wrapped.iterator();
	}

	@Override
	public int getMessageId() {
		return wrapped.getMessageId();
	}

	@Override
	public SearchResultDone getSearchResultDone() {
		return wrapped.getSearchResultDone();
	}

}

Reply via email to