From 149df264fb7c9c37e6439d00cc33613f57448ac1 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 03 Aug 2016 09:43:06 +0000
Subject: [PATCH] code cleanups

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java |  118 +++++-----
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java         |  124 ++--------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java     |  314 ++++++++++-----------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewEntryTask.java             |   50 +--
 4 files changed, 229 insertions(+), 377 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
index afa6800..64597f9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -165,7 +165,6 @@
     numSubordinateHacker = new NumSubordinateHacker();
   }
 
-
   /**
    * Set the connection for accessing the directory.  Since we must use
    * different controls when searching the configuration and the user data,
@@ -200,7 +199,6 @@
     startRefresh(null);
   }
 
-
   /**
    * Return the connection for accessing the directory configuration.
    * @return the connection for accessing the directory configuration.
@@ -217,7 +215,6 @@
     return connUserData;
   }
 
-
   /**
    * Return the JTree controlled by this controller.
    * @return the JTree controlled by this controller.
@@ -226,7 +223,6 @@
     return tree;
   }
 
-
   /**
    * Return the connection pool used by this controller.
    * If a client class adds authentication to the connection
@@ -248,8 +244,8 @@
   /**
    * Tells whether the given suffix is in the tree or not.
    * @param suffixDn the DN of the suffix to be analyzed.
-   * @return <CODE>true</CODE> if the provided String is the DN of a suffix
-   * and <CODE>false</CODE> otherwise.
+   * @return {@code true} if the provided String is the DN of a suffix
+   * and {@code false} otherwise.
    * @throws IllegalArgumentException if a node with the given dn exists but
    * is not a suffix node.
    */
@@ -262,7 +258,7 @@
    * Add an LDAP suffix to this controller.
    * A new node is added in the JTree and a refresh is started.
    * @param suffixDn the DN of the suffix.
-   * @param parentSuffixDn the DN of the parent suffix (or <CODE>null</CODE> if
+   * @param parentSuffixDn the DN of the parent suffix (or {@code null} if
    * there is no parent DN).
    * @return the TreePath of the new node.
    * @throws IllegalArgumentException if a node with the given dn exists.
@@ -313,7 +309,6 @@
     return new TreePath(treeModel.getPathToRoot(newNode));
   }
 
-
   /**
    * Remove all the suffixes.
    * The controller removes all the nodes from the JTree except the root.
@@ -325,7 +320,6 @@
     return new TreePath(treeModel.getPathToRoot(rootNode));
   }
 
-
   /**
    * Return the display flags.
    * @return the display flags.
@@ -334,7 +328,6 @@
     return displayFlags;
   }
 
-
   /**
    * Set the display flags and call startRefresh().
    * @param flags the display flags to be set.
@@ -368,8 +361,8 @@
 
   /**
    * Says whether we are showing the attribute name or not.
-   * @return <CODE>true</CODE> if we are showing the attribute name and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if we are showing the attribute name and
+   * {@code false} otherwise.
    */
   public boolean isAttributeNameShown() {
     return showAttributeName;
@@ -394,14 +387,13 @@
 
   /**
    * Return true if this controller follows referrals.
-   * @return <CODE>true</CODE> if this controller follows referrals and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if this controller follows referrals and
+   * {@code false} otherwise.
    */
   public boolean getFollowReferrals() {
     return followReferrals;
   }
 
-
   /**
    * Enable/display the following of referrals.
    * This routine starts a refresh on each referral node.
@@ -420,17 +412,15 @@
     startRefresh(null);
   }
 
-
   /**
    * Return true if entries are displayed sorted.
-   * @return <CODE>true</CODE> if entries are displayed sorted and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if entries are displayed sorted and
+   * {@code false} otherwise.
    */
   public boolean isSorted() {
     return sorted;
   }
 
-
   /**
    * Enable/disable entry sort.
    * This routine collapses the JTree and invokes startRefresh().
@@ -448,21 +438,19 @@
     startRefresh(null);
   }
 
-
   /**
    * Return true if only container entries are displayed.
    * An entry is a container if:
    *    - it has some children
    *    - or its class is one of the container classes
    *      specified with setContainerClasses().
-   * @return <CODE>true</CODE> if only container entries are displayed and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if only container entries are displayed and
+   * {@code false} otherwise.
    */
   public boolean isShowContainerOnly() {
     return showContainerOnly;
   }
 
-
   /**
    * Enable or disable container display and call startRefresh().
    * @param showContainerOnly whether to display only containers or all the
@@ -473,7 +461,6 @@
     startRefresh(null);
   }
 
-
   /**
    * Find the BrowserNodeInfo associated to a TreePath and returns
    * the describing IBrowserNodeInfo.
@@ -485,7 +472,6 @@
     return new BrowserNodeInfoImpl(node);
   }
 
-
   /**
    * Return the array of container classes for this controller.
    * Warning: the returned array is not cloned.
@@ -495,7 +481,6 @@
     return containerClasses;
   }
 
-
   /**
    * Set the list of container classes and calls startRefresh().
    * Warning: the array is not cloned.
@@ -506,7 +491,6 @@
     startRefresh(null);
   }
 
-
   /**
    * NUMSUBORDINATE HACK
    * Make the hacker public so that RefreshTask can use it.
@@ -516,7 +500,6 @@
     return numSubordinateHacker;
   }
 
-
   /**
    * NUMSUBORDINATE HACK
    * Set the hacker. Note this method does not trigger any
@@ -568,7 +551,6 @@
     return new TreePath(treeModel.getPathToRoot(childNode));
   }
 
-
   /**
    * Notify this controller that a entry has been deleted.
    * The controller removes the corresponding node from the JTree and returns
@@ -591,7 +573,6 @@
     return null;
   }
 
-
   /**
    * Notify this controller that an entry has changed.
    * The controller starts refreshing the corresponding node.
@@ -625,7 +606,6 @@
     startRefreshReferralNodes(rootNode);
   }
 
-
   /**
    * Start a refresh from the specified node.
    * If some refresh are on-going on descendant nodes, they are stopped.
@@ -633,13 +613,7 @@
    * @param nodeInfo the node to be refreshed.
    */
   public void startRefresh(BrowserNodeInfo nodeInfo) {
-    BasicNode node;
-    if (nodeInfo == null) {
-      node = rootNode;
-    }
-    else {
-      node = nodeInfo.getNode();
-    }
+    BasicNode node = nodeInfo != null ? nodeInfo.getNode() : rootNode;
     stopRefreshNode(node);
     startRefreshNode(node, null, true);
   }
@@ -690,9 +664,6 @@
     }
   }
 
