From b8f496a9076253f7dc672d361b7bd65d4a110a29 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 05 Mar 2013 16:05:52 +0000
Subject: [PATCH] Partial fix for OPENDJ-699: Implement DN reference mapping

---
 opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java
index 6e75dde..2a65484 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java
@@ -15,13 +15,18 @@
  */
 package org.forgerock.opendj.rest2ldap;
 
+import java.io.Closeable;
+import java.util.concurrent.atomic.AtomicReference;
+
 import org.forgerock.json.resource.ServerContext;
+import org.forgerock.opendj.ldap.Connection;
 
 /**
  * Common context information passed to containers and mappers.
  */
-final class Context {
+final class Context implements Closeable {
     private final Config config;
+    private final AtomicReference<Connection> connection = new AtomicReference<Connection>();
     private final ServerContext context;
 
     Context(final Config config, final ServerContext context) {
@@ -30,20 +35,32 @@
     }
 
     /**
-     * Returns the common configuration options.
-     *
-     * @return The common configuration options.
+     * {@inheritDoc}
      */
-    public Config getConfig() {
+    @Override
+    public void close() {
+        final Connection c = connection.getAndSet(null);
+        if (c != null) {
+            c.close();
+        }
+    }
+
+    Config getConfig() {
         return config;
     }
 
-    /**
-     * Returns the commons REST server context passed in with the REST request.
-     *
-     * @return The commons REST server context passed in with the REST request.
-     */
-    public ServerContext getServerContext() {
+    Connection getConnection() {
+        return connection.get();
+    }
+
+    ServerContext getServerContext() {
         return context;
     }
+
+    void setConnection(final Connection connection) {
+        if (!this.connection.compareAndSet(null, connection)) {
+            throw new IllegalStateException("LDAP connection obtained multiple times");
+        }
+    }
+
 }

--
Gitblit v1.10.0