From a3c93828f847345ed67fda0cddf1089d8fb433d5 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 07 Mar 2016 15:04:03 +0000
Subject: [PATCH] OPENDJ-1342 Migrate AVA, RDN, and DN classes: DirectoryException => LocalizedIllegalArgumentException

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java |   70 +++++++++++------------------------
 1 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
index c0ef2ce..3f6f8fe 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
@@ -36,23 +36,20 @@
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.LocalizedIllegalArgumentException;
+import org.forgerock.opendj.ldap.DN;
 import org.opends.guitools.controlpanel.browser.BrowserController;
 import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
 import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
 import org.opends.guitools.controlpanel.util.BackgroundTask;
 import org.opends.guitools.controlpanel.util.LDAPEntryReader;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.DirectoryException;
 import org.opends.server.util.Base64;
 import org.opends.server.util.LDIFException;
 import org.opends.server.util.ServerConstants;
 
-/**
- * The panel used to duplicate an entry.
- *
- */
+/** The panel used to duplicate an entry. */
 public class DuplicateEntryPanel extends AbstractNewEntryPanel
 {
   private static final long serialVersionUID = -9879879123123123L;
@@ -122,25 +119,18 @@
 
     DN aParentDN;
     String aRdn;
-    try
+    DN nodeDN = DN.valueOf(node.getDN());
+    if (nodeDN.isRootDN())
     {
-      DN nodeDN = DN.valueOf(node.getDN());
-      if (nodeDN.isRootDN())
-      {
-        aParentDN = nodeDN;
-        aRdn = "(1)";
-      }
-      else
-      {
-        aParentDN = nodeDN.parent();
-        aRdn = nodeDN.rdn().getFirstAVA().getAttributeValue() + "-1";
-      }
+      aParentDN = nodeDN;
+      aRdn = "(1)";
     }
-    catch (DirectoryException de)
+    else
     {
-      throw new IllegalStateException("Unexpected error decoding dn: '"+
-          node.getDN()+"' error: "+de, de);
+      aParentDN = nodeDN.parent();
+      aRdn = nodeDN.rdn().getFirstAVA().getAttributeValue() + "-1";
     }
+
     parentDN.setText(aParentDN != null ? aParentDN.toString() : "");
     name.setText(aRdn);
     password.setText("");
@@ -149,7 +139,7 @@
     readEntry(node);
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected LocalizableMessage getProgressDialogTitle()
   {
     return INFO_CTRL_PANEL_DUPLICATE_ENTRY_TITLE.get();
@@ -392,17 +382,7 @@
       }
       else
       {
-        String newValue;
-        try
-        {
-          DN theDN = DN.valueOf(dn);
-          newValue = theDN.rdn().getFirstAVA().getAttributeValue().toString();
-        }
-        catch (DirectoryException de)
-        {
-          throw new IllegalStateException("Unexpected error with dn: '"+dn+
-              "' "+de, de);
-        }
+        String newValue = getFirstValue(dn);
         if (values.size() == 1)
         {
           sb.append("\n");
@@ -410,17 +390,7 @@
         }
         else
         {
-          String oldValue;
-          try
-          {
-            DN oldDN = DN.valueOf(entryToDuplicate.getDN());
-            oldValue = oldDN.rdn().getFirstAVA().getAttributeValue().toString();
-          }
-          catch (DirectoryException de)
-          {
-            throw new IllegalStateException("Unexpected error with dn: '"+
-                entryToDuplicate.getDN()+"' "+de, de);
-          }
+          String oldValue = getFirstValue(entryToDuplicate.getDN());
           for (Object value : values)
           {
             sb.append("\n");
@@ -439,6 +409,11 @@
     return sb.toString();
   }
 
+  private String getFirstValue(String dn)
+  {
+    return DN.valueOf(dn).rdn().getFirstAVA().getAttributeValue().toString();
+  }
+
   private void browseClicked()
   {
     if (browseDlg == null)
@@ -510,10 +485,9 @@
             displayMainPanel();
             setEnabledOK(true);
           }
-          catch (DirectoryException de)
+          catch (LocalizedIllegalArgumentException e)
           {
-            displayErrorMessage(INFO_CTRL_PANEL_ERROR_DIALOG_TITLE.get(),
-                de.getMessageObject());
+            displayErrorMessage(INFO_CTRL_PANEL_ERROR_DIALOG_TITLE.get(), e.getMessageObject());
           }
         }
       }

--
Gitblit v1.10.0