-
-
-
   /**
    * Stop refreshing below this node.
    * TODO: this method is very costly when applied to something else than the
@@ -713,8 +684,6 @@
     }
   }
 
-
-
   /**
    * Call startRefreshNode() on each referral node accessible from parentNode.
    * @param parentNode the parent node.
@@ -732,8 +701,6 @@
     }
   }
 
-
-
   /**
    * Remove all the children below parentNode *without changing the leaf state*.
    * If specified, it keeps the SuffixNode and recurses on them. Inform the tree
@@ -774,7 +741,6 @@
     }
   }
 
-
   /**
    * For BrowserController private use.  When a node is collapsed the refresh
    * tasks on it are canceled.
@@ -808,15 +774,10 @@
    * @param node the selected node.
    */
   public void setInspectedNode(BrowserNodeInfo node) {
-    BrowserCellRenderer renderer = (BrowserCellRenderer)tree.getCellRenderer();
-    if (node == null) {
-      renderer.setInspectedNode(null);
-    } else {
-      renderer.setInspectedNode(node.getNode());
-    }
+    BrowserCellRenderer renderer = (BrowserCellRenderer) tree.getCellRenderer();
+    renderer.setInspectedNode(node != null ? node.getNode() : null);
   }
 
-
   /**
    * Routines for the task classes
    * =============================
@@ -826,7 +787,6 @@
    * called by task threads without synchronize clauses.
    */
 
-
   /**
    * The tree model created by the controller and assigned
    * to the JTree.
@@ -864,7 +824,6 @@
     return ALL_OBJECTS_FILTER;
   }
 
-
   /**
    * Return the LDAP search filter to use for searching child entries.
    * If showContainerOnly is true, the filter will select only the
@@ -910,9 +869,6 @@
     return result;
   }
 
-
-
-
   /**
    * Return the LDAP connection to reading the base entry of a node.
    * @param node the node for which we want the LDAP connection.
@@ -949,8 +905,8 @@
   /**
    * Returns whether a given node is a configuration node or not.
    * @param node the node to analyze.
-   * @return <CODE>true</CODE> if the node is a configuration node and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if the node is a configuration node and
+   * {@code false} otherwise.
    */
   public boolean isConfigurationNode(BasicNode node)
   {
@@ -989,7 +945,6 @@
     return findConnectionForDisplayedEntry(node, isConfigurationNode(node));
   }
 
