From 238ba0fdb4612736c0b8ea99a2fb2fcd34ee7e41 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Mon, 14 Apr 2014 14:52:42 +0000
Subject: [PATCH] OPENDJ-1343 Migrate dsconfig - Removed unnecessary interface ManagementContextFactory. - Minor code cleanup.

---
 /dev/null                                                                                                   |   77 -------------------------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DeleteSubCommandHandler.java      |    2 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java     |    5 +
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandlerFactory.java     |   12 ++--
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java      |    2 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java |   18 ++++--
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java            |    4 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java        |   20 +++---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java     |    2 
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java        |    5 +
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DSConfig.java                     |   26 +-------
 11 files changed, 43 insertions(+), 130 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
index 73b51d6..f222595 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
@@ -1146,7 +1146,7 @@
   /** {@inheritDoc} */
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
+      LDAPManagementContextFactory factory) throws ArgumentException,
       ClientException {
     LocalizableMessage ufn = relation.getUserFriendlyName();
 
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DSConfig.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DSConfig.java
index 99ca1e3..810eab2 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DSConfig.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -116,8 +116,6 @@
     /** The sub-command handler. */
     private final SubCommandHandler handler;
 
-
-
     /**
      * Creates a new sub-command handler call-back.
      *
@@ -128,8 +126,6 @@
       this.handler = handler;
     }
 
-
-
     /** {@inheritDoc} */
     @Override
     public MenuResult<Integer> invoke(ConsoleApplication app)
@@ -160,8 +156,6 @@
     }
   }
 
-
-
   /**
    * The interactive mode sub-menu implementation.
    */
@@ -170,8 +164,6 @@
     /** The menu. */
     private final Menu<Integer> menu;
 
-
-
     /**
      * Creates a new sub-menu implementation.
      *
@@ -256,8 +248,6 @@
       this.menu = builder.toMenu();
     }
 
-
-
     /** {@inheritDoc} */
     @Override
     public final MenuResult<Integer> invoke(ConsoleApplication app)
@@ -314,8 +304,6 @@
     }
   }
 
-
-
   /**
    * Provides the command-line arguments to the main application for
    * processing and returns the exit code as an integer.
@@ -334,8 +322,7 @@
       OutputStream errStream)
   {
     JDKLogging.disableLogging();
-    DSConfig app =
-        new DSConfig(System.in, outStream, errStream);
+    final DSConfig app = new DSConfig(System.in, outStream, errStream);
     app.sessionStartTime = System.currentTimeMillis();
     /*
      * FIXME: obtain path info from system properties.
@@ -365,7 +352,7 @@
    * The factory which the application should use to retrieve its management
    * context.
    */
