From 801602d7fa0aba9e5987683d26725daf91885c18 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 10 Jul 2015 08:26:35 +0000
Subject: [PATCH] Code cleanup
---
opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java | 26 --
opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java | 37 +-
opendj-server-legacy/src/test/java/org/opends/server/plugins/UniqueAttributePluginTestCase.java | 37 --
opendj-server-legacy/src/test/java/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java | 42 +--
opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java | 39 ---
opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java | 37 --
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java | 1
opendj-server-legacy/src/main/java/org/opends/server/types/Attributes.java | 29 -
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java | 4
opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java | 7
opendj-server-legacy/src/main/java/org/opends/server/monitors/BackendMonitor.java | 38 --
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java | 57 +---
opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java | 20 -
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java | 1
opendj-server-legacy/src/main/java/org/opends/server/backends/BackupBackend.java | 4
opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciHandler.java | 17
opendj-server-legacy/src/main/java/org/opends/server/monitors/StackTraceMonitorProvider.java | 48 +---
opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationMonitor.java | 5
opendj-server-legacy/src/main/java/org/opends/server/extensions/UserDefinedVirtualAttributeProvider.java | 5
opendj-server-legacy/src/main/java/org/opends/server/monitors/SystemInfoMonitorProvider.java | 70 +----
opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/AddMsg.java | 8
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java | 19 -
opendj-server-legacy/src/main/java/org/opends/server/replication/server/LightweightServerHandler.java | 9
opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java | 15 -
opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java | 8
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java | 7
opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java | 12
opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java | 6
28 files changed, 164 insertions(+), 444 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java b/opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java
index 74b5297..4b86808 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java
@@ -48,6 +48,7 @@
import org.opends.server.types.AttributeType;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Attributes;
+import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteSequenceReader;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.DirectoryException;
@@ -120,22 +121,19 @@
if (numValues == 1 && options.isEmpty())
{
final int valueLength = reader.getBERLength();
- final ByteString valueBytes = reader.getByteSequence(valueLength)
- .toByteString();
- return Attributes.create(attrType, valueBytes);
+ final ByteSequence valueBytes = reader.getByteSequence(valueLength);
+ return Attributes.create(attrType, valueBytes.toByteString());
}
else
{
// Read the appropriate number of values.
final AttributeBuilder builder = new AttributeBuilder(attrType);
builder.setOptions(options);
- builder.setInitialCapacity(numValues);
for (int i = 0; i < numValues; i++)
{
final int valueLength = reader.getBERLength();
- final ByteString valueBytes = reader.getByteSequence(valueLength)
- .toByteString();
- builder.add(valueBytes);
+ final ByteSequence valueBytes = reader.getByteSequence(valueLength);
+ builder.add(valueBytes.toByteString());
}
return builder.toAttribute();
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciHandler.java
index e552301..c0e9d50 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciHandler.java
@@ -30,6 +30,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
+
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
@@ -43,7 +44,11 @@
import org.opends.server.api.ConfigHandler;
import org.opends.server.backends.pluggable.SuffixContainer;
import org.opends.server.controls.GetEffectiveRightsRequestControl;
-import org.opends.server.core.*;
+import org.opends.server.core.BindOperation;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ExtendedOperation;
+import org.opends.server.core.ModifyDNOperation;
+import org.opends.server.core.SearchOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
@@ -444,15 +449,9 @@
return true;
}
- final AttributeBuilder builder =
- new AttributeBuilder(refAttrType, ATTR_REFERRAL_URL);
-
// Load the values, a bind rule might want to evaluate them.
- final List<String> URLStrings = reference.getReferralURLs();
- for (String URLString : URLStrings)
- {
- builder.add(URLString);
- }
+ final AttributeBuilder builder = new AttributeBuilder(refAttrType, ATTR_REFERRAL_URL);
+ builder.addAllStrings(reference.getReferralURLs());
final Entry e = new Entry(dn, null, null, null);
e.addAttribute(builder.toAttribute(), null);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/BackupBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/BackupBackend.java
index 85a51d1..610cfc1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/BackupBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/BackupBackend.java
@@ -644,9 +644,7 @@
if (dependencies != null && !dependencies.isEmpty()) {
t = DirectoryServer.getAttributeType(ATTR_BACKUP_DEPENDENCY, true);
AttributeBuilder builder = new AttributeBuilder(t);
- for (String s : dependencies) {
- builder.add(s);
- }
+ builder.addAllStrings(dependencies);
userAttrs.put(t, builder.toAttributeList());
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java
index a1d5546..bdc271b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java
@@ -462,13 +462,13 @@
HashMap<AttributeType,List<Attribute>> dseOperationalAttrs = new HashMap<>();
- Attribute publicNamingContextAttr = createDNAttribute(
+ Attribute publicNamingContextAttr = createAttribute(
ATTR_NAMING_CONTEXTS, ATTR_NAMING_CONTEXTS_LC,
DirectoryServer.getPublicNamingContexts().keySet());
addAttribute(publicNamingContextAttr, dseUserAttrs, dseOperationalAttrs);
// Add the "ds-private-naming-contexts" attribute.
- Attribute privateNamingContextAttr = createDNAttribute(
+ Attribute privateNamingContextAttr = createAttribute(
ATTR_PRIVATE_NAMING_CONTEXTS, ATTR_PRIVATE_NAMING_CONTEXTS,
DirectoryServer.getPrivateNamingContexts().keySet());
addAttribute(privateNamingContextAttr, dseUserAttrs, dseOperationalAttrs);
@@ -621,34 +621,6 @@
}
/**
- * Creates an attribute for the root DSE meant to hold a set of DNs.
- *
- * @param name The name for the attribute.
- * @param lowerName The name for the attribute formatted in all lowercase
- * characters.
- * @param values The set of DN values to use for the attribute.
- *
- * @return The constructed attribute.
- */
- private Attribute createDNAttribute(String name, String lowerName,
- Collection<DN> values)
- {
- AttributeType type = DirectoryServer.getAttributeType(lowerName);
- if (type == null)
- {
- type = DirectoryServer.getDefaultAttributeType(name);
- }
-
- AttributeBuilder builder = new AttributeBuilder(type, name);
- for (DN dn : values) {
- builder.add(dn.toString());
- }
- return builder.toAttribute();
- }
-
-
-
- /**
* Creates an attribute for the root DSE with the following
* criteria.
*
@@ -662,7 +634,7 @@
* @return The constructed attribute.
*/
private Attribute createAttribute(String name, String lowerName,
- Collection<String> values)
+ Collection<? extends Object> values)
{
AttributeType type = DirectoryServer.getAttributeType(lowerName);
if (type == null)
@@ -671,10 +643,7 @@
}
AttributeBuilder builder = new AttributeBuilder(type, name);
- builder.setInitialCapacity(values.size());
- for (String s : values) {
- builder.add(s);
- }
+ builder.addAllStrings(values);
return builder.toAttribute();
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index 8656c96..0c3de1f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -746,7 +746,6 @@
}
AttributeBuilder builder = new AttributeBuilder(schemaAttributeType);
- builder.setInitialCapacity(elements.size());
for (Object element : elements)
{
/*
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/UserDefinedVirtualAttributeProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/UserDefinedVirtualAttributeProvider.java
index ff90b66..6b4761e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/UserDefinedVirtualAttributeProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/UserDefinedVirtualAttributeProvider.java
@@ -112,10 +112,7 @@
return Attributes.create(rule.getAttributeType(), valueString);
default:
AttributeBuilder builder = new AttributeBuilder(rule.getAttributeType());
- for (String valueStr : userDefinedValues)
- {
- builder.add(valueStr);
- }
+ builder.addAllStrings(userDefinedValues);
return builder.toAttribute();
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/BackendMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/BackendMonitor.java
index d499756..6ecb5c5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/BackendMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/BackendMonitor.java
@@ -26,21 +26,19 @@
*/
package org.opends.server.monitors;
-
-
import static org.opends.server.util.ServerConstants.*;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.api.Backend;
import org.opends.server.api.MonitorProvider;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.schema.BooleanSyntax;
import org.opends.server.types.*;
-
/**
* This class implements a monitor provider that will report generic information
* for an enabled Directory Server backend, including its backend ID, base DNs,
@@ -51,22 +49,14 @@
{
/** The attribute type that will be used to report the backend ID. */
private AttributeType backendIDType;
-
/** The attribute type that will be used to report the set of base DNs. */
private AttributeType baseDNType;
-
/** The attribute type that will be used to report the number of entries. */
private AttributeType entryCountType;
-
- /**
- * The attribute type that will be used to report the number of entries per
- * base DN.
- */
+ /** The attribute type that will be used to report the number of entries per base DN. */
private AttributeType baseDNEntryCountType;
-
/** The attribute type that will be used to indicate if a backend is private. */
private AttributeType isPrivateType;
-
/** The attribute type that will be used to report the writability mode. */
private AttributeType writabilityModeType;
@@ -89,9 +79,7 @@
this.backend = backend;
}
-
-
- /** {@inheritDoc} */
+ @Override
public void initializeMonitorProvider(MonitorProviderCfg configuration)
{
monitorName = backend.getBackendID() + " Backend";
@@ -108,16 +96,12 @@
DirectoryConfig.getAttributeType(ATTR_MONITOR_BACKEND_WRITABILITY_MODE, true);
}
-
-
- /** {@inheritDoc} */
+ @Override
public String getMonitorInstanceName()
{
return monitorName;
}
-
-
/**
* Retrieves the objectclass that should be included in the monitor entry
* created from this monitor provider.
@@ -125,25 +109,23 @@
* @return The objectclass that should be included in the monitor entry
* created from this monitor provider.
*/
+ @Override
public ObjectClass getMonitorObjectClass()
{
return DirectoryConfig.getObjectClass(OC_MONITOR_BACKEND, true);
}
-
- /** {@inheritDoc} */
+ @Override
public List<Attribute> getMonitorData()
{
LinkedList<Attribute> attrs = new LinkedList<>();
attrs.add(Attributes.create(backendIDType, backend.getBackendID()));
- AttributeBuilder builder = new AttributeBuilder(baseDNType);
DN[] baseDNs = backend.getBaseDNs();
- for (DN dn : baseDNs)
- {
- builder.add(dn.toString());
- }
+
+ AttributeBuilder builder = new AttributeBuilder(baseDNType);
+ builder.addAllStrings(Arrays.asList(baseDNs));
attrs.add(builder.toAttribute());
attrs.add(Attributes.create(isPrivateType, BooleanSyntax
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
index a06e70b..d976965 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
@@ -159,10 +159,7 @@
if (!listeners.isEmpty())
{
AttributeBuilder builder = new AttributeBuilder(listenerType);
- for (HostPort hp : listeners)
- {
- builder.add(hp.toString());
- }
+ builder.addAllStrings(listeners);
attrs.add(builder.toAttribute());
}
@@ -183,4 +180,3 @@
return attrs;
}
}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/StackTraceMonitorProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/StackTraceMonitorProvider.java
index 0642d4b..5ce2003 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/StackTraceMonitorProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/StackTraceMonitorProvider.java
@@ -26,18 +26,19 @@
*/
package org.opends.server.monitors;
-
-
import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.admin.std.server.StackTraceMonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
-
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.InitializationException;
/**
* This class defines a Directory Server monitor provider that can be used to
@@ -47,7 +48,7 @@
public class StackTraceMonitorProvider
extends MonitorProvider<StackTraceMonitorProviderCfg>
{
- /** {@inheritDoc} */
+ @Override
public void initializeMonitorProvider(
StackTraceMonitorProviderCfg configuration)
throws ConfigException, InitializationException
@@ -55,34 +56,17 @@
// No initialization is required.
}
-
-
- /**
- * Retrieves the name of this monitor provider. It should be unique among all
- * monitor providers, including all instances of the same monitor provider.
- *
- * @return The name of this monitor provider.
- */
+ @Override
public String getMonitorInstanceName()
{
return "JVM Stack Trace";
}
-
-
- /**
- * Retrieves a set of attributes containing monitor data that should be
- * returned to the client if the corresponding monitor entry is requested.
- *
- * @return A set of attributes containing monitor data that should be
- * returned to the client if the corresponding monitor entry is
- * requested.
- */
- public ArrayList<Attribute> getMonitorData()
+ @Override
+ public List<Attribute> getMonitorData()
{
Map<Thread,StackTraceElement[]> threadStacks = Thread.getAllStackTraces();
-
// Re-arrange all of the elements by thread ID so that there is some logical order.
TreeMap<Long,Map.Entry<Thread,StackTraceElement[]>> orderedStacks = new TreeMap<>();
for (Map.Entry<Thread,StackTraceElement[]> e : threadStacks.entrySet())
@@ -90,7 +74,6 @@
orderedStacks.put(e.getKey().getId(), e);
}
-
AttributeType attrType =
DirectoryServer.getDefaultAttributeType("jvmThread");
AttributeBuilder builder = new AttributeBuilder(attrType);
@@ -100,21 +83,14 @@
StackTraceElement[] stackElements = e.getValue();
long id = t.getId();
-
- StringBuilder buffer = new StringBuilder();
- buffer.append("id=");
- buffer.append(id);
- buffer.append(" ---------- ");
- buffer.append(t.getName());
- buffer.append(" ----------");
- builder.add(buffer.toString());
+ builder.add("id=" + id + " ---------- " + t.getName() + " ----------");
// Create an attribute for the stack trace.
if (stackElements != null)
{
for (int j=0; j < stackElements.length; j++)
{
- buffer = new StringBuilder();
+ StringBuilder buffer = new StringBuilder();
buffer.append("id=");
buffer.append(id);
buffer.append(" frame[");
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/SystemInfoMonitorProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/SystemInfoMonitorProvider.java
index 4f27999..32ed703 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/SystemInfoMonitorProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/SystemInfoMonitorProvider.java
@@ -26,8 +26,6 @@
*/
package org.opends.server.monitors;
-
-
import static org.opends.server.util.ServerConstants.*;
import java.lang.management.ManagementFactory;
@@ -42,13 +40,16 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.admin.std.server.SystemInfoMonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.opends.server.types.*;
-
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.Attributes;
+import org.opends.server.types.InitializationException;
/**
* This class defines a Directory Server monitor provider that can be used to
@@ -60,9 +61,7 @@
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
-
- /** {@inheritDoc} */
+ @Override
public void initializeMonitorProvider(
SystemInfoMonitorProviderCfg configuration)
throws ConfigException, InitializationException
@@ -70,30 +69,14 @@
// No initialization is required.
}
-
-
- /**
- * Retrieves the name of this monitor provider. It should be unique among all
- * monitor providers, including all instances of the same monitor provider.
- *
- * @return The name of this monitor provider.
- */
+ @Override
public String getMonitorInstanceName()
{
return "System Information";
}
-
-
- /**
- * Retrieves a set of attributes containing monitor data that should be
- * returned to the client if the corresponding monitor entry is requested.
- *
- * @return A set of attributes containing monitor data that should be
- * returned to the client if the corresponding monitor entry is
- * requested.
- */
- public ArrayList<Attribute> getMonitorData()
+ @Override
+ public List<Attribute> getMonitorData()
{
ArrayList<Attribute> attrs = new ArrayList<>(13);
@@ -199,32 +182,19 @@
supportedTlsCiphers = Collections.emptyList();
}
-
- // Add the "supportedTLSProtocols" attribute.
- AttributeType supportedTLSProtocolsAttrType = DirectoryServer
- .getDefaultAttributeType(ATTR_SUPPORTED_TLS_PROTOCOLS);
- AttributeBuilder builder = new AttributeBuilder(
- supportedTLSProtocolsAttrType);
- for (String value : supportedTlsProtocols)
- {
- builder.add(value);
- }
- attrs.add(builder.toAttribute());
-
- // Add the "supportedTLSCiphers" attribute.
- AttributeType supportedTLSCiphersAttrType = DirectoryServer
- .getDefaultAttributeType(ATTR_SUPPORTED_TLS_CIPHERS);
- builder = new AttributeBuilder(supportedTLSCiphersAttrType);
- for (String value : supportedTlsCiphers)
- {
- builder.add(value);
- }
- attrs.add(builder.toAttribute());
+ addAttribute(attrs, ATTR_SUPPORTED_TLS_PROTOCOLS, supportedTlsProtocols);
+ addAttribute(attrs, ATTR_SUPPORTED_TLS_CIPHERS, supportedTlsCiphers);
return attrs;
}
-
+ private void addAttribute(ArrayList<Attribute> attrs, String attrName, Collection<String> values)
+ {
+ AttributeType attrType = DirectoryServer.getDefaultAttributeType(attrName);
+ AttributeBuilder builder = new AttributeBuilder(attrType);
+ builder.addAllStrings(values);
+ attrs.add(builder.toAttribute());
+ }
/**
* Constructs an attribute using the provided information. It will have the
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/AddMsg.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/AddMsg.java
index 867d03b..5ce7e68 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/AddMsg.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/AddMsg.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2014 ForgeRock AS
+ * Portions Copyright 2011-2015 ForgeRock AS
*/
package org.opends.server.replication.protocol;
@@ -232,11 +232,7 @@
// Encode the object classes (SET OF LDAPString).
AttributeBuilder builder = new AttributeBuilder(
DirectoryServer.getObjectClassAttributeType());
- builder.setInitialCapacity(objectClasses.size());
- for (String s : objectClasses.values())
- {
- builder.add(s);
- }
+ builder.addAllStrings(objectClasses.values());
new LDAPAttribute(builder.toAttribute()).write(writer);
// Encode the user and operational attributes (AttributeList).
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java
index 096cecf..035b631 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/DataServerHandler.java
@@ -259,14 +259,11 @@
String.valueOf(md.getApproxDelay(serverId))));
/* get the Server State */
- AttributeBuilder builder = new AttributeBuilder("server-state");
ServerState state = md.getLDAPServerState(serverId);
if (state != null)
{
- for (String str : state.toStringSet())
- {
- builder.add(str);
- }
+ AttributeBuilder builder = new AttributeBuilder("server-state");
+ builder.addAllStrings(state.toStringSet());
attributes.add(builder.toAttribute());
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/LightweightServerHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/LightweightServerHandler.java
index 46af9d2..83e0448 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/LightweightServerHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/LightweightServerHandler.java
@@ -30,11 +30,11 @@
import java.util.Date;
import java.util.List;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.replication.common.DSInfo;
import org.opends.server.replication.common.ServerState;
import org.opends.server.types.Attribute;
@@ -190,10 +190,7 @@
// get the Server State
AttributeBuilder builder = new AttributeBuilder("server-state");
- for (String str : remoteState.toStringSet())
- {
- builder.add(str);
- }
+ builder.addAllStrings(remoteState.toStringSet());
if (builder.size() == 0)
{
builder.add("unknown");
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java
index 56b5b58..45fac4b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -51,7 +51,6 @@
*/
public class ReplicationServerHandler extends ServerHandler
{
-
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
/** Properties filled only if remote server is a RS. */
@@ -671,14 +670,11 @@
String.valueOf(md.getMissingChangesRS(serverId))));
// get the Server State
- AttributeBuilder builder = new AttributeBuilder("server-state");
ServerState state = md.getRSStates(serverId);
if (state != null)
{
- for (String str : state.toStringSet())
- {
- builder.add(str);
- }
+ AttributeBuilder builder = new AttributeBuilder("server-state");
+ builder.addAllStrings(state.toStringSet());
attributes.add(builder.toAttribute());
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationMonitor.java
index 9a59d05..0ebbbea 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationMonitor.java
@@ -112,10 +112,7 @@
final String ATTR_SERVER_STATE = "server-state";
AttributeType type = DirectoryServer.getDefaultAttributeType(ATTR_SERVER_STATE);
AttributeBuilder builder = new AttributeBuilder(type, ATTR_SERVER_STATE);
- for (String str : domain.getServerState().toStringSet())
- {
- builder.add(str);
- }
+ builder.addAllStrings(domain.getServerState().toStringSet());
attributes.add(builder.toAttribute());
attributes.add(Attributes.create("ssl-encryption", String.valueOf(domain.isSessionEncrypted())));
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java b/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
index 0495284..9d7007f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
@@ -1234,17 +1234,13 @@
return wasModified;
}
-
-
/**
* Adds the specified attribute values to this attribute builder if
* they are not already present.
*
* @param values
- * The attribute values to be added to this attribute
- * builder.
- * @return <code>true</code> if this attribute builder was
- * modified.
+ * The attribute values to be added to this attribute builder.
+ * @return <code>true</code> if this attribute builder was modified.
*/
public boolean addAll(Collection<ByteString> values)
{
@@ -1256,7 +1252,24 @@
return wasModified;
}
-
+ /**
+ * Adds the specified attribute values to this attribute builder
+ * if they are not already present.
+ *
+ * @param values
+ * The attribute values to be added to this attribute builder.
+ * @return <code>true</code> if this attribute builder was modified.
+ * @throws NullPointerException if any of the values is null
+ */
+ public boolean addAllStrings(Collection<? extends Object> values)
+ {
+ boolean wasModified = false;
+ for (Object v : values)
+ {
+ wasModified |= add(v.toString());
+ }
+ return wasModified;
+ }
/**
* Removes all attribute values from this attribute builder.
@@ -1539,36 +1552,6 @@
setAttributeType(getAttributeType(attributeName), attributeName);
}
-
-
- /**
- * Sets the initial capacity of this attribute builders internal set
- * of attribute values.
- * <p>
- * The initial capacity of an attribute builder defaults to one.
- * Applications should override this default if the attribute being
- * built is expected to contain many values.
- * <p>
- * This method should only be called before any attribute values
- * have been added to this attribute builder. If it is called
- * afterwards an {@link IllegalStateException} will be thrown.
- *
- * @param initialCapacity
- * The initial capacity of this attribute builder.
- * @return This attribute builder.
- * @throws IllegalStateException
- * If this attribute builder already contains attribute
- * values.
- */
- public AttributeBuilder setInitialCapacity(int initialCapacity)
- throws IllegalStateException
- {
- // This is now a no op.
- return this;
- }
-
-
-
/**
* Adds the specified option to this attribute builder if it is not
* already present.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Attributes.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Attributes.java
index bc1866b..05d83e0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Attributes.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Attributes.java
@@ -26,6 +26,7 @@
*/
package org.opends.server.types;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -188,8 +189,6 @@
valueString);
}
-
-
/**
* Creates a new multi-valued attribute with the specified attribute
* name and attribute values.
@@ -201,36 +200,26 @@
* typically be reserved for use in unit tests and places where
* performance is not an issue. In particular, this method will
* construct a temporary array containing the attribute's values.
- * For peformance critical purposes, incrementally construct an
+ * For performance critical purposes, incrementally construct an
* attribute using an {@link AttributeBuilder}.
*
* @param attributeName
* The name or OID of the attribute type for this attribute
* (can be mixed case).
- * @param firstValueString
- * The string representation of the first attribute value.
- * @param otherValueStrings
- * The string representation of the remaining attribute
- * values.
+ * @param valueStrings
+ * The string representation of the attribute values.
* @return A new attribute with the specified name and values.
*/
- public static Attribute create(String attributeName,
- String firstValueString, String... otherValueStrings)
+ public static Attribute create(String attributeName, String... valueStrings)
{
- AttributeBuilder builder = new AttributeBuilder(attributeName);
-
- builder.add(firstValueString);
-
- for (String value : otherValueStrings)
- {
- builder.add(value);
+ if (valueStrings.length == 0) {
+ return empty(attributeName);
}
-
+ AttributeBuilder builder = new AttributeBuilder(attributeName);
+ builder.addAllStrings(Arrays.asList(valueStrings));
return builder.toAttribute();
}
-
-
/**
* Creates a new attribute which has the same attribute type and
* attribute options as the provided attribute but no attribute
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
index 5e3b944..00270e9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -371,11 +371,7 @@
{
AttributeType ocType = DirectoryServer.getObjectClassAttributeType();
AttributeBuilder builder = new AttributeBuilder(ocType, ATTR_OBJECTCLASS);
- for (Map.Entry<ObjectClass, String> e : objectClasses.entrySet())
- {
- builder.add(e.getValue());
- }
-
+ builder.addAllStrings(objectClasses.values());
objectClassAttribute = builder.toAttribute();
}
@@ -3803,7 +3799,6 @@
int numValues = entryBuffer.getBERLength();
// Next, we have the sequence of length-value pairs.
- builder.setInitialCapacity(numValues);
for (int j=0; j < numValues; j++)
{
int valueLength = entryBuffer.getBERLength();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
index 64f7546..61baf14 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -1451,9 +1451,7 @@
// Reconstruct the object class attribute.
AttributeType ocType = DirectoryServer.getObjectClassAttributeType();
AttributeBuilder builder = new AttributeBuilder(ocType, "objectClass");
- for (String value : objectClasses.values()) {
- builder.add(value);
- }
+ builder.addAllStrings(objectClasses.values());
Map<AttributeType, List<Attribute>> attributes = toAttributesMap(attrBuilders);
if (attributes.get(ocType) == null)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
index 7550932..da661f9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
@@ -796,7 +796,6 @@
List<PasswordStorageScheme<?>> defaultStorageSchemes =
passwordPolicy.getDefaultPasswordStorageSchemes();
AttributeBuilder builder = new AttributeBuilder(passwordAttr, true);
- builder.setInitialCapacity(defaultStorageSchemes.size());
for (ByteString value : passwordAttr)
{
// See if the password is pre-encoded.
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java
index b81ae92..dbbda89 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java
@@ -26,8 +26,6 @@
*/
package org.opends.server.backends.jeb;
-import static org.opends.server.schema.SchemaConstants.*;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
@@ -89,6 +87,7 @@
import static org.opends.server.backends.pluggable.SuffixContainer.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
+import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.types.Attributes.*;
import static org.opends.server.util.StaticUtils.*;
import static org.testng.Assert.*;
@@ -933,7 +932,6 @@
Entry entry;
Entry newEntry;
EntryID entryID;
- AttributeType attribute;
AttributeIndex titleIndex;
AttributeIndex nameIndex;
Set<ByteString> addKeys;
@@ -947,29 +945,20 @@
List<Modification> modifications = new ArrayList<>();
modifications.add(new Modification(ADD, create("title", "debugger")));
- AttributeBuilder builder = new AttributeBuilder("title");
- builder.setOption("lang-en");
- builder.add("debugger2");
-
- modifications.add(new Modification(ADD, builder.toAttribute()));
+ Attribute attr = attributeWithOption("title", "debugger2", "lang-en");
+ modifications.add(new Modification(ADD, attr));
modifications.add(new Modification(DELETE, create("cn", "Aaren Atp")));
modifications.add(new Modification(ADD, create("cn", "Aaren Rigor")));
modifications.add(new Modification(ADD, create("cn", "Aarenister Rigor")));
- builder = new AttributeBuilder("givenname");
- builder.add("test");
- builder.setOption("lang-de");
- modifications.add(new Modification(ADD, builder.toAttribute()));
+ attr = attributeWithOption("givenname", "test", "lang-de");
+ modifications.add(new Modification(ADD, attr));
- builder = new AttributeBuilder("givenname");
- builder.add("test2");
- builder.setOption("lang-cn");
- modifications.add(new Modification(DELETE, builder.toAttribute()));
+ attr = attributeWithOption("givenname", "test2", "lang-cn");
+ modifications.add(new Modification(DELETE, attr));
- builder = new AttributeBuilder("givenname");
- builder.add("newtest3");
- builder.setOption("lang-es");
- modifications.add(new Modification(REPLACE, builder.toAttribute()));
+ attr = attributeWithOption("givenname", "newtest3", "lang-es");
+ modifications.add(new Modification(REPLACE, attr));
modifications.add(new Modification(REPLACE, create("employeenumber", "222")));
newEntry = entries.get(1);
@@ -1061,6 +1050,14 @@
}
}
+ private Attribute attributeWithOption(String attributeName, String value, String option)
+ {
+ AttributeBuilder builder = new AttributeBuilder(attributeName);
+ builder.add(value);
+ builder.setOption(option);
+ return builder.toAttribute();
+ }
+
@Test(dependsOnMethods = {"testAdd", "testSearchIndex", "testSearchScope",
"testMatchedDN"})
public void testModifyDN() throws Exception {
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java
index 569ccea..e1fbfc2 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java
@@ -26,39 +26,33 @@
*/
package org.opends.server.extensions;
-
-
import static org.testng.Assert.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.server.AdminTestCaseUtils;
import org.opends.server.admin.std.meta.FingerprintCertificateMapperCfgDefn;
import org.opends.server.admin.std.server.FingerprintCertificateMapperCfg;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.Attribute;
-import org.opends.server.types.AttributeBuilder;
-import org.opends.server.types.AttributeType;
import org.opends.server.types.Attributes;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
-import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-
-
/**
* A set of test cases for the fingerprint certificate mapper.
*/
@@ -659,21 +653,9 @@
{
String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config";
- AttributeType attrType =
- DirectoryServer.getAttributeType("ds-cfg-user-base-dn");
-
- AttributeBuilder builder = new AttributeBuilder(attrType);
- if (baseDNs != null)
- {
- for (String baseDN : baseDNs)
- {
- builder.add(baseDN);
- }
- }
-
ArrayList<Modification> mods = new ArrayList<>();
mods.add(new Modification(ModificationType.REPLACE,
- builder.toAttribute()));
+ Attributes.create("ds-cfg-user-base-dn", baseDNs)));
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java
index 261b728..452f0af 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java
@@ -27,19 +27,20 @@
*/
package org.opends.server.extensions;
-
-
import static org.testng.Assert.*;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.server.AdminTestCaseUtils;
import org.opends.server.admin.std.meta.SubjectAttributeToUserAttributeCertificateMapperCfgDefn;
import org.opends.server.admin.std.server.SubjectAttributeToUserAttributeCertificateMapperCfg;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
@@ -52,18 +53,11 @@
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
-import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-
-
-/**
- * A set of test cases for the Subject Attribute to User Attribute certificate
- * mapper.
- */
+/** A set of test cases for the Subject Attribute to User Attribute certificate mapper. */
public class SubjectAttributeToUserAttributeCertificateMapperTestCase
extends ExtensionsTestCase
{
@@ -922,21 +916,9 @@
String mapperDN = "cn=Subject Attribute to User Attribute," +
"cn=Certificate Mappers,cn=config";
- AttributeType attrType =
- DirectoryServer.getAttributeType(
- "ds-cfg-subject-attribute-mapping");
-
- AttributeBuilder builder = new AttributeBuilder(attrType);
- if (mappings != null)
- {
- for (String mapping : mappings)
- {
- builder.add(mapping);
- }
- }
-
ArrayList<Modification> mods = new ArrayList<>();
- mods.add(new Modification(ModificationType.REPLACE, builder.toAttribute()));
+ mods.add(new Modification(ModificationType.REPLACE,
+ Attributes.create("ds-cfg-subject-attribute-mapping", mappings)));
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
@@ -969,10 +951,7 @@
AttributeBuilder builder = new AttributeBuilder(attrType);
if (baseDNs != null)
{
- for (String baseDN : baseDNs)
- {
- builder.add(baseDN);
- }
+ builder.addAllStrings(Arrays.asList(baseDNs));
}
ArrayList<Modification> mods = new ArrayList<>();
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java
index 7258831..69f2458 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java
@@ -26,19 +26,20 @@
*/
package org.opends.server.extensions;
-
-
import static org.testng.Assert.*;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.server.AdminTestCaseUtils;
import org.opends.server.admin.std.meta.SubjectDNToUserAttributeCertificateMapperCfgDefn;
import org.opends.server.admin.std.server.SubjectDNToUserAttributeCertificateMapperCfg;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
@@ -51,14 +52,10 @@
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
-import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-
-
/**
* A set of test cases for the Subject DN to User Attribute certificate mapper.
*/
@@ -688,16 +685,11 @@
String mapperDN =
"cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config";
- AttributeType attrType =
- DirectoryServer.getAttributeType("ds-cfg-user-base-dn");
-
+ AttributeType attrType = DirectoryServer.getAttributeType("ds-cfg-user-base-dn");
AttributeBuilder builder = new AttributeBuilder(attrType);
if (baseDNs != null)
{
- for (String baseDN : baseDNs)
- {
- builder.add(baseDN);
- }
+ builder.addAllStrings(Arrays.asList(baseDNs));
}
ArrayList<Modification> mods = new ArrayList<>();
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
index 7be9c65..29243c4 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
@@ -47,12 +47,14 @@
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
-import org.opends.server.types.*;
+import org.opends.server.types.AttributeType;
import org.opends.server.types.Attributes;
+import org.opends.server.types.Control;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.opends.server.types.RDN;
+import org.opends.server.types.SearchResultEntry;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -1023,58 +1025,36 @@
* Add specified attr type and type values to the entry specified by dn.
*
* @param dn The dn of the entry to add the attribute and values to.
- *
- * @param attrTypeString The attribute type to add the values to.
- *
+ * @param attrName The attribute type to add the values to.
* @param attrValStrings The values to add to the entry.
- *
*/
private ModifyOperation
- addAttrEntry(DN dn, String attrTypeString, String... attrValStrings) {
+ addAttrEntry(DN dn, String attrName, String... attrValStrings) {
LinkedList<Modification> mods = new LinkedList<>();
- AttributeType attrType = getAttrType(attrTypeString);
- AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
- for(String valString : attrValStrings) {
- builder.add(valString);
- }
- mods.add(new Modification(ModificationType.ADD, builder.toAttribute()));
+ mods.add(new Modification(ModificationType.ADD, Attributes.create(attrName, attrValStrings)));
return getRootConnection().processModify(dn, mods);
}
-/**
+ /**
* Replace specified attr type and type values to the entry specified by dn.
*
* @param dn The dn of the entry to replace the attribute and values to.
- *
- * @param attrTypeString The attribute type to replace the values in.
- *
+ * @param attrName The attribute type to replace the values in.
* @param attrValStrings The values to replace in the the entry.
- *
*/
- private ModifyOperation
- replaceAttrEntry(DN dn, String attrTypeString, String... attrValStrings) {
+ private ModifyOperation replaceAttrEntry(DN dn, String attrName, String... attrValStrings) {
LinkedList<Modification> mods = new LinkedList<>();
- AttributeType attrType = getAttrType(attrTypeString);
- AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
- for(String valString : attrValStrings) {
- builder.add(valString);
- }
- mods.add(new Modification(ModificationType.REPLACE, builder.toAttribute()));
+ mods.add(new Modification(ModificationType.REPLACE, Attributes.create(attrName, attrValStrings)));
return getRootConnection().processModify(dn, mods);
}
-
/**
* Remove the attributes specified by the attribute type strings from the
* entry corresponding to the dn argument.
*
* @param dn The entry to remove the attributes from.
- *
- * @param attrTypeStrings The attribute type string list to remove from the
- * entry.
- *
+ * @param attrTypeStrings The attribute type string list to remove from the entry.
* @throws Exception If an error occurs.
- *
*/
private void
deleteAttrsEntry(DN dn, String... attrTypeStrings) throws Exception {
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/plugins/UniqueAttributePluginTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/plugins/UniqueAttributePluginTestCase.java
index 950fc4a..9fb3100 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/plugins/UniqueAttributePluginTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/plugins/UniqueAttributePluginTestCase.java
@@ -737,17 +737,9 @@
getRootConnection().processModify(dn, mods);
}
-
-
- private void
- replaceAttrInEntry(DN dn, String attrTypeString, String... attrValStrings) {
+ private void replaceAttrInEntry(DN dn, String attrName, String... attrValStrings) {
LinkedList<Modification> mods = new LinkedList<>();
- AttributeType attrType = getAttrType(attrTypeString);
- AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
- for(String valString : attrValStrings) {
- builder.add(valString);
- }
- mods.add(new Modification(ModificationType.REPLACE, builder.toAttribute()));
+ mods.add(new Modification(ModificationType.REPLACE, Attributes.create(attrName, attrValStrings)));
getRootConnection().processModify(dn, mods);
}
@@ -800,17 +792,11 @@
* Add an attribute to an entry with specified values.
*
* @param entry The entry to add the attribute to.
- * @param attrTypeString The attribute type string name.
+ * @param attrName The attribute type string name.
* @param attrValues The values use in building the attribute.
*/
- private void
- addAttribute(Entry entry, String attrTypeString, String... attrValues) {
- AttributeType attrType=getAttrType(attrTypeString);
- AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
- for(String attrValue : attrValues) {
- builder.add(attrValue);
- }
- entry.addAttribute(builder.toAttribute(), null);
+ private void addAttribute(Entry entry, String attrName, String... attrValues) {
+ entry.addAttribute(Attributes.create(attrName, attrValues), null);
}
/**
@@ -818,20 +804,15 @@
* type to a list of modifications.
*
* @param mods The modification list to add to.
- * @param attrTypeString The attribute type string name.
+ * @param attrName The attribute type string name.
* @param modificationType The modification type.
* @param attrValues The values to build the modification from.
*/
private void
- addMods(LinkedList<Modification> mods, String attrTypeString,
+ addMods(LinkedList<Modification> mods, String attrName,
ModificationType modificationType, String... attrValues) {
- AttributeType attrType=getAttrType(attrTypeString);
- AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
- for(String attrValue : attrValues) {
- builder.add(attrValue);
- }
mods.add(new Modification(modificationType,
- builder.toAttribute()));
+ Attributes.create(attrName, attrValues)));
}
/**
@@ -867,7 +848,7 @@
/**
* Perform modify DN operation. Expect return value of rc.
*
- * @param dn The DN to renmame or move.
+ * @param dn The DN to rename or move.
* @param rdn RDN value.
* @param delOld Delete old flag.
* @param newSuperior New superior to move to.
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
index 45fdf32..9cc0d5a 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -1384,24 +1384,9 @@
return mods;
}
- private Modification buildMod(String attrName, ModificationType modType,
- String... values)
+ private Modification buildMod(String attrName, ModificationType modType, String... values)
{
- Attribute attr;
- if (values.length == 0)
- {
- attr = Attributes.empty(attrName);
- }
- else
- {
- AttributeBuilder builder = new AttributeBuilder(attrName);
- for (String value : values)
- {
- builder.add(value);
- }
- attr = builder.toAttribute();
- }
- return new Modification(modType, attr);
+ return new Modification(modType, Attributes.create(attrName, values));
}
private Attribute buildSyncHist(String attrName, String... values)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java
index b335eac..b67cb28 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestEntry.java
@@ -26,7 +26,6 @@
*/
package org.opends.server.types;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -43,6 +42,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
/**
@@ -90,8 +90,7 @@
throw new RuntimeException("Unable to resolve object class top");
}
- ObjectClass extensible = DirectoryServer
- .getObjectClass("extensibleobject");
+ ObjectClass extensible = DirectoryServer.getObjectClass("extensibleobject");
if (extensible == null) {
throw new RuntimeException(
"Unable to resolve object class extensibleObject");
@@ -105,14 +104,8 @@
Entry testEntry = new Entry(entryDN, objectClasses, null, null);
// Now add the attribute.
- AttributeBuilder builder = new AttributeBuilder(type);
- for (String value : values) {
- builder.add(value);
- }
- ArrayList<Attribute> attributes = new ArrayList<>();
- attributes.add(builder.toAttribute());
- testEntry.putAttribute(type, attributes);
-
+ Attribute attr = Attributes.create(type.getNameOrOID(), values);
+ testEntry.putAttribute(type, newArrayList(attr));
return testEntry;
}
--
Gitblit v1.10.0