-
   /**
    * Return the LDAP connection to search the displayed entry (which can be the
    * local or remote entry).
@@ -1007,8 +962,6 @@
     return findConnectionForLocalEntry(node, isConfigurationNode);
   }
 
-
-
   /**
    * Release a connection returned by selectConnectionForChildEntries() or
    * selectConnectionForBaseEntry().
@@ -1022,7 +975,6 @@
     }
   }
 
-
   /**
    * Returns the local entry URL for a given node.
    * @param node the node.
@@ -1041,7 +993,6 @@
     return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), node.getDN(), connConfig.isLdaps());
   }
 
-
   /**
    * Returns the displayed entry URL for a given node.
    * @param node the node.
@@ -1055,7 +1006,6 @@
     return findUrlForLocalEntry(node);
   }
 
-
   /**
    * Returns the DN to use for searching children of a given node.
    * In most cases, it's node.getDN(). However if node has referral data
@@ -1072,13 +1022,11 @@
     return node.getDN();
   }
 
-
-
   /**
    * Tells whether a node is displaying a remote entry.
    * @param node the node.
-   * @return <CODE>true</CODE> if the node displays a remote entry and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if the node displays a remote entry and
+   * {@code false} otherwise.
    */
   private boolean isDisplayedEntryRemote(BasicNode node) {
     if (followReferrals) {
@@ -1096,7 +1044,6 @@
     return false;
   }
 
-
   /**
    * Returns the list of attributes for the red search.
    * @return the list of attributes for the red search.
@@ -1200,7 +1147,6 @@
     return getRequestControls();
   }
 
-
   /**
    * Callbacks invoked by task classes
    * =================================
@@ -1278,14 +1224,12 @@
     }
     else if (newState == NodeRefresher.State.CANCELLED ||
         newState == NodeRefresher.State.INTERRUPTED) {
-
       // Let's collapse task.getNode()
       tree.collapsePath(new TreePath(treeModel.getPathToRoot(node)));
 
       // TODO: should we reflect this situation visually ?
     }
     else {
-
       if (oldState != NodeRefresher.State.SEARCHING_CHILDREN
           && newState == NodeRefresher.State.SEARCHING_CHILDREN) {
         // The children search is going to start
@@ -1326,7 +1270,6 @@
         }
       }
       else if (oldState == NodeRefresher.State.SEARCHING_CHILDREN) {
-
         updateChildNodes(task);
         if (newState == NodeRefresher.State.FINISHED) {
           // The children search is finished
@@ -1359,7 +1302,6 @@
       }
     }
 
-
     if (nodeChanged) {
       treeModel.nodeChanged(task.getNode());
     }
@@ -1369,7 +1311,6 @@
     }
   }
 
-
   /**
    * Commodity method that calls the method refreshTaskDidProgress in the event
    * thread.
@@ -1427,19 +1368,16 @@
     // Walk through the entries
     for (SearchResultEntry entry : task.getChildEntries())
     {
-      BasicNode child;
-
       // Search a child node matching the DN of the entry
       int index;
       if (differential) {
-//      System.out.println("Differential mode -> starting to search");
         index = findChildNode(parent, entry.getName().toString());
-//      System.out.println("Differential mode -> ending to search");
       }
       else {
         index = - (parent.getChildCount() + 1);
       }
 
+      BasicNode child;
       // If no node matches, we create a new node
       if (index < 0) {
         // -(index + 1) is the location where to insert the new node
@@ -1448,7 +1386,6 @@
         parent.insert(child, index);
         updateNodeRendering(child, entry);
         insertIndex.add(index);
-//      System.out.println("Inserted " + child.getDN() + " at " + index);
       }
       else { // Else we update the existing one
         child = (BasicNode)parent.getChildAt(index);
@@ -1473,25 +1410,19 @@
         hasNoSubOrdinates = !child.hasSubOrdinates();
       }
 
-
-
       // Propagate the refresh
       // Note: logically we should unconditionally call:
       //  startRefreshNode(child, false, true);
       //
-      // However doing that saturates refreshQueue
-      // with many nodes. And, by design, RefreshTask
-      // won't do anything on a node if:
+      // However doing that saturates refreshQueue with many nodes.
+      // And, by design, RefreshTask won't do anything on a node if:
       //    - this node has no subordinates
       //    - *and* this node has no referral data
-      // So we test these conditions here and
-      // skip the call to startRefreshNode() if
-      // possible.
+      // So we test these conditions here
+      // and skip the call to startRefreshNode() if possible.
       //
-      // The exception to this is the case where the
-      // node had children (in the tree).  In this case
-      // we force the refresh. See bug 5015115
-      //
+      // The exception to this is the case where the node had children
+      // (in the tree). In this case we force the refresh. See bug 5015115
       if (!hasNoSubOrdinates
           || child.getReferral() != null
           || child.getChildCount() > 0) {
@@ -1499,7 +1430,6 @@
       }
     }
 
-
     // Inform the tree model that we have created some new nodes
     if (insertIndex.size() >= 1) {
       treeModel.nodesWereInserted(parent, intArrayFromCollection(insertIndex));
@@ -1509,26 +1439,24 @@
     }
   }
 
-
-
   /**
    * Tells whether a differential update can be made in the provided task.
    * @param task the task.
-   * @return <CODE>true</CODE> if a differential update can be made and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if a differential update can be made and
+   * {@code false} otherwise.
    */
   private boolean canDoDifferentialUpdate(NodeRefresher task) {
     return task.getNode().getChildCount() >= 1
         && task.getNode().getNumSubOrdinates() <= 100;
   }
 
-
   /**
    * Recompute the rendering props of a node (text, style, icon) depending on.
    *    - the state of this node
    *    - the LDAPEntry displayed by this node
    * @param node the node to be rendered.
    * @param entry the search result for the entry that the node represents.
+   * @return whether the node display changed
    */
   private boolean updateNodeRendering(BasicNode node, SearchResultEntry entry)
   throws NamingException {
@@ -1545,58 +1473,7 @@
     Icon newIcon = getNewIcon(node, entry);
 
     // Construct the icon text according the dn, the aci count...
-    StringBuilder sb2 = new StringBuilder();
-    if (aciCount >= 1) {
-      sb2.append(aciCount);
-      sb2.append(" aci");
-      if (aciCount != 1) {
-        sb2.append("s");
-      }
-    }
-
-    StringBuilder sb1 = new StringBuilder();
-    if (node instanceof SuffixNode) {
-      if (entry != null) {
-        sb1.append(entry.getName());
-      }
-    } else {
-      boolean useRdn = true;
-      if (!RDN_ATTRIBUTE.equals(displayAttribute) && entry != null) {
-        String value = firstValueAsString(entry, displayAttribute);
-        if (value != null) {
-          if (showAttributeName) {
-            value = displayAttribute+"="+value;
-          }
-          sb1.append(value);
-          useRdn = false;
-        }
-      }
-
-      if (useRdn) {
-        String rdn;
-        if (followReferrals && node.getRemoteUrl() != null) {
-          if (showAttributeName) {
-            rdn = node.getRemoteRDNWithAttributeName();
-          } else {
-            rdn = node.getRemoteRDN();
-          }
-        }
-        else {
-          if (showAttributeName) {
-            rdn = node.getRDNWithAttributeName();
-          } else {
-            rdn = node.getRDN();
-          }
-        }
-        sb1.append(rdn);
-      }
-    }
-    if (sb2.length() >= 1) {
-      sb1.append("  (");
-      sb1.append(sb2);
-      sb1.append(")");
-    }
-    String newDisplayName = sb1.toString();
+    String newDisplayName = newDisplayName(node, entry, aciCount);
 
     // Select the font style according referral
     int newStyle = 0;
@@ -1613,8 +1490,79 @@
       node.setIcon(newIcon);
       node.setDisplayName(newDisplayName);
       node.setFontStyle(newStyle);
+      return true;
     }
-    return changed;
+    return false;
+  }
+
+  private String newDisplayName(BasicNode node, SearchResultEntry entry, int aciCount)
+  {
+    StringBuilder result = new StringBuilder();
+    if (node instanceof SuffixNode)
+    {
+      if (entry != null)
+      {
+        result.append(entry.getName());
+      }
+    }
+    else
+    {
+      boolean useRdn = true;
+      if (!RDN_ATTRIBUTE.equals(displayAttribute) && entry != null)
+      {
+        String value = firstValueAsString(entry, displayAttribute);
+        if (value != null)
+        {
+          if (showAttributeName)
+          {
+            value = displayAttribute + "=" + value;
+          }
+          result.append(value);
+          useRdn = false;
+        }
+      }
+
+      if (useRdn)
+      {
+        result.append(getRDN(node));
+      }
+    }
+
+    StringBuilder acis = new StringBuilder();
+    if (aciCount >= 1)
+    {
+      acis.append(aciCount);
+      acis.append(" aci");
+      if (aciCount != 1)
+      {
+        acis.append("s");
+      }
+    }
+    if (acis.length() >= 1)
+    {
+      result.append("  (");
+      result.append(acis);
+      result.append(")");
+    }
+    return result.toString();
+  }
+
+  private String getRDN(BasicNode node)
+  {
+    if (followReferrals && node.getRemoteUrl() != null) {
+      if (showAttributeName) {
+        return node.getRemoteRDNWithAttributeName();
+      } else {
+        return node.getRemoteRDN();
+      }
+    }
+    else {
+      if (showAttributeName) {
+        return node.getRDNWithAttributeName();
+      } else {
+        return node.getRDN();
+      }
+    }
   }
 
   private int getAciCount(SearchResultEntry entry) throws NamingException