-  private ManagementContextFactory factory = null;
+  private LDAPManagementContextFactory factory = null;
 
   /**
    * Flag indicating whether or not the global arguments have already been
@@ -762,12 +749,7 @@
       retCode = runSubCommand(handler);
     }
 
-    try {
-      // Close the Management context ==> an LDAP UNBIND is sent
-      factory.close();
-    } catch (Exception e) {
-      // Nothing to report in this case
-    }
+    factory.close();
 
     return retCode;
   }
@@ -1176,7 +1158,7 @@
         String[] allArgsArray = allArguments.toArray(new String[]{});
 
         int exitCode = main(allArgsArray, getOutputStream(), getErrorStream());
-        if (exitCode != 0)
+        if (exitCode != ReturnCode.SUCCESS.get())
         {
           System.exit(filterExitCode(exitCode));
         }
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DeleteSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DeleteSubCommandHandler.java
index 764d5e3..f3962d0 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DeleteSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/DeleteSubCommandHandler.java
@@ -219,7 +219,7 @@
   /** {@inheritDoc} */
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
+      LDAPManagementContextFactory factory) throws ArgumentException,
       ClientException {
     // Get the naming argument values.
     List<String> names = getNamingArgValues(app, namingArgs);
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
index 5fbfc20..c9a92c8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
@@ -231,7 +231,7 @@
    */
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
+      LDAPManagementContextFactory factory) throws ArgumentException,
       ClientException {
     // Get the property names.
     Set<String> propertyNames = getPropertyNames();
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
index 1c51512..523c174 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
@@ -800,8 +800,9 @@
   /** {@inheritDoc} */
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
-      ClientException {
+      LDAPManagementContextFactory factory) throws ArgumentException,
+      ClientException
+  {
 
     String categoryName = categoryArgument.getValue();
     String typeName = typeArgument.getValue();
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
index e2fd071..f9ac25a 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -46,9 +46,9 @@
 import com.forgerock.opendj.cli.ReturnCode;
 
 /**
- * An LDAP management context factory.
+ * An LDAP management context factory for the DSConfig tool.
  */
-public final class LDAPManagementContextFactory implements ManagementContextFactory
+public final class LDAPManagementContextFactory
 {
 
   /** The management context. */
@@ -79,15 +79,21 @@
     factory = cfp.getAuthenticatedConnectionFactory();
   }
 
-  /** {@inheritDoc} */
-  @Override
+  /**
+   * Closes this management context.
+   */
   public void close()
   {
     closeSilently(context);
   }
 
-  /** {@inheritDoc} */
-  @Override
+  /**
+   * Returns the command builder that provides the equivalent arguments in
+   * interactive mode to get the management context.
+   *
+   * @return the command builder that provides the equivalent arguments in
+   *         interactive mode to get the management context.
+   */
   public CommandBuilder getContextCommandBuilder()
   {
     return contextCommandBuilder;
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java
index a9896cc..b59d927 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java
@@ -158,21 +158,21 @@
       SubCommandArgumentParser parser, ManagedObjectPath<?, ?> p,
       RelationDefinition<?, ?> r, String rname, LocalizableMessage rufn)
       throws ArgumentException {
-    this.path = p;
-    this.relation = r;
+    path = p;
+    relation = r;
 
     // Create the sub-command.
-    String name = "list-" + rname;
-    LocalizableMessage desc = INFO_DSCFG_DESCRIPTION_SUBCMD_LIST.get(rufn);
-    this.subCommand = new SubCommand(parser, name, false, 0, 0, null, desc);
+    subCommand =
+        new SubCommand(parser, "list-" + rname, false, 0, 0, null,
+            INFO_DSCFG_DESCRIPTION_SUBCMD_LIST.get(rufn));
 
     // Create the naming arguments.
-    this.namingArgs = createNamingArgs(subCommand, path, false);
+    namingArgs = createNamingArgs(subCommand, path, false);
 
     // Register arguments.
-    registerPropertyNameArgument(this.subCommand);
-    registerUnitSizeArgument(this.subCommand);
-    registerUnitTimeArgument(this.subCommand);
+    registerPropertyNameArgument(subCommand);
+    registerUnitSizeArgument(subCommand);
+    registerUnitTimeArgument(subCommand);
 
     // Register the tags associated with the child managed objects.
     addTags(relation.getChildDefinition().getAllTags());
@@ -204,7 +204,7 @@
   /** {@inheritDoc} */
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
+      LDAPManagementContextFactory factory) throws ArgumentException,
       ClientException {
     // Get the property names.
     Set<String> propertyNames = getPropertyNames();
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ManagementContextFactory.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ManagementContextFactory.java
deleted file mode 100644
index 265c947..0000000
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/ManagementContextFactory.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 2007-2009 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.tools.dsconfig;
-
-import org.forgerock.opendj.config.client.ManagementContext;
-
-import com.forgerock.opendj.cli.ArgumentException;
-import com.forgerock.opendj.cli.ClientException;
-import com.forgerock.opendj.cli.CommandBuilder;
-import com.forgerock.opendj.cli.ConsoleApplication;
-
-
-
-/**
- * A factory for retrieving the management context which should be used by the
- * DSConfig application.
- * <p>
- * Factory implementations are responsible for registering their required global
- * options during initialization.
- */
-public interface ManagementContextFactory {
-
-  /**
-   * Gets the management context which sub-commands should use in
-   * order to manage the directory server.
-   *
-   * @param app
-   *          The application instance.
-   * @return Returns the management context which sub-commands should
-   *         use in order to manage the directory server.
-   * @throws ArgumentException
-   *           If a management context related argument could not be
-   *           parsed successfully.
-   * @throws ClientException
-   *           If the management context could not be created.
-   */
-  ManagementContext getManagementContext(ConsoleApplication app)
-      throws ArgumentException, ClientException;
-
-  /**
-   * Closes this management context.
-   */
-  void close();
-
-  /**
-   * Returns the command builder that provides the equivalent arguments in
-   * interactive mode to get the management context.
-   *
-   * @return the command builder that provides the equivalent arguments in
-   *         interactive mode to get the management context.
-   */
-  CommandBuilder getContextCommandBuilder();
-}
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
index f999cff..664f25b 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -694,8 +694,9 @@
   @SuppressWarnings("unchecked")
   @Override
   public MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
-      ClientException {
+      LDAPManagementContextFactory factory) throws ArgumentException,
+      ClientException
+  {
     // Get the naming argument values.
     List<String> names = getNamingArgValues(app, namingArgs);
 
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
index 2fe79f9..07535b4 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -816,7 +816,7 @@
    * @param app
    *          The console application.
    * @param factory
-   *          The management context factory.
+   *          The LDAP management context factory context factory.
    * @return Returns a {@link MenuResult#success()} containing zero if
    *         the sub-command completed successfully or non-zero if it
    *         did not, or {@link MenuResult#quit()}, or
@@ -829,7 +829,7 @@
    *           If the management context could not be created.
    */
   public abstract MenuResult<Integer> run(ConsoleApplication app,
-      ManagementContextFactory factory) throws ArgumentException,
+      LDAPManagementContextFactory factory) throws ArgumentException,
       ClientException;
 
 
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandlerFactory.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandlerFactory.java
index 690f3e0..b76e90c 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandlerFactory.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandlerFactory.java
@@ -84,9 +84,9 @@
 
 
     /** {@inheritDoc} */
-    public <C extends ConfigurationClient, S extends Configuration>
-        Void visitOptional(
-        OptionalRelationDefinition<C, S> rd, ManagedObjectPath<?, ?> p) {
+    public <C extends ConfigurationClient, S extends Configuration> Void visitOptional(
+        OptionalRelationDefinition<C, S> rd, ManagedObjectPath<?, ?> p)
+    {
       try {
         // Create the sub-commands.
         createHandlers.add(CreateSubCommandHandler.create(parser, p, rd));
@@ -108,9 +108,9 @@
 
 
     /** {@inheritDoc} */
-    public <C extends ConfigurationClient, S extends Configuration>
-        Void visitSet(
-        SetRelationDefinition<C, S> rd, ManagedObjectPath<?, ?> p) {
+    public <C extends ConfigurationClient, S extends Configuration> Void visitSet(
+        SetRelationDefinition<C, S> rd, ManagedObjectPath<?, ?> p)
+    {
       try {
         // Create the sub-commands.
         createHandlers.add(CreateSubCommandHandler.create(parser, p, rd));

--
Gitblit v1.10.0