From 1b12eb719f2aeec7624182b983d79fc949d7cea2 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Tue, 05 May 2015 15:26:50 +0000
Subject: [PATCH] OPENDJ-1932 CR-6839 Improve management context API
---
opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java | 14
opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagementContext.java | 110 +++----------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java | 24 +-
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java | 11
opendj-config/src/main/java/org/forgerock/opendj/config/client/DriverBasedManagementContext.java | 160 ++++++++++++++++++++
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java | 11
opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java | 135 ++++++++++++++--
7 files changed, 329 insertions(+), 136 deletions(-)
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/client/DriverBasedManagementContext.java b/opendj-config/src/main/java/org/forgerock/opendj/config/client/DriverBasedManagementContext.java
new file mode 100644
index 0000000..17f3deb
--- /dev/null
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/client/DriverBasedManagementContext.java
@@ -0,0 +1,160 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Copyright 2008-2009 Sun Microsystems, Inc.
+ * Portions Copyright 2014-2015 ForgeRock AS
+ */
+package org.forgerock.opendj.config.client;
+
+import java.util.Set;
+import java.util.SortedSet;
+
+import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
+import org.forgerock.opendj.config.Configuration;
+import org.forgerock.opendj.config.ConfigurationClient;
+import org.forgerock.opendj.config.DefinitionDecodingException;
+import org.forgerock.opendj.config.InstantiableRelationDefinition;
+import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+import org.forgerock.opendj.config.ManagedObjectPath;
+import org.forgerock.opendj.config.OptionalRelationDefinition;
+import org.forgerock.opendj.config.PropertyDefinition;
+import org.forgerock.opendj.config.SetRelationDefinition;
+import org.forgerock.opendj.config.client.spi.Driver;
+import org.forgerock.opendj.ldap.LdapException;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
+
+/**
+ * Driver based client management connection context.
+ */
+public abstract class DriverBasedManagementContext implements ManagementContext {
+
+ /**
+ * Creates a new management context.
+ */
+ protected DriverBasedManagementContext() {
+ // No implementation required.
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name)
+ throws ManagedObjectNotFoundException, OperationRejectedException,
+ LdapException {
+ return getDriver().deleteManagedObject(parent, rd, name);
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws
+ ManagedObjectNotFoundException, OperationRejectedException, LdapException {
+ return getDriver().deleteManagedObject(parent, rd);
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name)
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException {
+ return getDriver().deleteManagedObject(parent, rd, name);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject(
+ ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException,
+ ManagedObjectNotFoundException, LdapException {
+ // Be careful to handle the root configuration.
+ if (path.isEmpty()) {
+ return (ManagedObject<C>) getRootConfigurationManagedObject();
+ }
+
+ return getDriver().getManagedObject(path);
+ }
+
+ @Override
+ public final <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
+ Set<P> values = getPropertyValues(path, pd);
+ if (values.isEmpty()) {
+ return null;
+ } else {
+ return values.iterator().next();
+ }
+ }
+
+ @Override
+ public final <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
+ return getDriver().getPropertyValues(path, pd);
+ }
+
+ @Override
+ public final RootCfgClient getRootConfiguration() {
+ return getRootConfigurationManagedObject().getConfiguration();
+ }
+
+ @Override
+ public final ManagedObject<RootCfgClient> getRootConfigurationManagedObject() {
+ return getDriver().getRootConfigurationManagedObject();
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws
+ ManagedObjectNotFoundException, LdapException {
+ return listManagedObjects(parent, rd, rd.getChildDefinition());
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd,
+ AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws
+ ManagedObjectNotFoundException, LdapException {
+ return getDriver().listManagedObjects(parent, rd, d);
+ }
+
+ @Override
+ public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws
+ ManagedObjectNotFoundException, LdapException {
+ return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition());
+ }
+
+ @Override
+ public final boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException,
+ LdapException {
+ return getDriver().managedObjectExists(path);
+ }
+
+ /**
+ * Gets the driver associated with this management context.
+ *
+ * @return Returns the driver associated with this management context.
+ */
+ protected abstract Driver getDriver();
+
+ @Override
+ public final void close() {
+ getDriver().close();
+ }
+
+}
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagementContext.java b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagementContext.java
index 07a6aa2..6e16eae 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagementContext.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ManagementContext.java
@@ -22,15 +22,13 @@
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
+ * Portions Copyright 2014-2015 ForgeRock AS
*/
package org.forgerock.opendj.config.client;
import java.io.Closeable;
-import java.util.Set;
import java.util.SortedSet;
-import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
import org.forgerock.opendj.config.Configuration;
import org.forgerock.opendj.config.ConfigurationClient;
@@ -42,20 +40,13 @@
import org.forgerock.opendj.config.PropertyDefinition;
import org.forgerock.opendj.config.PropertyException;
import org.forgerock.opendj.config.SetRelationDefinition;
-import org.forgerock.opendj.config.client.spi.Driver;
import org.forgerock.opendj.ldap.LdapException;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
/**
* Client management connection context.
*/
-public abstract class ManagementContext implements Closeable {
-
- /**
- * Creates a new management context.
- */
- protected ManagementContext() {
- // No implementation required.
- }
+public interface ManagementContext extends Closeable {
/**
* Deletes the named instantiable child managed object from the named parent
@@ -88,12 +79,9 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name)
- throws ManagedObjectNotFoundException, OperationRejectedException,
- LdapException {
- return getDriver().deleteManagedObject(parent, rd, name);
- }
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException;
/**
* Deletes the optional child managed object from the named parent managed
@@ -124,11 +112,9 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws
- ManagedObjectNotFoundException, OperationRejectedException, LdapException {
- return getDriver().deleteManagedObject(parent, rd);
- }
+ ManagedObjectNotFoundException, OperationRejectedException, LdapException;
/**
* Deletes s set child managed object from the named parent managed object.
@@ -160,11 +146,9 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name)
- throws ManagedObjectNotFoundException, OperationRejectedException, LdapException {
- return getDriver().deleteManagedObject(parent, rd, name);
- }
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException;
/**
* Gets the named managed object.
@@ -190,17 +174,9 @@
* @throws LdapException
* If any other error occurs.
*/
- @SuppressWarnings("unchecked")
- public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject(
+ <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject(
ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException,
- ManagedObjectNotFoundException, LdapException {
- // Be careful to handle the root configuration.
- if (path.isEmpty()) {
- return (ManagedObject<C>) getRootConfigurationManagedObject();
- }
-
- return getDriver().getManagedObject(path);
- }
+ ManagedObjectNotFoundException, LdapException;
/**
* Gets the effective value of a property in the named managed object.
@@ -228,15 +204,8 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
- throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
- Set<P> values = getPropertyValues(path, pd);
- if (values.isEmpty()) {
- return null;
- } else {
- return values.iterator().next();
- }
- }
+ <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException;
/**
* Gets the effective values of a property in the named managed object.
@@ -264,10 +233,8 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
- throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
- return getDriver().getPropertyValues(path, pd);
- }
+ <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException;
/**
* Gets the root configuration client associated with this management
@@ -276,9 +243,7 @@
* @return Returns the root configuration client associated with this
* management context.
*/
- public final RootCfgClient getRootConfiguration() {
- return getRootConfigurationManagedObject().getConfiguration();
- }
+ RootCfgClient getRootConfiguration();
/**
* Gets the root configuration managed object associated with this
@@ -287,9 +252,7 @@
* @return Returns the root configuration managed object associated with
* this management context.
*/
- public final ManagedObject<RootCfgClient> getRootConfigurationManagedObject() {
- return getDriver().getRootConfigurationManagedObject();
- }
+ ManagedObject<RootCfgClient> getRootConfigurationManagedObject();
/**
* Lists the child managed objects of the named parent managed object.
@@ -313,11 +276,9 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws
- ManagedObjectNotFoundException, LdapException {
- return listManagedObjects(parent, rd, rd.getChildDefinition());
- }
+ ManagedObjectNotFoundException, LdapException;
/**
* Lists the child managed objects of the named parent managed object which
@@ -345,12 +306,10 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd,
AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws
- ManagedObjectNotFoundException, LdapException {
- return getDriver().listManagedObjects(parent, rd, d);
- }
+ ManagedObjectNotFoundException, LdapException;
/**
* Lists the child managed objects of the named parent managed object.
@@ -374,11 +333,9 @@
* @throws LdapException
* If any other error occurs.
*/
- public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws
- ManagedObjectNotFoundException, LdapException {
- return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition());
- }
+ ManagedObjectNotFoundException, LdapException;
/**
* Determines whether or not the named managed object exists.
@@ -392,24 +349,5 @@
* @throws LdapException
* If any other error occurs.
*/
- public final boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException,
- LdapException {
- return getDriver().managedObjectExists(path);
- }
-
- /**
- * Gets the driver associated with this management context.
- *
- * @return Returns the driver associated with this management context.
- */
- protected abstract Driver getDriver();
-
- /**
- * Closes this management context.
- */
- @Override
- public final void close() {
- getDriver().close();
- }
-
+ boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, LdapException;
}
diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
index 306525e..824c142 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
@@ -35,28 +35,142 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.SortedSet;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
+import org.forgerock.opendj.config.Configuration;
+import org.forgerock.opendj.config.ConfigurationClient;
+import org.forgerock.opendj.config.DefinitionDecodingException;
+import org.forgerock.opendj.config.InstantiableRelationDefinition;
import org.forgerock.opendj.config.LDAPProfile;
+import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+import org.forgerock.opendj.config.ManagedObjectPath;
+import org.forgerock.opendj.config.OptionalRelationDefinition;
+import org.forgerock.opendj.config.PropertyDefinition;
+import org.forgerock.opendj.config.SetRelationDefinition;
+import org.forgerock.opendj.config.client.DriverBasedManagementContext;
+import org.forgerock.opendj.config.client.ManagedObject;
+import org.forgerock.opendj.config.client.ManagedObjectDecodingException;
import org.forgerock.opendj.config.client.ManagementContext;
+import org.forgerock.opendj.config.client.OperationRejectedException;
import org.forgerock.opendj.config.client.spi.Driver;
import org.forgerock.opendj.ldap.AbstractConnectionWrapper;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.Entry;
+import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.MemoryBackend;
import org.forgerock.opendj.ldap.requests.UnbindRequest;
import org.forgerock.opendj.ldif.LDIF;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.forgerock.util.Reject;
/**
* An LDAP management connection context.
*/
-public final class LDAPManagementContext extends ManagementContext {
+public final class LDAPManagementContext extends DriverBasedManagementContext {
+
+ private static final class ManagementContextWrapper implements ManagementContext {
+ private final ManagementContext delegate;
+ private final List<IOException> exceptions;
+
+ private ManagementContextWrapper(ManagementContext result, List<IOException> exceptions) {
+ this.delegate = result;
+ this.exceptions = exceptions;
+ }
+
+ @Override
+ public boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException,
+ LdapException {
+ return delegate.managedObjectExists(path);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws ManagedObjectNotFoundException,
+ LdapException {
+ return delegate.listManagedObjects(parent, rd);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd,
+ AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException,
+ LdapException {
+ return delegate.listManagedObjects(parent, rd, d);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd)
+ throws ManagedObjectNotFoundException, LdapException {
+ return delegate.listManagedObjects(parent, rd);
+ }
+
+ @Override
+ public ManagedObject<RootCfgClient> getRootConfigurationManagedObject() {
+ return delegate.getRootConfigurationManagedObject();
+ }
+
+ @Override
+ public RootCfgClient getRootConfiguration() {
+ return delegate.getRootConfiguration();
+ }
+
+ @Override
+ public <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
+ return delegate.getPropertyValues(path, pd);
+ }
+
+ @Override
+ public <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd)
+ throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException {
+ return delegate.getPropertyValue(path, pd);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject(
+ ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException,
+ ManagedObjectNotFoundException, LdapException {
+ return delegate.getManagedObject(path);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name)
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException {
+ return delegate.deleteManagedObject(parent, rd, name);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd)
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException {
+ return delegate.deleteManagedObject(parent, rd);
+ }
+
+ @Override
+ public <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject(
+ ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name)
+ throws ManagedObjectNotFoundException, OperationRejectedException, LdapException {
+ return delegate.deleteManagedObject(parent, rd, name);
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ if (!exceptions.isEmpty()) {
+ throw exceptions.get(0);
+ }
+ }
+ }
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -77,21 +191,7 @@
return context;
}
- /**
- * Returns a LDIF management context on the provided LDIF file.
- *
- * @param ldifFile
- * The LDIF file to manage
- * @param profile
- * The LDAP profile
- * @param exceptions
- * Contains {@code IOException} that may occurred during management context close.
- * Could be {@code null}
- * @return A LDIF file management context
- * @throws IOException
- * If problems occurs while reading the file.
- */
- public static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile,
+ private static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile,
final List<IOException> exceptions) throws IOException {
final BufferedReader configReader = new BufferedReader(new FileReader(ldifFile));
try {
@@ -145,7 +245,8 @@
*/
public static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile)
throws IOException {
- return newLDIFManagementContext(ldifFile, profile, null);
+ final List<IOException> exceptions = new ArrayList<>();
+ return new ManagementContextWrapper(newLDIFManagementContext(ldifFile, profile, exceptions), exceptions);
}
/** The LDAP management context driver. */
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
index 5869643..eb012b7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
@@ -31,7 +31,7 @@
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
-import java.io.IOException;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -388,11 +388,10 @@
throws OpenDsException
{
getInfo().initializeConfigurationFramework();
- try
+ final File configFile = Installation.getLocal().getCurrentConfigurationFile();
+ final LDAPProfile ldapProfile = LDAPProfile.getInstance();
+ try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile))
{
- final List<IOException> exceptions = new ArrayList<>();
- final ManagementContext context = LDAPManagementContext.newLDIFManagementContext(
- Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
final BackendCfgClient backend = context.getRootConfiguration().getBackend(backendName);
if (backend instanceof LocalDBBackendCfgClient)
{
@@ -404,8 +403,6 @@
updateBackendIndexOnline(
(PluggableBackendCfgClient) backend, indexToModify, attributeName, indexTypes, indexEntryLimit);
}
- context.close();
- Utilities.throwFirstFrom(exceptions);
}
catch (final Exception e)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
index a6e791c..4e04b7e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
@@ -38,7 +38,7 @@
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
-import java.io.IOException;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
@@ -1103,11 +1103,10 @@
final List<VLVSortOrder> sortOrder) throws OpenDsException
{
getInfo().initializeConfigurationFramework();
- try
+ final File configFile = Installation.getLocal().getCurrentConfigurationFile();
+ final LDAPProfile ldapProfile = LDAPProfile.getInstance();
+ try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile))
{
- final List<IOException> exceptions = new ArrayList<>();
- final ManagementContext context = LDAPManagementContext.newLDIFManagementContext(
- Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
final BackendCfgClient backend = context.getRootConfiguration().getBackend(backendName);
if (backend instanceof LocalDBBackendCfgClient)
{
@@ -1119,8 +1118,6 @@
updateVLVBackendIndexOnline((PluggableBackendCfgClient) backend, vlvIndexName, indexToModify, baseDN, filter,
searchScope, sortOrder);
}
- context.close();
- Utilities.throwFirstFrom(exceptions);
}
catch (final Exception e)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
index adcfde5..36bdce0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -1019,18 +1019,18 @@
try
{
getInfo().initializeConfigurationFramework();
- final List<IOException> exceptions = new ArrayList<>();
- final org.forgerock.opendj.config.client.ManagementContext context =
- org.forgerock.opendj.config.client.ldap.LDAPManagementContext.newLDIFManagementContext(
- Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
- final org.forgerock.opendj.server.config.client.BackendCfgClient backend =
- context.getRootConfiguration().getBackend(backendName);
- final SortedSet<org.forgerock.opendj.ldap.DN> baseDNs = backend.getBaseDN();
- baseDNs.add(org.forgerock.opendj.ldap.DN.valueOf(newBaseDN));
- backend.setBaseDN(baseDNs);
- backend.commit();
- context.close();
- Utilities.throwFirstFrom(exceptions);
+ final File config = Installation.getLocal().getCurrentConfigurationFile();
+ final LDAPProfile profile = LDAPProfile.getInstance();
+ try (org.forgerock.opendj.config.client.ManagementContext context =
+ org.forgerock.opendj.config.client.ldap.LDAPManagementContext.newLDIFManagementContext(config, profile))
+ {
+ final org.forgerock.opendj.server.config.client.BackendCfgClient backend =
+ context.getRootConfiguration().getBackend(backendName);
+ final SortedSet<org.forgerock.opendj.ldap.DN> baseDNs = backend.getBaseDN();
+ baseDNs.add(org.forgerock.opendj.ldap.DN.valueOf(newBaseDN));
+ backend.setBaseDN(baseDNs);
+ backend.commit();
+ }
}
catch (Exception e)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
index 0478454..4da3de3 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
@@ -25,7 +25,7 @@
*/
package org.opends.server.tools;
-import java.io.IOException;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@@ -130,12 +130,12 @@
ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType) throws Exception
{
Utilities.initializeConfigurationFramework();
- final List<IOException> exceptions = new ArrayList<>();
- final ManagementContext context = LDAPManagementContext.newLDIFManagementContext(
- Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
- createBackend(context.getRootConfiguration(), backendName, baseDNs, backendType);
- context.close();
- Utilities.throwFirstFrom(exceptions);
+ final File configFile = Installation.getLocal().getCurrentConfigurationFile();
+ final LDAPProfile ldapProfile = LDAPProfile.getInstance();
+ try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile))
+ {
+ createBackend(context.getRootConfiguration(), backendName, baseDNs, backendType);
+ }
}
/**
--
Gitblit v1.10.0