@@ -1625,7 +1573,6 @@
     return 0;
   }
 
-
   private Icon getNewIcon(BasicNode node, SearchResultEntry entry)
   {
     // Select the icon according the objectClass,...
@@ -1690,7 +1637,6 @@
     treeModel.removeNodeFromParent(node);
   }
 
-
   /**
    * BrowserEvent management
    * =======================
@@ -1730,7 +1676,6 @@
     return refreshQueue.size();
   }
 
-
   /**
    * Fires a BrowserEvent.
    * @param type the type of the event.
@@ -1754,7 +1699,7 @@
    * Find a SuffixNode in the tree model.
    * @param suffixDn the dn of the suffix node.
    * @param suffixNode the node from which we start searching.
-   * @return the SuffixNode associated with the provided DN.  <CODE>null</CODE>
+   * @return the SuffixNode associated with the provided DN.  {@code null}
    * if nothing is found.
    * @throws IllegalArgumentException if a node with the given dn exists but
    * is not a suffix node.
@@ -1799,20 +1744,14 @@
     throw new IllegalArgumentException(suffixDn + " is not a suffix node");
   }
 
-
-
   /**
-   * Return <CODE>true</CODE> if x is a non <code>null</code>
-   * NameNotFoundException.
-   * @return <CODE>true</CODE> if x is a non <code>null</code>
-   * NameNotFoundException.
+   * Return {@code true} if x is a non {@code null} NameNotFoundException.
+   * @return {@code true} if x is a non {@code null} NameNotFoundException.
    */
   private boolean isNameNotFoundException(Object x) {
     return x instanceof NameNotFoundException;
   }
 
