From 1a9b0c4c35b0fbcc2cf09db1f40a17fc76cb4a90 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Wed, 26 Mar 2014 09:54:47 +0000
Subject: [PATCH] Minor code cleanup.

---
 opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java    |   68 ++++++++++++++++++----------------
 opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java |    4 -
 opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java            |    2 -
 opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java   |   30 ++++++---------
 4 files changed, 49 insertions(+), 55 deletions(-)

diff --git a/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index e788d64..42c0ae8 100644
--- a/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -27,6 +27,11 @@
 
 package org.opends.guitools.uninstaller;
 
+import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_LONG_REFERENCED_HOST_NAME;
+import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_SHORT_HOST;
+import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
+import static com.forgerock.opendj.cli.CliMessages.*;
+
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
@@ -36,20 +41,14 @@
 import org.opends.quicksetup.UserData;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 import org.opends.server.admin.client.cli.SecureConnectionCliParser;
-import org.opends.server.tools.JavaPropertiesTool.ErrorReturnCode;
-
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.BooleanArgument;
 import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ReturnCode;
 import com.forgerock.opendj.cli.StringArgument;
 
-import static org.opends.messages.AdminToolMessages.*;
-import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.ArgumentConstants.*;
-import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
-
 /**
  * Class used to parse and populate the arguments of the Uninstaller.
  *
@@ -70,7 +69,7 @@
 
   private StringArgument referencedHostNameArg;
 
-  // This CLI is always using the administration connector with SSL
+  /** This CLI is always using the administration connector with SSL. */
   private final boolean alwaysSSL = true;
 
   /**
@@ -372,12 +371,11 @@
   @Override
   public int validateGlobalOptions(LocalizableMessageBuilder buf)
   {
-    int returnValue;
     if (!noPromptArg.isPresent() && forceOnErrorArg.isPresent())
     {
-      LocalizableMessage message = ERR_UNINSTALL_FORCE_REQUIRES_NO_PROMPT.get(
-          "--"+forceOnErrorArg.getLongIdentifier(),
-          "--"+noPromptArg.getLongIdentifier());
+      final LocalizableMessage message =
+          ERR_TOOL_CONFLICTING_ARGS.get(forceOnErrorArg.getLongIdentifier(),
+              noPromptArg.getLongIdentifier());
       if (buf.length() > 0)
       {
         buf.append(LINE_SEPARATOR);
@@ -412,13 +410,9 @@
     super.validateGlobalOptions(buf);
     if (buf.length() > 0)
     {
-      returnValue = ErrorReturnCode.CONFLICTING_ARGS.getReturnCode();
+      return ReturnCode.CONFLICTING_ARGS.get();
     }
-    else
-    {
-      returnValue = ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode();
-    }
-    return returnValue;
+    return ReturnCode.SUCCESS.get();
   }
 
   /**
diff --git a/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index 5a77dd7..bf4fd94 100644
--- a/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -68,11 +68,10 @@
 import com.forgerock.opendj.cli.StringArgument;
 
 /**
- * This is a commodity class that can be used to check the arguments required
- * to establish a secure connection in the command line.  It can be used
- * to generate an ApplicationTrustManager object based on the options provided
- * by the user in the command line.
- *
+ * This is a commodity class that can be used to check the arguments required to
+ * establish a secure connection in the command line. It can be used to generate
+ * an ApplicationTrustManager object based on the options provided by the user
+ * in the command line.
  */
 public final class SecureConnectionCliArgs
 {
@@ -228,10 +227,11 @@
   }
 
   /**
-   * Tells whether this parser uses the Administrator UID (instead of the
-   * bind DN) or not.
-   * @return <CODE>true</CODE> if this parser uses the Administrator UID and
-   * <CODE>false</CODE> otherwise.
+   * Tells whether this parser uses the Administrator UID (instead of the bind
+   * DN) or not.
+   *
+   * @return {@code true} if this parser uses the Administrator UID and
+   *         {@code false} otherwise.
    */
   public boolean useAdminUID()
   {
@@ -600,30 +600,29 @@
 
 
   /**
-   * Returns <CODE>true</CODE> if we can read on the provided path and
-   * <CODE>false</CODE> otherwise.
-   * @param path the path.
-   * @return <CODE>true</CODE> if we can read on the provided path and
-   * <CODE>false</CODE> otherwise.
+   * Returns {@code true} if we can read on the provided path and
+   * {@code false} otherwise.
+   *
+   * @param path
+   *          the path.
+   * @return {@code true} if we can read on the provided path and
+   *         {@code false} otherwise.
    */
   private boolean canRead(String path)
   {
     final File file = new File(path);
-    if (file.exists())
-    {
-      return file.canRead();
-    }
-    return false;
+    return file.exists() && file.canRead();
   }
 
   /**
-   *  Returns the absolute path of the trust store file that appears on the
-   *  config.  Returns <CODE>null</CODE> if the trust store is not defined or
-   *  it does not exist.
+   * Returns the absolute path of the trust store file that appears on the
+   * config. Returns {@code null} if the trust store is not defined or it
+   * does not exist.
    *
-   *  @return the absolute path of the trust store file that appears on the
-   *  config.
-   *  @throws ConfigException if there is an error reading the configuration.
+   * @return the absolute path of the trust store file that appears on the
+   *         config.
+   * @throws ConfigException
+   *           if there is an error reading the configuration.
    */
   public String getTruststoreFileFromConfig() throws ConfigException
   {
@@ -681,8 +680,10 @@
 
   /**
    * Returns the admin port from the configuration.
+   *
    * @return the admin port from the configuration.
-   * @throws ConfigException if an error occurs reading the configuration.
+   * @throws ConfigException
+   *           if an error occurs reading the configuration.
    */
   public int getAdminPortFromConfig() throws ConfigException
   {
@@ -726,10 +727,11 @@
 
   /**
    * Returns the port to be used according to the configuration and the
-   * arguments provided by the user.
-   * This method should be called after the arguments have been parsed.
+   * arguments provided by the user. This method should be called after the
+   * arguments have been parsed.
+   *
    * @return the port to be used according to the configuration and the
-   * arguments provided by the user.
+   *         arguments provided by the user.
    */
   public int getPortFromConfig()
   {
@@ -742,10 +744,10 @@
       {
         portNumber = getAdminPortFromConfig();
       } catch (ConfigException ex) {
-        // nothing to do
+        // Nothing to do
       }
     } else {
-      portNumber = 636;
+      portNumber = CliConstants.DEFAULT_SSL_PORT;
     }
     return portNumber;
   }
@@ -753,7 +755,9 @@
   /**
    * Updates the default values of the port and the trust store with what is
    * read in the configuration.
-   * @throws ConfigException if there is an error reading the configuration.
+   *
+   * @throws ConfigException
+   *           if there is an error reading the configuration.
    */
   public void initArgumentsWithConfiguration() throws ConfigException
   {
diff --git a/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java b/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
index 6b3be70..57bafa9 100644
--- a/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
+++ b/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -61,7 +61,6 @@
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.admin.ads.util.ConnectionUtils;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
-import org.opends.server.tools.JavaPropertiesTool.ErrorReturnCode;
 import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
 
 import com.forgerock.opendj.cli.Argument;
@@ -202,7 +201,6 @@
           {
             if (app.isInteractive()
                 && ci.isTrustStoreInMemory()
-                && e.getCause() != null
                 && e.getCause() instanceof SSLException
                 && e.getCause().getCause() instanceof CertificateException)
             {
@@ -354,7 +352,7 @@
     // arguments.
     LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
     int v = secureArgsList.validateGlobalOptions(buf);
-    if (v != ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode())
+    if (v != ReturnCode.SUCCESS.get())
     {
       throw new ArgumentException(buf.toMessage());
     }
diff --git a/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java b/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
index 314c870..2fe79f9 100644
--- a/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
+++ b/opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -827,8 +827,6 @@
    *           parsed successfully.
    * @throws ClientException
    *           If the management context could not be created.
-   * @throws ClientException
-   *           If a CLI exception occurred.
    */
   public abstract MenuResult<Integer> run(ConsoleApplication app,
       ManagementContextFactory factory) throws ArgumentException,

--
Gitblit v1.10.0