diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-02-22 14:04:33 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-03-18 14:03:54 +0100 |
| commit | 6e35118970c7af70eb0ac938859d794f7348d367 (patch) | |
| tree | c85299f5a174a04c9df2847c1f469ff427dd6f64 /src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java | |
| parent | d6cfc7505be13b3b09adf423206cf75d9f806c12 (diff) | |
Extracted LDAP specifics into subpackage
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java new file mode 100644 index 0000000..ffd8010 --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java @@ -0,0 +1,78 @@ +package com.c2kernel.lookup.ldap;
+
+import java.util.Iterator;
+
+import com.c2kernel.lookup.Path;
+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 Iterator<Path> {
+ LDAPSearchResults results;
+ LDAPEntry nextEntry;
+
+ public LDAPPathSet() { // empty
+ results = null;
+ }
+
+ public LDAPPathSet(LDAPSearchResults results) {
+ this.results = results;
+ }
+
+ @Override
+ public boolean hasNext() {
+ 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;
+ }
+
+ @Override
+ public Path next() {
+ if (results == null) return null;
+ try {
+ if (nextEntry == null)
+ nextEntry = results.next();
+ Path nextPath = ((LDAPLookup)Gateway.getLookup()).nodeToPath(nextEntry);
+ nextEntry = null;
+ return nextPath;
+ } catch (Exception ex) {
+ Logger.error("Error loading next path");
+ Logger.error(ex);
+ nextEntry = null;
+ if (hasNext()) {
+ Logger.error("Skipping to next entry");
+ return next();
+ }
+ else
+ return null;
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new RuntimeException("Not implemented");
+ }
+}
|