-
-
   /**
    * Get the value of the numSubordinates attribute.
    * If numSubordinates is not present, returns 0.
@@ -1863,7 +1802,6 @@
     return toInt(v);
   }
 
-
   private static int toInt(String v)
   {
     if (v == null)
@@ -1903,13 +1841,12 @@
     return getNumSubOrdinates(entry) > 0;
   }
 
-
   /**
    * Returns the value of the 'ref' attribute.
-   * <CODE>null</CODE> if the attribute is not present.
+   * {@code null} if the attribute is not present.
    * @param entry the entry to analyze.
    * @throws NamingException if an error occurs.
-   * @return the value of the ref attribute.  <CODE>null</CODE> if the attribute
+   * @return the value of the ref attribute.  {@code null} if the attribute
    * could not be found.
    */
   public static String[] getReferral(SearchResultEntry entry) throws NamingException
@@ -1926,12 +1863,10 @@
     return null;
   }
 
-
   /**
    * Returns true if the node is expanded.
    * @param node the node to analyze.
-   * @return <CODE>true</CODE> if the node is expanded and <CODE>false</CODE>
-   * otherwise.
+   * @return {@code true} if the node is expanded and {@code false} otherwise.
    */
   public boolean nodeIsExpanded(BasicNode node) {
     TreePath tp = new TreePath(treeModel.getPathToRoot(node));
@@ -1951,8 +1886,6 @@
     automaticallyExpandedNode = false;
   }
 
