From e1cd6c2bc4addf80537e31f929118ac8f908ea63 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 23 Mar 2015 14:51:59 +0000
Subject: [PATCH] AutoRefactored javadocs + simplified code in equals()
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java | 114 +++-------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java | 67 ++---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/VLVSortOrder.java | 30 +-
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java | 59 +---
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java | 51 +---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java | 104 ++++-----
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ScheduleType.java | 69 +----
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlerDescriptor.java | 30 -
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java | 125 +++-------
9 files changed, 225 insertions(+), 424 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
index 7368a1d..1b30d8e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
@@ -22,9 +22,8 @@
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2013 ForgeRock AS.
+ * Portions Copyright 2013-2015 ForgeRock AS.
*/
-
package org.opends.admin.ads.util;
import java.util.LinkedHashSet;
@@ -38,27 +37,20 @@
*/
public class PreferredConnection
{
- private String ldapUrl;
- private Type type;
- /**
- * The type of the connection.
- */
+ /** The type of the connection. */
public enum Type
{
- /**
- * LDAP connection.
- */
+ /** LDAP connection. */
LDAP,
- /**
- * LDAPS connection.
- */
+ /** LDAPS connection. */
LDAPS,
- /**
- * Start TLS connection.
- */
+ /** Start TLS connection. */
START_TLS
}
+ private String ldapUrl;
+ private Type type;
+
/**
* The constructor of the PreferredConnection.
* @param ldapUrl the LDAP URL to connect to the server.
@@ -89,35 +81,26 @@
return type;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode()
{
return (type+ldapUrl.toLowerCase()).hashCode();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals = false;
- if (this != o)
+ if (this == o)
{
- if ((o != null) &&
- (o instanceof PreferredConnection))
- {
- PreferredConnection p = (PreferredConnection)o;
- equals = type == p.getType() &&
- ldapUrl.equalsIgnoreCase(p.getLDAPURL());
- }
+ return true;
}
- else
+ if (o instanceof PreferredConnection)
{
- equals = true;
+ PreferredConnection p = (PreferredConnection)o;
+ return type == p.getType()
+ && ldapUrl.equalsIgnoreCase(p.getLDAPURL());
}
- return equals;
+ return false;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
index 42fe496..edb7385 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BackendDescriptor.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2008-2011 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
+ * Portions Copyright 2014-2015 ForgeRock AS
*/
package org.opends.guitools.controlpanel.datamodel;
@@ -32,10 +32,7 @@
import org.opends.admin.ads.ADSContext;
-/**
- * The class that describes the backend configuration.
- *
- */
+/** The class that describes the backend configuration. */
public class BackendDescriptor
{
private final String backendID;
@@ -49,40 +46,24 @@
private final Type type;
private int hashCode;
- /**
- * An enumeration describing the type of backend.
- */
+ /** An enumeration describing the type of backend. */
public enum Type
{
- /**
- * The backend is a local backend.
- */
+ /** The backend is a local backend. */
LOCAL_DB,
- /**
- * The backend is a LDIF backend.
- */
+ /** The backend is a LDIF backend. */
LDIF,
- /**
- * The backend is a memory backend.
- */
+ /** The backend is a memory backend. */
MEMORY,
- /**
- * The backend is a backup backend.
- */
+ /** The backend is a backup backend. */
BACKUP,
- /**
- * The backend is a monitor backend.
- */
+ /** The backend is a monitor backend. */
MONITOR,
- /**
- * The backend is a task backend.
- */
+ /** The backend is a task backend. */
TASK,
- /**
- * The backend is another type of backend (for instance user defined).
- */
+ /** The backend is another type of backend (for instance user defined). */
OTHER
- };
+ }
/**
* Constructor for this class.
@@ -156,55 +137,34 @@
return entries;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
- public boolean equals(Object v)
+ public boolean equals(Object o)
{
- boolean equals = false;
- if (this != v)
+ if (this == o)
{
- if (v instanceof BackendDescriptor)
- {
- BackendDescriptor desc = (BackendDescriptor)v;
- equals = getBackendID().equals(desc.getBackendID()) &&
- (getEntries() == desc.getEntries());
-
- if (equals)
- {
- equals = desc.getBaseDns().equals(getBaseDns());
- }
-
- if (equals)
- {
- equals = desc.getIndexes().equals(getIndexes());
- }
-
- if (equals)
- {
- equals = desc.getVLVIndexes().equals(getVLVIndexes());
- }
-
- if (equals)
- {
- // Compare monitoring entries
- if (getMonitoringEntry() == null)
- {
- equals = desc.getMonitoringEntry() == null;
- }
- else
- {
- equals = getMonitoringEntry().equals(desc.getMonitoringEntry());
- }
- }
- }
+ return true;
}
- else
+ if (o instanceof BackendDescriptor)
{
- equals = true;
+ BackendDescriptor desc = (BackendDescriptor)o;
+ return getBackendID().equals(desc.getBackendID())
+ && getEntries() == desc.getEntries()
+ && desc.getBaseDns().equals(getBaseDns())
+ && desc.getIndexes().equals(getIndexes())
+ && desc.getVLVIndexes().equals(getVLVIndexes())
+ && equal(getMonitoringEntry(), desc.getMonitoringEntry());
}
- return equals;
+ return false;
+ }
+
+ private boolean equal(CustomSearchResult m1, CustomSearchResult m2)
+ {
+ if (m1 == null)
+ {
+ return m2 == null;
+ }
+ return m1.equals(m2);
}
/**
@@ -216,9 +176,7 @@
return monitoringEntry;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public int hashCode()
{
@@ -229,7 +187,6 @@
* Method called when one of the elements that affect the value of the
* hashcode is modified. It is used to minimize the time spent calculating
* hashCode.
- *
*/
private void recalculateHashCode()
{
@@ -259,8 +216,7 @@
*
*/
private void updateBaseDnsAndIndexes(Set<BaseDNDescriptor> baseDns,
- Set<IndexDescriptor> indexes,
- Set<VLVIndexDescriptor> vlvIndexes)
+ Set<IndexDescriptor> indexes, Set<VLVIndexDescriptor> vlvIndexes)
{
for (BaseDNDescriptor baseDN : baseDns)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
index d3d2623..64835be 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
@@ -167,69 +167,59 @@
return file;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals = false;
- if (o != null)
+ if (this == o)
{
- equals = this == o;
- if (!equals)
- {
- equals = o instanceof BinaryValue;
- if (equals)
- {
- BinaryValue candidate = (BinaryValue)o;
- equals = candidate.getType() == getType();
- if (equals)
- {
- if (file == null)
- {
- equals = candidate.getFile() == null;
- }
- else if (candidate.getFile() != null)
- {
- equals = file.equals(candidate.getFile());
- }
- else
- {
- equals = false;
- }
- }
- if (equals)
- {
- if (type == Type.BASE64_STRING)
- {
- equals = candidate.getBase64().equals(getBase64());
- }
- else
- {
- try
- {
- equals = candidate.getBytes().length == getBytes().length;
- for (int i=0; i<getBytes().length && equals; i++)
- {
- equals = bytes[i] == candidate.getBytes()[i];
- }
- }
- catch (ParseException pe)
- {
- throw new RuntimeException(
- "Unexpected error getting bytes: "+pe, pe);
- }
- }
- }
- }
- }
+ return true;
}
- return equals;
+ if (o instanceof BinaryValue)
+ {
+ BinaryValue candidate = (BinaryValue)o;
+ return candidate.getType() == getType()
+ && equal(file, candidate.getFile())
+ && bytesEqual(candidate);
+ }
+ return false;
}
- /**
- * {@inheritDoc}
- */
+ private boolean equal(File o1, File o2)
+ {
+ if (o1 == null)
+ {
+ return o2 == null;
+ }
+ return o1.equals(o2);
+ }
+
+ private boolean bytesEqual(BinaryValue candidate)
+ {
+ if (type == Type.BASE64_STRING)
+ {
+ return candidate.getBase64().equals(getBase64());
+ }
+
+ try
+ {
+ if (candidate.getBytes().length != getBytes().length) {
+ return false;
+ }
+ boolean equals = true;
+ for (int i=0; i<getBytes().length && equals; i++)
+ {
+ equals = bytes[i] == candidate.getBytes()[i];
+ }
+ return equals;
+ }
+ catch (ParseException pe)
+ {
+ throw new RuntimeException(
+ "Unexpected error getting bytes: "+pe, pe);
+ }
+ }
+
+ /** {@inheritDoc} */
public int hashCode()
{
return hashCode;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlerDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlerDescriptor.java
index ec10871..8b0fae7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlerDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ConnectionHandlerDescriptor.java
@@ -230,47 +230,35 @@
this.monitoringEntries = Collections.unmodifiableSet(monitoringEntries);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public int hashCode()
{
return hashCode;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public String toString()
{
return toString;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
- boolean equals = false;
if (o == this)
{
- equals = true;
+ return true;
}
- else if (o instanceof ConnectionHandlerDescriptor)
+ if (o instanceof ConnectionHandlerDescriptor)
{
- equals = toString.equals(o.toString());
- if (equals)
- {
- ConnectionHandlerDescriptor ch =
- (ConnectionHandlerDescriptor)o;
- // Compare monitoring entries
- equals = (getMonitoringEntries().equals(ch.getMonitoringEntries()));
- }
+ ConnectionHandlerDescriptor ch = (ConnectionHandlerDescriptor) o;
+ return toString.equals(o.toString())
+ && getMonitoringEntries().equals(ch.getMonitoringEntries());
}
- return equals;
+ return false;
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
index f2ac402..6cd0a36 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
@@ -22,9 +22,8 @@
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2014 ForgeRock AS
+ * Portions Copyright 2011-2015 ForgeRock AS
*/
-
package org.opends.guitools.controlpanel.datamodel;
import static org.opends.server.util.StaticUtils.toLowerCase;
@@ -61,7 +60,6 @@
* Basically it retrieves all the attributes and values on the SearchResult and
* calculates its DN. Using it we avoid having to handle the NamingException
* exceptions that most of the methods in SearchResult throw.
- *
*/
public class CustomSearchResult implements Comparable<CustomSearchResult>
{
@@ -193,9 +191,7 @@
return attrNames;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int compareTo(CustomSearchResult o) {
if (this.equals(o))
{
@@ -219,50 +215,41 @@
return sr;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals = false;
- if (o != null)
+ if (o == this)
{
- equals = o == this;
- if (!equals && (o instanceof CustomSearchResult))
- {
- CustomSearchResult sr = (CustomSearchResult)o;
- equals = getDN().equals(sr.getDN());
- if (equals)
- {
- equals = getAttributeNames().equals(sr.getAttributeNames());
- if (equals)
- {
- for (String attrName : getAttributeNames())
- {
- equals = getAttributeValues(attrName).equals(
- sr.getAttributeValues(attrName));
- if (!equals)
- {
- break;
- }
- }
- }
- }
- }
+ return true;
}
- return equals;
+ if (o instanceof CustomSearchResult)
+ {
+ CustomSearchResult sr = (CustomSearchResult)o;
+ return getDN().equals(sr.getDN())
+ && getAttributeNames().equals(sr.getAttributeNames())
+ && attrValuesEqual(sr);
+ }
+ return false;
}
- /**
- * {@inheritDoc}
- */
+ private boolean attrValuesEqual(CustomSearchResult sr)
+ {
+ for (String attrName : getAttributeNames())
+ {
+ if (!getAttributeValues(attrName).equals(sr.getAttributeValues(attrName)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /** {@inheritDoc} */
public String toString() {
return toString;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode() {
return hashCode;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java
index 9429142..597d61e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ObjectClassValue.java
@@ -22,8 +22,8 @@
*
*
* Copyright 2008 Sun Microsystems, Inc.
+ * Portions Copyright 2015 ForgeRock AS.
*/
-
package org.opends.guitools.controlpanel.datamodel;
import java.util.Set;
@@ -34,7 +34,6 @@
* This class represent all the objectclass values for a given entry. It is
* used by the entry editors (SimplifiedEntryView and TableEntryView) to edit
* and display the objectclass.
- *
*/
public class ObjectClassValue
{
@@ -80,54 +79,34 @@
return structural;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode()
{
return hashCode;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals;
- if (o != this)
+ if (this == o)
{
- if (o != null)
- {
- if (o instanceof ObjectClassValue)
- {
- ObjectClassValue oc = (ObjectClassValue)o;
- if (structural != null)
- {
- equals = structural.equals(oc.getStructural());
- }
- else
- {
- equals = oc.getStructural() == null;
- }
- if (equals)
- {
- equals = auxiliary.equals(oc.getAuxiliary());
- }
- }
- else
- {
- equals = false;
- }
- }
- else
- {
- equals = false;
- }
+ return true;
}
- else
+ if (o instanceof ObjectClassValue)
{
- equals = true;
+ ObjectClassValue oc = (ObjectClassValue)o;
+ return equal(structural, oc.getStructural())
+ && auxiliary.equals(oc.getAuxiliary());
}
- return equals;
+ return false;
+ }
+
+ private boolean equal(String s1, String s2)
+ {
+ if (s1 == null)
+ {
+ return s2 == null;
+ }
+ return s1.equals(s2);
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ScheduleType.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ScheduleType.java
index 6a4e8cb..589789a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ScheduleType.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ScheduleType.java
@@ -22,34 +22,23 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
+ * Portions Copyright 2015 ForgeRock AS.
*/
package org.opends.guitools.controlpanel.datamodel;
import java.util.Date;
-/**
- * The class to be used to describe the task schedule.
- *
- */
+/** The class to be used to describe the task schedule. */
public class ScheduleType
{
- /**
- * The different type of schedules.
- *
- */
+ /** The different type of schedules. */
public enum Type
{
- /**
- * Launch now.
- */
+ /** Launch now. */
LAUNCH_NOW,
- /**
- * Launch later in a specific date.
- */
+ /** Launch later in a specific date. */
LAUNCH_LATER,
- /**
- * Launch periodically.
- */
+ /** Launch periodically. */
LAUNCH_PERIODICALLY
}
@@ -133,41 +122,24 @@
return cronValue;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals;
- if (o != null)
+ if (o == this)
{
- if (o == this)
- {
- equals = true;
- }
- else
- {
- equals = toString().equals(o.toString());
- }
+ return true;
}
- else
- {
- equals = false;
- }
- return equals;
+ return o != null
+ && toString().equals(o.toString());
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String toString()
{
return toString;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode()
{
return hashCode;
@@ -185,21 +157,16 @@
private String calculateToString()
{
- String toString;
switch (type)
{
case LAUNCH_NOW:
- toString = "Schedule Type: Launch Now";
- break;
+ return "Schedule Type: Launch Now";
case LAUNCH_LATER:
- toString = "Schedule Type: Launch Later at date "+launchLaterDate;
- break;
+ return "Schedule Type: Launch Later at date " + launchLaterDate;
case LAUNCH_PERIODICALLY:
- toString = "Schedule Type: periodical schedule "+cronValue;
- break;
- default:
- throw new RuntimeException("Invalid type: "+type);
+ return "Schedule Type: periodical schedule " + cronValue;
+ default:
+ throw new RuntimeException("Invalid type: " + type);
}
- return toString;
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/VLVSortOrder.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/VLVSortOrder.java
index 359bb9d..ee0764c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/VLVSortOrder.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/VLVSortOrder.java
@@ -22,8 +22,8 @@
*
*
* Copyright 2008 Sun Microsystems, Inc.
+ * Portions Copyright 2015 ForgeRock AS.
*/
-
package org.opends.guitools.controlpanel.datamodel;
/**
@@ -66,30 +66,24 @@
return isAscending;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int hashCode()
{
return hashCode;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public boolean equals(Object o)
{
- boolean equals = o == this;
- if (!equals)
- {
- equals = o instanceof VLVSortOrder;
- if (equals)
- {
- VLVSortOrder sortOrder = (VLVSortOrder)o;
- equals = sortOrder.getAttributeName().equalsIgnoreCase(attributeName) &&
- sortOrder.isAscending() == isAscending;
- }
+ if (o == this) {
+ return true;
}
- return equals;
+ if (o instanceof VLVSortOrder)
+ {
+ VLVSortOrder sortOrder = (VLVSortOrder)o;
+ return sortOrder.getAttributeName().equalsIgnoreCase(attributeName)
+ && sortOrder.isAscending() == isAscending;
+ }
+ return false;
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java
index cfc6a8c..2e26e7c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java
@@ -22,9 +22,8 @@
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2012-2014 ForgeRock AS
+ * Portions Copyright 2012-2015 ForgeRock AS
*/
-
package org.opends.guitools.controlpanel.ui;
import static org.opends.messages.AdminToolMessages.*;
@@ -44,23 +43,45 @@
import javax.swing.event.DocumentListener;
import javax.swing.tree.TreePath;
+import org.forgerock.i18n.LocalizableMessage;
import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
import org.opends.guitools.controlpanel.task.OfflineUpdateException;
import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.Base64;
-import org.opends.server.util.StaticUtils;
import org.opends.server.util.LDIFReader;
+import org.opends.server.util.StaticUtils;
/**
* The panel displaying an LDIF view of an entry.
- *
*/
public class LDIFViewEntryPanel extends ViewEntryPanel
{
+ /** Callback that sets the viewport's view position. */
+ private static final class SetViewPosition implements Runnable
+ {
+ private final Point p;
+ private final JScrollPane scroll;
+
+ private SetViewPosition(JScrollPane scroll, Point p)
+ {
+ this.p = p;
+ this.scroll = scroll;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void run()
+ {
+ if (p != null && scroll.getViewport().contains(p))
+ {
+ scroll.getViewport().setViewPosition(p);
+ }
+ }
+ }
+
private static final long serialVersionUID = 2775960608128921072L;
private JScrollPane editableScroll;
private JScrollPane readOnlyScroll;
@@ -68,19 +89,13 @@
private JTextArea readOnlyAttributes;
private CustomSearchResult searchResult;
- /**
- * Default constructor.
- *
- */
+ /** Default constructor. */
public LDIFViewEntryPanel()
{
- super();
createLayout();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public Component getPreferredFocusComponent()
{
@@ -89,7 +104,6 @@
/**
* Creates the layout of the panel (but the contents are not populated here).
- *
*/
private void createLayout()
{
@@ -141,8 +155,7 @@
gbc.gridy ++;
add(lReadOnly, gbc);
gbc.insets.top = 5;
- readOnlyAttributes = Utilities.createNonEditableTextArea(LocalizableMessage.EMPTY, 10,
- 30);
+ readOnlyAttributes = Utilities.createNonEditableTextArea(LocalizableMessage.EMPTY, 10, 30);
gbc.weightx = 1.0;
gbc.weighty = 0.4;
gbc.fill = GridBagConstraints.BOTH;
@@ -151,24 +164,20 @@
add(readOnlyScroll, gbc);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void update(CustomSearchResult sr, boolean isReadOnly, TreePath path)
{
boolean sameEntry = false;
- if ((searchResult != null) && (sr != null))
+ if (searchResult != null && sr != null)
{
sameEntry = searchResult.getDN().equals(sr.getDN());
}
searchResult = sr;
-
updateTitle(sr, path);
StringBuilder sb = new StringBuilder();
-
sb.append("dn: ").append(sr.getDN());
if (isReadOnly)
@@ -185,20 +194,7 @@
final Point p1 = sameEntry ?
readOnlyScroll.getViewport().getViewPosition() : new Point(0, 0);
readOnlyAttributes.setText(sb.toString());
- SwingUtilities.invokeLater(new Runnable()
- {
- /**
- * {@inheritDoc}
- */
- @Override
- public void run()
- {
- if ((p1 != null) && (readOnlyScroll.getViewport().contains(p1)))
- {
- readOnlyScroll.getViewport().setViewPosition(p1);
- }
- }
- });
+ SwingUtilities.invokeLater(new SetViewPosition(readOnlyScroll, p1));
}
else
{
@@ -221,20 +217,7 @@
editableAttributes.setText(sb.toString());
ignoreEntryChangeEvents = false;
- SwingUtilities.invokeLater(new Runnable()
- {
- /**
- * {@inheritDoc}
- */
- @Override
- public void run()
- {
- if ((p1 != null) && (editableScroll.getViewport().contains(p1)))
- {
- editableScroll.getViewport().setViewPosition(p1);
- }
- }
- });
+ SwingUtilities.invokeLater(new SetViewPosition(editableScroll, p1));
// Read-only attributes
boolean oneLineAdded = false;
sb = new StringBuilder();
@@ -254,26 +237,11 @@
final Point p2 = sameEntry ?
readOnlyScroll.getViewport().getViewPosition() : new Point(0, 0);
readOnlyAttributes.setText(sb.toString());
- SwingUtilities.invokeLater(new Runnable()
- {
- /**
- * {@inheritDoc}
- */
- @Override
- public void run()
- {
- if ((p2 != null) && (readOnlyScroll.getViewport().contains(p2)))
- {
- readOnlyScroll.getViewport().setViewPosition(p2);
- }
- }
- });
+ SwingUtilities.invokeLater(new SetViewPosition(readOnlyScroll, p2));
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public GenericDialog.ButtonType getButtonType()
{
@@ -281,9 +249,7 @@
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
protected String getDisplayedDN()
{
@@ -302,22 +268,17 @@
return dn;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
protected List<Object> getValues(String attrName)
{
throw new IllegalStateException("This method should not be called.");
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public Entry getEntry() throws OpenDsException
{
- Entry entry = null;
LDIFImportConfig ldifImportConfig = null;
try
{
@@ -325,8 +286,9 @@
ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
LDIFReader reader = new LDIFReader(ldifImportConfig);
- entry = reader.readEntry(checkSchema());
+ Entry entry = reader.readEntry(checkSchema());
addValuesInRDN(entry);
+ return entry;
}
catch (IOException ioe)
{
@@ -340,7 +302,6 @@
ldifImportConfig.close();
}
}
- return entry;
}
/**
@@ -350,10 +311,7 @@
*/
private String getLDIF()
{
- StringBuilder sb = new StringBuilder();
- sb.append(editableAttributes.getText());
-
- return sb.toString();
+ return editableAttributes.getText();
}
/**
@@ -367,7 +325,6 @@
String attrValue;
if (o instanceof String)
{
- //
if (Utilities.hasControlCharaters((String)o))
{
attrValue = Base64.encode(StaticUtils.getBytes((String)o));
--
Gitblit v1.10.0