diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
| commit | b086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch) | |
| tree | 8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /src/main/java/com/c2kernel/lookup/LDAPPathSet.java | |
| parent | 22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff) | |
Initial Maven Conversion
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LDAPPathSet.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/LDAPPathSet.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/LDAPPathSet.java new file mode 100644 index 0000000..d3cf7d9 --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/LDAPPathSet.java @@ -0,0 +1,72 @@ +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<Path> {
+ LDAPSearchResults results;
+ LDAPEntry nextEntry;
+
+ public LDAPPathSet() { // empty
+ results = null;
+ }
+
+ public LDAPPathSet(LDAPSearchResults results) {
+ this.results = results;
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public Path 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;
+ }
+ }
+}
|