-
-
   /** Collection utilities. */
   /**
    * Returns an array of integer from a Collection of Integer objects.
@@ -1970,7 +1903,6 @@
     return result;
   }
 
-
   /**
    * For debugging purpose: allows to switch easily
    * between invokeLater() and invokeAndWait() for
@@ -1991,7 +1923,6 @@
     }
   }
 
-
   /** The default implementation of the BrowserNodeInfo interface. */
   private class BrowserNodeInfoImpl implements BrowserNodeInfo
   {
@@ -2071,8 +2002,7 @@
 
     /**
      * Tells whether this is a root node or not.
-     * @return <CODE>true</CODE> if this is a root node and <CODE>false</CODE>
-     * otherwise.
+     * @return {@code true} if this is a root node and {@code false} otherwise.
      */
     @Override
     public boolean isRootNode() {
@@ -2081,8 +2011,7 @@
 
     /**
      * Tells whether this is a suffix node or not.
-     * @return <CODE>true</CODE> if this is a suffix node and <CODE>false</CODE>
-     * otherwise.
+     * @return {@code true} if this is a suffix node and {@code false} otherwise.
      */
     @Override
     public boolean isSuffix() {
@@ -2091,8 +2020,7 @@
 
     /**
      * Tells whether this is a remote node or not.
-     * @return <CODE>true</CODE> if this is a remote node and <CODE>false</CODE>
-     * otherwise.
+     * @return {@code true} if this is a remote node and {@code false} otherwise.
      */
     @Override
     public boolean isRemote() {
@@ -2131,9 +2059,9 @@
 
     /**
      * Returns the error type associated we got when refreshing the node.
-     * <CODE>null</CODE> if no error was found.
+     * {@code null} if no error was found.
      * @return the error type associated we got when refreshing the node.
-     * <CODE>null</CODE> if no error was found.
+     * {@code null} if no error was found.
      */
     @Override
     public int getErrorType() {
@@ -2142,9 +2070,9 @@
 
     /**
      * Returns the exception associated we got when refreshing the node.
-     * <CODE>null</CODE> if no exception was found.
+     * {@code null} if no exception was found.
      * @return the exception associated we got when refreshing the node.
-     * <CODE>null</CODE> if no exception was found.
+     * {@code null} if no exception was found.
      */
     @Override
     public Exception getErrorException() {
@@ -2153,9 +2081,9 @@
 
     /**
      * Returns the error argument associated we got when refreshing the node.
-     * <CODE>null</CODE> if no error argument was found.
+     * {@code null} if no error argument was found.
      * @return the error argument associated we got when refreshing the node.
-     * <CODE>null</CODE> if no error argument was found.
+     * {@code null} if no error argument was found.
      */
     @Override
     public Object getErrorArg() {
@@ -2192,8 +2120,8 @@
     /**
      * Compares the provide node with this object.
      * @param node the node.
-     * @return <CODE>true</CODE> if the node info represents the same node as
-     * this and <CODE>false</CODE> otherwise.
+     * @return {@code true} if the node info represents the same node as
+     * this and {@code false} otherwise.
      */
     @Override
     public boolean representsSameNode(BrowserNodeInfo node) {
@@ -2201,19 +2129,17 @@
     }
   }
 
-
   /**
    * Returns whether we are in automatic expand mode.  This mode is used when
    * the user specifies a filter and all the nodes are automatically expanded.
-   * @return <CODE>true</CODE> if we are in automatic expand mode and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if we are in automatic expand mode and
+   * {@code false} otherwise.
    */
   public boolean isAutomaticExpand()
   {
     return automaticExpand;
   }
 
-
   /**
    * Sets the automatic expand mode.
    * @param automaticExpand whether to expand automatically the nodes or not.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
index e7b1a2e..6fe7815 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -124,7 +124,7 @@
   }
 
   /**
-   * Returns the remote entry for the node.  It will be <CODE>null</CODE> if
+   * Returns the remote entry for the node.  It will be {@code null} if
    * the entry is not a referral.
    * @return the remote entry for the node.
    */
@@ -133,7 +133,7 @@
   }
 
   /**
-   * Returns the URL of the remote entry.  It will be <CODE>null</CODE> if
+   * Returns the URL of the remote entry.  It will be {@code null} if
    * the entry is not a referral.
    * @return the URL of the remote entry.
    */
@@ -143,8 +143,7 @@
 
   /**
    * Tells whether the node is a leaf or not.
-   * @return <CODE>true</CODE> if the node is a leaf and <CODE>false</CODE>
-   * otherwise.
+   * @return {@code true} if the node is a leaf and {@code false} otherwise.
    */
   public boolean isLeafNode() {
     return isLeafNode;
@@ -159,10 +158,9 @@
   }
 
   /**
-   * Returns whether this refresher object is working on differential mode or
-   * not.
-   * @return <CODE>true</CODE> if the refresher is working on differential
-   * mode and <CODE>false</CODE> otherwise.
+   * Returns whether this refresher object is working on differential mode or not.
+   * @return {@code true} if the refresher is working on differential
+   * mode and {@code false} otherwise.
    */
   public boolean isDifferential() {
     return differential;
@@ -170,7 +168,7 @@
 
   /**
    * Returns the exception that occurred during the processing.  It returns
-   * <CODE>null</CODE> if no exception occurred.
+   * {@code null} if no exception occurred.
    * @return the exception that occurred during the processing.
    */
   public Exception getException() {
@@ -179,7 +177,7 @@
 
   /**
    * Returns the argument of the exception that occurred during the processing.
-   * It returns <CODE>null</CODE> if no exception occurred or if the exception
+   * It returns {@code null} if no exception occurred or if the exception
    * has no arguments.
    * @return the argument exception that occurred during the processing.
    */
@@ -211,21 +209,20 @@
    * otherwise.
    */
   public LDAPURL getDisplayedUrl() {
-    LDAPURL result;
     if (controller.getFollowReferrals() && remoteUrl != null)
     {
-      result = remoteUrl;
+      return remoteUrl;
     }
-    else {
-      result = controller.findUrlForLocalEntry(getNode());
+    else
+    {
+      return controller.findUrlForLocalEntry(getNode());
     }
-    return result;
   }
 
   /**
    * Returns whether the refresh is over or not.
-   * @return <CODE>true</CODE> if the refresh is over and <CODE>false</CODE>
-   * otherwise.
+   *
+   * @return {@code true} if the refresh is over and {@code false} otherwise.
    */
   public boolean isInFinalState() {
     return state == State.FINISHED || state == State.CANCELLED || state == State.FAILED || state == State.INTERRUPTED;
@@ -293,16 +290,11 @@
   /**
    * Tells whether a custom filter is being used (specified by the user in the
    * browser dialog) or not.
-   * @return <CODE>true</CODE> if a custom filter is being used and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if a custom filter is being used and {@code false} otherwise.
    */
   private boolean useCustomFilter()
   {
-    if (controller.getFilter()!=null)
-    {
-      return !BrowserController.ALL_OBJECTS_FILTER.equals(controller.getFilter());
-    }
-    return false;
+    return controller.getFilter() != null && !BrowserController.ALL_OBJECTS_FILTER.equals(controller.getFilter());
   }
 
   /**
@@ -408,14 +400,8 @@
         SearchRequest request =
             newSearchRequest(node.getDN(), BASE_OBJECT, filter, controller.getAttrsForRedSearch())
             .setSizeLimit(controller.getMaxChildren());
-        try (ConnectionEntryReader s = conn.getConnection().search(request))
-        {
-          while (s.hasNext())
-          {
-            localEntry = s.readEntry();
-            localEntry.setName(node.getDN());
-          }
-        }
+        localEntry = conn.getConnection().searchSingleEntry(request);
+        localEntry.setName(node.getDN());
         if (localEntry == null) {
           /* Not enough rights to read the entry or the entry simply does not exist */
           throw newLdapException(ResultCode.NO_SUCH_OBJECT, "Can't find entry: " + node.getDN());
@@ -485,11 +471,11 @@
         if (url.getHost() == null)
         {
           // Use the local server connection.
-          conn = controller.getUserDataConnection();
-          HostPort hostPort = conn.getHostPort();
+          ConnectionWrapper userConn = controller.getUserDataConnection();
+          HostPort hostPort = userConn.getHostPort();
           url.setHost(hostPort.getHost());
           url.setPort(hostPort.getPort());
-          url.setScheme(conn.isLdaps() ? "ldaps" : "ldap");
+          url.setScheme(userConn.isLdaps() ? "ldaps" : "ldap");
         }
         conn = connectionPool.getConnection(url);
         remoteDn = url.getRawBaseDN();
@@ -595,8 +581,7 @@
    * This is used when the user provides a custom filter, in this case we
    * expand automatically the tree.
    * @param node the node to analyze.
-   * @return <CODE>true</CODE> if the node must be expanded and
-   * <CODE>false</CODE> otherwise.
+   * @return {@code true} if the node must be expanded and {@code false} otherwise.
    */
   private boolean mustAutomaticallyExpand(BasicNode node)
   {
@@ -887,16 +872,9 @@
         newSearchRequest(dn, BASE_OBJECT, controller.getObjectSearchFilter(), controller.getAttrsForRedSearch())
         .setSizeLimit(controller.getMaxChildren());
 
-    try (ConnectionEntryReader entries = conn.getConnection().search(request))
-    {
-      SearchResultEntry sr = null;
-      while (entries.hasNext())
-      {
-        sr = entries.readEntry();
-        sr.setName(dn);
-      }
-      return sr;
-    }
+    SearchResultEntry sr = conn.getConnection().searchSingleEntry(request);
+    sr.setName(dn);
+    return sr;
   }
 
   /** Utilities. */
@@ -924,21 +902,15 @@
    * @throws SearchAbandonException if the task/refresher must be abandoned.
    */
   private void throwAbandonIfNeeded(Exception x) throws SearchAbandonException {
-    SearchAbandonException tax = null;
     if (x != null) {
       if (x instanceof InterruptedException || x instanceof InterruptedNamingException)
       {
-        tax = new SearchAbandonException(State.INTERRUPTED, x, null);
+        throw new SearchAbandonException(State.INTERRUPTED, x, null);
       }
-      else {
-        tax = new SearchAbandonException(State.FAILED, x, null);
-      }
+      throw new SearchAbandonException(State.FAILED, x, null);
     }
     else if (isCanceled()) {
-      tax = new SearchAbandonException(State.CANCELLED, null, null);
-    }
-    if (tax != null) {
-      throw tax;
+      throw new SearchAbandonException(State.CANCELLED, null, null);
     }
   }
 
@@ -989,8 +961,8 @@
    * Checks that the entry's objectClass contains 'referral' and that the
    * attribute 'ref' is present.
    * @param entry the search result.
-   * @return <CODE>true</CODE> if the entry's objectClass contains 'referral'
-   * and the attribute 'ref' is present and <CODE>false</CODE> otherwise.
+   * @return {@code true} if the entry's objectClass contains 'referral'
+   * and the attribute 'ref' is present and {@code false} otherwise.
    * @throws NamingException if an error occurs.
    */
   private static boolean isReferralEntry(SearchResultEntry entry) throws NamingException
@@ -1006,42 +978,6 @@
   }
 
   /**
-   * Returns the scope to be used in a JNDI request based on the information
-   * of an LDAP URL.
-   * @param url the LDAP URL.
-   * @return the scope to be used in a JNDI request.
-   */
-  private int getJNDIScope(LDAPURL url)
-  {
-    int scope;
-    if (url.getScope() != null)
-    {
-      switch (url.getScope().asEnum())
-      {
-      case BASE_OBJECT:
-        scope = SearchControls.OBJECT_SCOPE;
-        break;
-      case WHOLE_SUBTREE:
-        scope = SearchControls.SUBTREE_SCOPE;
-        break;
-      case SUBORDINATES:
-        scope = SearchControls.ONELEVEL_SCOPE;
-        break;
-      case SINGLE_LEVEL:
-        scope = SearchControls.ONELEVEL_SCOPE;
-        break;
-      default:
-        scope = SearchControls.OBJECT_SCOPE;
-      }
-    }
-    else
-    {
-      scope = SearchControls.OBJECT_SCOPE;
-    }
-    return scope;
-  }
-
-  /**
    * Returns the filter to be used in a JNDI request based on the information
    * of an LDAP URL.
    * @param url the LDAP URL.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewEntryTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewEntryTask.java
index b7d137e..03a7bfb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewEntryTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewEntryTask.java
@@ -218,17 +218,13 @@
             {
               insertNode(realParentNode, newEntry.getName(), false);
             }
-            else
+            else if (isBaseDN(newEntry.getName()))
             {
-              if (isBaseDN(newEntry.getName()))
+              int nRootChildren = controller.getTreeModel().getChildCount(controller.getTreeModel().getRoot());
+              if (nRootChildren > 1)
               {
-                int nRootChildren = controller.getTreeModel().getChildCount(
-                  controller.getTreeModel().getRoot());
-                if (nRootChildren > 1)
-                {
-                  // Insert in the root.
-                  insertNode(root, newEntry.getName(), true);
-                }
+                // Insert in the root.
+                insertNode(root, newEntry.getName(), true);
               }
             }
           }
@@ -303,29 +299,23 @@
 
   private void insertNode(BasicNode parentNode, DN dn, boolean isSuffix)
   {
-    TreePath parentPath =
-      new TreePath(controller.getTreeModel().getPathToRoot(parentNode));
-    if (parentPath != null)
+    TreePath parentPath = new TreePath(controller.getTreeModel().getPathToRoot(parentNode));
+    BrowserNodeInfo nodeInfo = controller.getNodeInfoFromPath(parentPath);
+    if (nodeInfo != null)
     {
-      BrowserNodeInfo nodeInfo =
-        controller.getNodeInfoFromPath(parentPath);
-      if (nodeInfo != null)
+      TreePath newPath;
+      if (isSuffix)
       {
-        TreePath newPath;
-        if (isSuffix)
-        {
-          newPath = controller.addSuffix(dn.toString(), parentNode.getDN());
-        }
-        else
-        {
-          newPath = controller.notifyEntryAdded(
-            controller.getNodeInfoFromPath(parentPath), dn.toString());
-        }
-        if (newPath != null)
-        {
-          controller.getTree().setSelectionPath(newPath);
-          controller.getTree().scrollPathToVisible(newPath);
-        }
+        newPath = controller.addSuffix(dn.toString(), parentNode.getDN());
+      }
+      else
+      {
+        newPath = controller.notifyEntryAdded(controller.getNodeInfoFromPath(parentPath), dn.toString());
+      }
+      if (newPath != null)
+      {
+        controller.getTree().setSelectionPath(newPath);
+        controller.getTree().scrollPathToVisible(newPath);
       }
     }
   }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
index 9e073bd..e38db37 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -128,7 +128,6 @@
   private static final String[] SYSTEM_INDEXES =
     { "aci", "dn2id", "ds-sync-hist", "entryUUID", "id2children", "id2subtree" };
 
-
   private JComboBox<String> baseDNs;
 
   /** The combo box containing the different filter types. */
@@ -971,7 +970,6 @@
     });
   }
 
-
   private static boolean displayIndex(String name)
   {
     for (String systemIndex : SYSTEM_INDEXES)
@@ -1319,12 +1317,8 @@
             {
               for (BaseDNDescriptor baseDN : backend.getBaseDns())
               {
-                boolean isBaseDN = false;
                 String dn = Utilities.unescapeUtf8(baseDN.getDn().toString());
-                if (theDN != null && baseDN.getDn().equals(theDN))
-                {
-                  isBaseDN = true;
-                }
+                boolean isBaseDN = baseDN.getDn().equals(theDN);
                 if (baseDN.getEntries() > 0)
                 {
                   try
@@ -1460,63 +1454,69 @@
             null, INFO_CERTIFICATE_EXCEPTION.get(h, p), ne, h, p, trustManager.getLastRefusedChain(),
             trustManager.getLastRefusedAuthType(), excType);
 
-        if (SwingUtilities.isEventDispatchThread())
-        {
-          handleCertificateException(udce, bindDN, bindPassword);
-        }
-        else
-        {
-          final ConfigReadException[] fcre = { null };
-          final NamingException[] fne = { null };
-          final IOException[] fioe = { null };
-          try
-          {
-            SwingUtilities.invokeAndWait(new Runnable()
-            {
-              @Override
-              public void run()
-              {
-                try
-                {
-                  handleCertificateException(udce, bindDN, bindPassword);
-                }
-                catch (ConfigReadException cre)
-                {
-                  fcre[0] = cre;
-                }
-                catch (NamingException ne)
-                {
-                  fne[0] = ne;
-                }
-                catch (IOException ioe)
-                {
-                  fioe[0] = ioe;
-                }
-              }
-            });
-          }
-          catch (Exception e)
-          {
-            throw new IllegalArgumentException("Unexpected error: " + e, e);
-          }
-          if (fcre[0] != null)
-          {
-            throw fcre[0];
-          }
-          if (fne[0] != null)
-          {
-            throw fne[0];
-          }
-          if (fioe[0] != null)
-          {
-            throw fioe[0];
-          }
-        }
+        handleCertificateExceptionInSwing(bindDN, bindPassword, udce);
       }
     }
     return createdUserDataConn;
   }
 
+  private void handleCertificateExceptionInSwing(final DN bindDN, final String bindPassword,
+      final UserDataCertificateException udce) throws NamingException, IOException, ConfigReadException
+  {
+    if (SwingUtilities.isEventDispatchThread())
+    {
+      handleCertificateException(udce, bindDN, bindPassword);
+    }
+    else
+    {
+      final ConfigReadException[] fcre = { null };
+      final NamingException[] fne = { null };
+      final IOException[] fioe = { null };
+      try
+      {
+        SwingUtilities.invokeAndWait(new Runnable()
+        {
+          @Override
+          public void run()
+          {
+            try
+            {
+              handleCertificateException(udce, bindDN, bindPassword);
+            }
+            catch (ConfigReadException cre)
+            {
+              fcre[0] = cre;
+            }
+            catch (NamingException ne)
+            {
+              fne[0] = ne;
+            }
+            catch (IOException ioe)
+            {
+              fioe[0] = ioe;
+            }
+          }
+        });
+      }
+      catch (Exception e)
+      {
+        throw new IllegalArgumentException("Unexpected error: " + e, e);
+      }
+      if (fcre[0] != null)
+      {
+        throw fcre[0];
+      }
+      if (fne[0] != null)
+      {
+        throw fne[0];
+      }
+      if (fioe[0] != null)
+      {
+        throw fioe[0];
+      }
+    }
+  }
+
   /**
    * Displays a dialog asking the user to accept a certificate if the user
    * accepts it, we update the trust manager and simulate a click on "OK" to

--
Gitblit v1.10.0