From db786032bf45be89c4a893281911364d158cfb6e Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Sat, 20 Oct 2012 10:10:53 +0000
Subject: [PATCH] Update to use new json-resource 2.0 APIs.

---
 opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java |   74 ++++++++++++++++++------------------
 1 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
index 0c92b63..214950b 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimpleAttributeMapper.java
@@ -26,26 +26,27 @@
 
 import org.forgerock.json.fluent.JsonPointer;
 import org.forgerock.json.fluent.JsonValue;
+import org.forgerock.json.resource.ResultHandler;
+import org.forgerock.json.resource.ServerContext;
 import org.forgerock.opendj.ldap.Attribute;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.Function;
 import org.forgerock.opendj.ldap.Functions;
-import org.forgerock.resource.provider.Context;
 
 /**
  *
  */
 public class SimpleAttributeMapper implements AttributeMapper {
 
-    private final String ldapAttributeName;
-    private final String jsonAttributeName;
-    private final String normalizedJsonAttributeName;
-
-    private boolean forceSingleValued = false;
-    private Object defaultValue = null;
-    private boolean isReadOnly = false;
     private Function<ByteString, ?, Void> decoder = null;
+    private Object defaultValue = null;
+    private boolean forceSingleValued = false;
+
+    private boolean isReadOnly = false;
+    private final String jsonAttributeName;
+    private final String ldapAttributeName;
+    private final String normalizedJsonAttributeName;
 
     /**
      * Creates a new simple attribute mapper which maps a single LDAP attribute
@@ -54,7 +55,7 @@
      * @param attributeName
      *            The name of the simple JSON and LDAP attribute.
      */
-    public SimpleAttributeMapper(String attributeName) {
+    public SimpleAttributeMapper(final String attributeName) {
         this(attributeName, attributeName);
     }
 
@@ -67,54 +68,38 @@
      * @param ldapAttributeName
      *            The name of the LDAP attribute.
      */
-    public SimpleAttributeMapper(String jsonAttributeName, String ldapAttributeName) {
+    public SimpleAttributeMapper(final String jsonAttributeName, final String ldapAttributeName) {
         this.jsonAttributeName = jsonAttributeName;
         this.ldapAttributeName = ldapAttributeName;
         this.normalizedJsonAttributeName = toLowerCase(jsonAttributeName);
     }
 
-    public SimpleAttributeMapper withDefaultValue(Object defaultValue) {
-        this.defaultValue = defaultValue;
-        return this;
-    }
-
-    public SimpleAttributeMapper isReadOnly(boolean readOnly) {
-        this.isReadOnly = readOnly;
-        return this;
-    }
-
-    public SimpleAttributeMapper forceSingleValued(boolean singleValued) {
+    public SimpleAttributeMapper forceSingleValued(final boolean singleValued) {
         this.forceSingleValued = singleValued;
         return this;
     }
 
-    public SimpleAttributeMapper withDecoder(Function<ByteString, ?, Void> f) {
-        this.decoder = f;
-        return this;
-    }
-
     /**
      * {@inheritDoc}
      */
-    public void getLDAPAttributes(JsonPointer jsonAttribute, Set<String> ldapAttributes) {
+    public void getLDAPAttributes(final JsonPointer jsonAttribute, final Set<String> ldapAttributes) {
         if (attributeMatchesPointer(jsonAttribute)) {
             ldapAttributes.add(ldapAttributeName);
         }
     }
 
-    private boolean attributeMatchesPointer(JsonPointer resourceAttribute) {
-        return resourceAttribute.isEmpty()
-                || toLowerCase(resourceAttribute.get(0)).equals(normalizedJsonAttributeName);
+    public SimpleAttributeMapper isReadOnly(final boolean readOnly) {
+        this.isReadOnly = readOnly;
+        return this;
     }
 
     /**
      * {@inheritDoc}
      */
-    public void toJson(Context c, Entry e,
-            final AttributeMapperCompletionHandler<Map<String, Object>> h) {
-        Attribute a = e.getAttribute(ldapAttributeName);
+    public void toJson(final ServerContext c, final Entry e, final ResultHandler<Map<String, Object>> h) {
+        final Attribute a = e.getAttribute(ldapAttributeName);
         if (a != null) {
-            Function<ByteString, ?, Void> f =
+            final Function<ByteString, ?, Void> f =
                     decoder == null ? Functions.fixedFunction(byteStringToJson(), a) : decoder;
             final Object value;
             if (forceSingleValued || a.getAttributeDescription().getAttributeType().isSingleValue()) {
@@ -122,17 +107,32 @@
             } else {
                 value = a.parse().asSetOf(f, defaultValue);
             }
-            Map<String, Object> result = Collections.singletonMap(jsonAttributeName, value);
-            h.onSuccess(result);
+            final Map<String, Object> result = Collections.singletonMap(jsonAttributeName, value);
+            h.handleResult(result);
         }
     }
 
     /**
      * {@inheritDoc}
      */
-    public void toLDAP(Context c, JsonValue v, AttributeMapperCompletionHandler<List<Attribute>> h) {
+    public void toLDAP(final ServerContext c, final JsonValue v, final ResultHandler<List<Attribute>> h) {
         // TODO Auto-generated method stub
 
     }
 
+    public SimpleAttributeMapper withDecoder(final Function<ByteString, ?, Void> f) {
+        this.decoder = f;
+        return this;
+    }
+
+    public SimpleAttributeMapper withDefaultValue(final Object defaultValue) {
+        this.defaultValue = defaultValue;
+        return this;
+    }
+
+    private boolean attributeMatchesPointer(final JsonPointer resourceAttribute) {
+        return resourceAttribute.isEmpty()
+                || toLowerCase(resourceAttribute.get(0)).equals(normalizedJsonAttributeName);
+    }
+
 }

--
Gitblit v1.10.0