From 89d4b5f3d862c3697d7421233a969db05a9b641b Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Tue, 25 Feb 2014 13:18:25 +0000
Subject: [PATCH] Add methods to convert from/to server Entry class to/from SDK Entry class
---
opendj-server3x-adapter/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/opendj-server3x-adapter/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java b/opendj-server3x-adapter/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java
index 74effd1..847ddd8 100644
--- a/opendj-server3x-adapter/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java
+++ b/opendj-server3x-adapter/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java
@@ -41,6 +41,7 @@
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.ldap.ErrorResultException;
import org.forgerock.opendj.ldap.LinkedAttribute;
+import org.forgerock.opendj.ldap.LinkedHashMapEntry;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.controls.Control;
@@ -71,6 +72,28 @@
}
/**
+ * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Entry} to OpenDJ
+ * server {@link org.opends.server.types.Entry}.
+ *
+ * @param sdkEntry
+ * SDK entry to convert
+ * @return the converted entry
+ */
+ public static org.opends.server.types.Entry to(
+ final org.forgerock.opendj.ldap.Entry sdkEntry) {
+ if (sdkEntry != null) {
+ org.opends.server.types.Entry entry =
+ new org.opends.server.types.Entry(to(sdkEntry.getName()), null, null, null);
+ List<AttributeValue> duplicateValues = new ArrayList<AttributeValue>();
+ for (org.opends.server.types.Attribute attribute : toAttributes(sdkEntry.getAllAttributes())) {
+ entry.addAttribute(attribute, duplicateValues);
+ }
+ return entry;
+ }
+ return null;
+ }
+
+ /**
* Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.responses.SearchResultEntry} to OpenDJ
* server {@link org.opends.server.types.SearchResultEntry}.
*
@@ -494,6 +517,27 @@
}
/**
+ * Converts from OpenDJ server
+ * {@link org.opends.server.types.Entry} to OpenDJ LDAP SDK
+ * {@link org.forgerock.opendj.ldap.Entry}.
+ *
+ * @param srvResultEntry
+ * value to convert
+ * @return the converted value
+ */
+ public static org.forgerock.opendj.ldap.Entry from(
+ final org.opends.server.types.Entry srvResultEntry) {
+
+ final org.forgerock.opendj.ldap.Entry entry = new LinkedHashMapEntry(srvResultEntry.getName().toString());
+ if (srvResultEntry.getAttributes() != null) {
+ for (org.opends.server.types.Attribute a : srvResultEntry.getAttributes()) {
+ entry.addAttribute(from(a));
+ }
+ }
+ return entry;
+ }
+
+ /**
* Populates the result object with the operation details and return the
* result object if it was successful. Otherwise, it throws an
* {@link ErrorResultException}.
--
Gitblit v1.10.0