From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- source/com/c2kernel/lookup/LDAPPathSet.java | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 source/com/c2kernel/lookup/LDAPPathSet.java (limited to 'source/com/c2kernel/lookup/LDAPPathSet.java') diff --git a/source/com/c2kernel/lookup/LDAPPathSet.java b/source/com/c2kernel/lookup/LDAPPathSet.java new file mode 100755 index 0000000..9c68c5c --- /dev/null +++ b/source/com/c2kernel/lookup/LDAPPathSet.java @@ -0,0 +1,70 @@ +package com.c2kernel.lookup; + +import java.util.Enumeration; + +import com.c2kernel.process.Gateway; +import com.c2kernel.utils.Logger; +import com.novell.ldap.LDAPEntry; +import com.novell.ldap.LDAPException; +import com.novell.ldap.LDAPSearchResults; + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 2005/12/01 14:23:14 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + + + +public class LDAPPathSet implements Enumeration { + LDAPSearchResults results; + LDAPEntry nextEntry; + + public LDAPPathSet() { // empty + results = null; + } + + public LDAPPathSet(LDAPSearchResults results) { + this.results = results; + } + + public boolean hasMoreElements() { + if (results == null) return false; + if (nextEntry != null) return true; + if (results.hasMore()) + try { + nextEntry = results.next(); + return true; + } catch (LDAPException ex) { + if (ex.getResultCode()!=32) {// no results + Logger.error(ex); + Logger.error("Error loading LDAP result set: "+ex.getMessage()); + } + } + return false; + } + + public Object nextElement() { + if (results == null) return null; + try { + if (nextEntry == null) + nextEntry = results.next(); + Path nextPath = Gateway.getLDAPLookup().nodeToPath(nextEntry); + nextEntry = null; + return nextPath; + } catch (Exception ex) { + Logger.error("Error loading next path"); + Logger.error(ex); + nextEntry = null; + if (hasMoreElements()) { + Logger.error("Skipping to next entry"); + return nextElement(); + } + else + return null; + } + } +} -- cgit v1.2.3