From 63f448170875fbc69cfd9496507eab923535e07d Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 13 Jul 2015 15:14:07 +0000
Subject: [PATCH] Code cleanup. Removed duplication.
---
opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java | 262 ++------
opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java | 151 ++---
opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java | 78 +
opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java | 300 ++-------
opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java | 213 +-----
opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java | 140 +---
opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java | 217 ++-----
opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java | 273 +++------
8 files changed, 504 insertions(+), 1,130 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java
index c2f9dec..2bc0ea4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java
@@ -26,8 +26,6 @@
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
-
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -36,13 +34,14 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.ByteString;
-import static org.opends.server.config.ConfigConstants.*;
import static org.opends.messages.ConfigMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
@@ -195,10 +194,7 @@
{
return pendingValue;
}
- else
- {
- return activeValue;
- }
+ return activeValue;
}
@@ -233,10 +229,7 @@
*/
private static LinkedHashSet<ByteString> getValueSet(boolean booleanValue)
{
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(
- booleanValue ? CONFIG_VALUE_TRUE : CONFIG_VALUE_FALSE));
- return valueSet;
+ return getValueSet(booleanValue ? CONFIG_VALUE_TRUE : CONFIG_VALUE_FALSE);
}
@@ -419,60 +412,47 @@
if (pendingValueSet)
{
// We cannot have multiple pending values.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()));
}
-
-
if (a.isEmpty())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
+ }
+
+ // Get the value and parse it as a Boolean.
+ Iterator<ByteString> iterator = a.iterator();
+ String valueString = iterator.next().toString().toLowerCase();
+
+ if (valueString.equals("true") || valueString.equals("yes") ||
+ valueString.equals("on") || valueString.equals("1"))
+ {
+ pendingValue = true;
+ pendingValueSet = true;
+ }
+ else if (valueString.equals("false") || valueString.equals("no") ||
+ valueString.equals("off") || valueString.equals("0"))
+ {
+ pendingValue = false;
+ pendingValueSet = true;
}
else
{
- // Get the value and parse it as a Boolean.
- Iterator<ByteString> iterator = a.iterator();
- String valueString = iterator.next().toString().toLowerCase();
+ // This is an illegal value.
+ throw new ConfigException(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), valueString));
+ }
- if (valueString.equals("true") || valueString.equals("yes") ||
- valueString.equals("on") || valueString.equals("1"))
- {
- pendingValue = true;
- pendingValueSet = true;
- }
- else if (valueString.equals("false") || valueString.equals("no") ||
- valueString.equals("off") || valueString.equals("0"))
- {
- pendingValue = false;
- pendingValueSet = true;
- }
- else
- {
- // This is an illegal value.
- LocalizableMessage message = ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
- getName(), valueString);
- throw new ConfigException(message);
- }
-
- if (iterator.hasNext())
- {
- // This is illegal -- it must be single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
- }
+ if (iterator.hasNext())
+ {
+ // This is illegal -- it must be single-valued.
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()));
}
}
else
{
// This is illegal -- only the pending option is allowed for
// configuration attributes.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()));
}
}
else
@@ -481,51 +461,40 @@
if (activeValueSet)
{
// We cannot have multiple active values.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()));
}
-
-
if (a.isEmpty())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
+ }
+
+ // Get the value and parse it as a Boolean.
+ Iterator<ByteString> iterator = a.iterator();
+ String valueString = iterator.next().toString().toLowerCase();
+
+ if (valueString.equals("true") || valueString.equals("yes") ||
+ valueString.equals("on") || valueString.equals("1"))
+ {
+ activeValue = true;
+ activeValueSet = true;
+ }
+ else if (valueString.equals("false") || valueString.equals("no") ||
+ valueString.equals("off") || valueString.equals("0"))
+ {
+ activeValue = false;
+ activeValueSet = true;
}
else
{
- // Get the value and parse it as a Boolean.
- Iterator<ByteString> iterator = a.iterator();
- String valueString = iterator.next().toString().toLowerCase();
+ // This is an illegal value.
+ throw new ConfigException(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), valueString));
+ }
- if (valueString.equals("true") || valueString.equals("yes") ||
- valueString.equals("on") || valueString.equals("1"))
- {
- activeValue = true;
- activeValueSet = true;
- }
- else if (valueString.equals("false") || valueString.equals("no") ||
- valueString.equals("off") || valueString.equals("0"))
- {
- activeValue = false;
- activeValueSet = true;
- }
- else
- {
- // This is an illegal value.
- LocalizableMessage message = ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
- getName(), valueString);
- throw new ConfigException(message);
- }
-
- if (iterator.hasNext())
- {
- // This is illegal -- it must be single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
- }
+ if (iterator.hasNext())
+ {
+ // This is illegal -- it must be single-valued.
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()));
}
}
}
@@ -533,8 +502,7 @@
if (! activeValueSet)
{
// This is not OK. The value set must contain an active value.
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()));
}
if (pendingValueSet)
@@ -712,4 +680,3 @@
pendingValue);
}
}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java
index ae14463..a6d9316 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java
@@ -25,22 +25,22 @@
* Portions Copyright 2014-2015 ForgeRock AS
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
-
+import static org.opends.messages.ConfigMessages.*;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+
import javax.management.AttributeList;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.ByteString;
-import static org.opends.messages.ConfigMessages.*;
/**
* This class defines a configuration attribute, which can hold zero or more
* values associated with a configurable property within the Directory Server.
@@ -341,10 +341,7 @@
{
return pendingValues;
}
- else
- {
- return activeValues;
- }
+ return activeValues;
}
@@ -389,27 +386,23 @@
{
if (isRequired)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(name);
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(name));
+ }
+
+ if (requiresAdminAction)
+ {
+ pendingValues = notNull(values);
+ hasPendingValues = true;
}
else
{
- if (requiresAdminAction)
- {
- pendingValues = notNull(values);
+ activeValues = notNull(values);
- hasPendingValues = true;
- }
- else
- {
- activeValues = notNull(values);
-
- pendingValues = activeValues;
- hasPendingValues = false;
- }
-
- return;
+ pendingValues = activeValues;
+ hasPendingValues = false;
}
+
+ return;
}
@@ -880,5 +873,40 @@
* @return A duplicate of this configuration attribute.
*/
public abstract ConfigAttribute duplicate();
-}
+ /**
+ * Creates the appropriate value set with the provided value.
+ *
+ * @param value
+ * The value to use to create the value set.
+ * @return The value set constructed from the provided value.
+ */
+ static LinkedHashSet<ByteString> getValueSet(String value)
+ {
+ LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
+ valueSet.add(ByteString.valueOf(value));
+ return valueSet;
+ }
+
+ /**
+ * Creates the appropriate value set with the provided values.
+ *
+ * @param values
+ * The values to use to create the value set.
+ * @return The constructed value set.
+ */
+ static LinkedHashSet<ByteString> getValueSet(List<String> values)
+ {
+ if (values == null)
+ {
+ return null;
+ }
+
+ LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(values.size());
+ for (String value : values)
+ {
+ valueSet.add(ByteString.valueOf(value));
+ }
+ return valueSet;
+ }
+}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java
index a123a60..764c9cd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java
@@ -118,7 +118,7 @@
DN value)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(value));
+ getDNValueSet(value));
if (value == null)
@@ -157,7 +157,7 @@
List<DN> values)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(values));
+ getDNValueSet(values));
activeValues = values != null ? values : new ArrayList<DN>();
pendingValues = activeValues;
@@ -189,8 +189,8 @@
List<DN> activeValues, List<DN> pendingValues)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(activeValues), (pendingValues != null),
- getValueSet(pendingValues));
+ getDNValueSet(activeValues), pendingValues != null,
+ getDNValueSet(pendingValues));
if (activeValues == null)
@@ -356,14 +356,14 @@
if (requiresAdminAction())
{
pendingValues = newArrayList(value);
- setPendingValues(getValueSet(value));
+ setPendingValues(getDNValueSet(value));
}
else
{
activeValues.clear();
activeValues.add(value);
pendingValues = activeValues;
- setActiveValues(getValueSet(value));
+ setActiveValues(getDNValueSet(value));
}
}
@@ -385,32 +385,27 @@
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
+ }
+
+ if (requiresAdminAction())
+ {
+ setPendingValues(new LinkedHashSet<ByteString>(0));
+ pendingValues = new ArrayList<>();
}
else
{
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- setActiveValues(new LinkedHashSet<ByteString>(0));
- activeValues.clear();
- }
+ setActiveValues(new LinkedHashSet<ByteString>(0));
+ activeValues.clear();
}
}
// Next check if the set contains multiple values and if that is allowed.
int numValues = values.size();
- if ((! isMultiValued()) && (numValues > 1))
+ if (!isMultiValued() && (numValues > 1))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
@@ -421,16 +416,13 @@
{
if (value == null)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_NULL.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_DN_NULL.get(getName()));
}
ByteString attrValue = ByteString.valueOf(value.toString());
if (valueSet.contains(attrValue))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value);
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
}
valueSet.add(attrValue);
@@ -460,19 +452,13 @@
*
* @return The constructed value set.
*/
- private static LinkedHashSet<ByteString> getValueSet(DN value)
+ private static LinkedHashSet<ByteString> getDNValueSet(DN value)
{
- LinkedHashSet<ByteString> valueSet;
if (value == null)
{
- valueSet = new LinkedHashSet<>(0);
+ return new LinkedHashSet<>(0);
}
- else
- {
- valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(value.toString()));
- }
- return valueSet;
+ return newLinkedHashSet(ByteString.valueOf(value.toString()));
}
@@ -484,7 +470,7 @@
*
* @return The constructed value set.
*/
- private static LinkedHashSet<ByteString> getValueSet(List<DN> values)
+ private static LinkedHashSet<ByteString> getDNValueSet(List<DN> values)
{
if (values == null)
{
@@ -584,13 +570,9 @@
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
- else
- {
- return new LinkedHashSet<>();
- }
+ return new LinkedHashSet<>();
}
@@ -608,16 +590,8 @@
{
if (valueString == null)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_NULL.get(getName());
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_DN_NULL.get(getName()));
+ continue;
}
@@ -630,37 +604,32 @@
{
logger.traceException(e);
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(valueString, getName(), e);
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(valueString, getName(), e));
+ continue;
}
-
valueSet.add(ByteString.valueOf(dn.toString()));
}
-
// If this method was configured to continue on error, then it is possible
// that we ended up with an empty list. Check to see if this is a required
// attribute and if so deal with it accordingly.
if ((isRequired()) && valueSet.isEmpty())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
-
return valueSet;
}
-
+ private void reportError(boolean allowFailures, LocalizableMessage message) throws ConfigException
+ {
+ if (!allowFailures)
+ {
+ throw new ConfigException(message);
+ }
+ logger.error(message);
+ }
/**
* Converts the set of active values for this configuration attribute into a
@@ -760,24 +729,18 @@
if (isRequired())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
}
- else
- {
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
+ // This is fine. The pending value set can be empty.
+ pendingValues = new ArrayList<>(0);
}
else
{
int numValues = a.size();
- if ((numValues > 1) && (! isMultiValued()))
+ if (numValues > 1 && (!isMultiValued()))
{
// This is illegal -- the attribute is single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()));
}
pendingValues = new ArrayList<>(numValues);
@@ -792,8 +755,7 @@
{
logger.traceException(e);
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(
- v, getName(), e);
+ LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(v, getName(), e);
throw new ConfigException(message, e);
}
@@ -825,24 +787,18 @@
if (isRequired())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
}
- else
- {
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
+ // This is fine. The active value set can be empty.
+ activeValues = new ArrayList<>(0);
}
else
{
int numValues = a.size();
- if ((numValues > 1) && (! isMultiValued()))
+ if (numValues > 1 && !isMultiValued())
{
// This is illegal -- the attribute is single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()));
}
activeValues = new ArrayList<>(numValues);
@@ -857,8 +813,7 @@
{
logger.traceException(e);
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(
- v, getName(), e);
+ LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(v, getName(), e);
throw new ConfigException(message, e);
}
@@ -923,17 +878,14 @@
return new javax.management.Attribute(name, values);
}
+ else if (!requestedValues.isEmpty())
+ {
+ DN dn = requestedValues.get(0);
+ return new javax.management.Attribute(name, dn.toString());
+ }
else
{
- if (requestedValues.isEmpty())
- {
- return null;
- }
- else
- {
- DN dn = requestedValues.get(0);
- return new javax.management.Attribute(name, dn.toString());
- }
+ return null;
}
}
@@ -1046,44 +998,14 @@
*/
public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
{
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, true, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, true, false));
- }
-
+ attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
+ String.valueOf(getDescription()), true, true, false));
if (requiresAdminAction())
{
String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
+ attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
+ String.valueOf(getDescription()), true, false, false));
}
}
@@ -1098,19 +1020,13 @@
*/
public MBeanParameterInfo toJMXParameterInfo()
{
- if (isMultiValued())
- {
- return new MBeanParameterInfo(getName(), JMX_TYPE_STRING_ARRAY,
- String.valueOf(getDescription()));
- }
- else
- {
- return new MBeanParameterInfo(getName(), String.class.getName(),
- String.valueOf(getDescription()));
- }
+ return new MBeanParameterInfo(getName(), getType(), String.valueOf(getDescription()));
}
-
+ private String getType()
+ {
+ return isMultiValued() ? JMX_TYPE_STRING_ARRAY : String.class.getName();
+ }
/**
* Attempts to set the value of this configuration attribute based on the
@@ -1129,8 +1045,7 @@
Object value = jmxAttribute.getValue();
if (value == null)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_NULL.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_DN_NULL.get(getName()));
}
else if (value instanceof DN)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java
index 9f2cebb..68f6d22 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java
@@ -26,8 +26,6 @@
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
-
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -37,14 +35,16 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
import org.opends.server.util.CollectionUtils;
-import org.forgerock.opendj.ldap.ByteString;
-import static org.opends.server.config.ConfigConstants.*;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
+
import static org.opends.messages.ConfigMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
/**
* This class defines an integer configuration attribute, which can hold zero or
@@ -64,24 +64,17 @@
/** The set of active values for this attribute. */
private List<Long> activeValues;
-
/** The set of pending values for this attribute. */
private List<Long> pendingValues;
-
/** Indicates whether this attribute will impose a lower bound for its values. */
private boolean hasLowerBound;
-
/** Indicates whether this attribute will impose an upper bound for its values. */
private boolean hasUpperBound;
-
/** The lower bound for values of this attribute. */
private long lowerBound;
-
/** The upper bound for values of this attribute. */
private long upperBound;
-
-
/**
* Creates a new integer configuration attribute stub with the provided
* information but no values. The values will be set using the
@@ -114,7 +107,6 @@
{
super(name, description, isRequired, isMultiValued, requiresAdminAction);
-
this.hasLowerBound = hasLowerBound;
this.lowerBound = lowerBound;
this.hasUpperBound = hasUpperBound;
@@ -124,8 +116,6 @@
pendingValues = activeValues;
}
-
-
/**
* Creates a new integer configuration attribute with the provided
* information. No validation will be performed on the provided value.
@@ -159,8 +149,7 @@
long value)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(value));
-
+ getLongValueSet(value));
this.hasLowerBound = hasLowerBound;
this.lowerBound = lowerBound;
@@ -171,8 +160,6 @@
pendingValues = activeValues;
}
-
-
/**
* Creates a new integer configuration attribute with the provided
* information. No validation will be performed on the provided values.
@@ -206,8 +193,7 @@
List<Long> values)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(values));
-
+ getLongValueSet(values));
this.hasLowerBound = hasLowerBound;
this.lowerBound = lowerBound;
@@ -218,8 +204,6 @@
pendingValues = activeValues;
}
-
-
/**
* Creates a new integer configuration attribute with the provided
* information. No validation will be performed on the provided values.
@@ -256,9 +240,8 @@
List<Long> pendingValues)
{
super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(activeValues), (pendingValues != null),
- getValueSet(pendingValues));
-
+ getLongValueSet(activeValues), (pendingValues != null),
+ getLongValueSet(pendingValues));
this.hasLowerBound = hasLowerBound;
this.lowerBound = lowerBound;
@@ -284,8 +267,6 @@
}
}
-
-
/**
* Retrieves the name of the data type for this configuration attribute. This
* is for informational purposes (e.g., inclusion in method signatures and
@@ -299,8 +280,6 @@
return "Integer";
}
-
-
/**
* Retrieves the attribute syntax for this configuration attribute.
*
@@ -311,8 +290,6 @@
return DirectoryServer.getDefaultIntegerSyntax();
}
-
-
/**
* Retrieves the active value for this configuration attribute as a long.
* This is only valid for single-valued attributes that have a value.
@@ -325,7 +302,7 @@
public long activeValue()
throws ConfigException
{
- if ((activeValues == null) || activeValues.isEmpty())
+ if (activeValues == null || activeValues.isEmpty())
{
LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
throw new ConfigException(message);
@@ -340,8 +317,6 @@
return activeValues.get(0);
}
-
-
/**
* Retrieves the active value for this configuration attribute as an integer.
* This is only valid for single-valued attributes that have a value within
@@ -357,7 +332,7 @@
public int activeIntValue()
throws ConfigException
{
- if ((activeValues == null) || activeValues.isEmpty())
+ if (activeValues == null || activeValues.isEmpty())
{
LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
throw new ConfigException(message);
@@ -382,8 +357,6 @@
}
}
-
-
/**
* Retrieves the set of active values for this configuration attribute.
*
@@ -394,8 +367,6 @@
return activeValues;
}
-
-
/**
* Retrieves the pending value for this configuration attribute as a long.
* This is only valid for single-valued attributes that have a value. If this
@@ -415,7 +386,7 @@
return activeValue();
}
- if ((pendingValues == null) || pendingValues.isEmpty())
+ if (pendingValues == null || pendingValues.isEmpty())
{
LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
throw new ConfigException(message);
@@ -430,8 +401,6 @@
return pendingValues.get(0);
}
-
-
/**
* Retrieves the pending value for this configuration attribute as an integer.
* This is only valid for single-valued attributes that have a value within
@@ -453,7 +422,7 @@
return activeIntValue();
}
- if ((pendingValues == null) || pendingValues.isEmpty())
+ if (pendingValues == null || pendingValues.isEmpty())
{
LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
throw new ConfigException(message);
@@ -478,8 +447,6 @@
}
}
-
-
/**
* Retrieves the set of pending values for this configuration attribute. If
* there are no pending values, then the set of active values will be
@@ -497,8 +464,6 @@
return pendingValues;
}
-
-
/**
* Indicates whether a lower bound will be enforced for the value of this
* configuration attribute.
@@ -512,8 +477,6 @@
return hasLowerBound;
}
-
-
/**
* Retrieves the lower bound for the value of this configuration attribute.
*
@@ -524,8 +487,6 @@
return lowerBound;
}
-
-
/**
* Indicates whether an upper bound will be enforced for the calculated value
* of this configuration attribute.
@@ -539,8 +500,6 @@
return hasUpperBound;
}
-
-
/**
* Retrieves the upper bound for the calculated value of this configuration
* attribute.
@@ -553,8 +512,6 @@
return upperBound;
}
-
-
/**
* Sets the value for this integer configuration attribute.
*
@@ -565,14 +522,14 @@
public void setValue(long value)
throws ConfigException
{
- if (hasLowerBound && (value < lowerBound))
+ if (hasLowerBound && value < lowerBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
getName(), value, lowerBound);
throw new ConfigException(message);
}
- if (hasUpperBound && (value > upperBound))
+ if (hasUpperBound && value > upperBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
getName(), value, upperBound);
@@ -582,19 +539,17 @@
if (requiresAdminAction())
{
pendingValues = CollectionUtils.newArrayList(value);
- setPendingValues(getValueSet(value));
+ setPendingValues(getLongValueSet(value));
}
else
{
activeValues.clear();
activeValues.add(value);
pendingValues = activeValues;
- setActiveValues(getValueSet(value));
+ setActiveValues(getLongValueSet(value));
}
}
-
-
/**
* Sets the values for this integer configuration attribute.
*
@@ -607,52 +562,47 @@
throws ConfigException
{
// First check if the set is empty and if that is allowed.
- if ((values == null) || (values.isEmpty()))
+ if (values == null || values.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
+ }
+
+ if (requiresAdminAction())
+ {
+ setPendingValues(new LinkedHashSet<ByteString>(0));
+ pendingValues = new ArrayList<>();
}
else
{
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- setActiveValues(new LinkedHashSet<ByteString>(0));
- activeValues.clear();
- }
+ setActiveValues(new LinkedHashSet<ByteString>(0));
+ activeValues.clear();
}
}
-
// Next check if the set contains multiple values and if that is allowed.
int numValues = values.size();
- if ((! isMultiValued()) && (numValues > 1))
+ if (!isMultiValued() && numValues > 1)
{
LocalizableMessage message =
ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
throw new ConfigException(message);
}
-
// Iterate through all the provided values, make sure that they are
// acceptable, and build the value set.
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (long value : values)
{
- if (hasLowerBound && (value < lowerBound))
+ if (hasLowerBound && value < lowerBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
getName(), value, lowerBound);
throw new ConfigException(message);
}
- if (hasUpperBound && (value > upperBound))
+ if (hasUpperBound && value > upperBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
getName(), value, upperBound);
@@ -671,7 +621,6 @@
valueSet.add(attrValue);
}
-
// Apply this value set to the new active or pending value set.
if (requiresAdminAction())
{
@@ -686,8 +635,6 @@
}
}
-
-
/**
* Creates the appropriate value set with the provided value.
*
@@ -695,15 +642,11 @@
*
* @return The constructed value set.
*/
- private static LinkedHashSet<ByteString> getValueSet(long value)
+ private static LinkedHashSet<ByteString> getLongValueSet(long value)
{
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(String.valueOf(value)));
- return valueSet;
+ return getValueSet(String.valueOf(value));
}
-
-
/**
* Creates the appropriate value set with the provided values.
*
@@ -711,7 +654,7 @@
*
* @return The constructed value set.
*/
- private static LinkedHashSet<ByteString> getValueSet(List<Long> values)
+ private static LinkedHashSet<ByteString> getLongValueSet(List<Long> values)
{
if (values == null)
{
@@ -726,8 +669,6 @@
return valueSet;
}
-
-
/**
* Applies the set of pending values, making them the active values for this
* configuration attribute. This will not take any action if there are no
@@ -744,8 +685,6 @@
activeValues = pendingValues;
}
-
-
/**
* Indicates whether the provided value is acceptable for use in this
* attribute. If it is not acceptable, then the reason should be written into
@@ -776,29 +715,25 @@
return false;
}
-
// Perform any necessary bounds checking.
- if (hasLowerBound && (longValue < lowerBound))
+ if (hasLowerBound && longValue < lowerBound)
{
rejectReason.append(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
getName(), longValue, lowerBound));
return false;
}
- if (hasUpperBound && (longValue > upperBound))
+ if (hasUpperBound && longValue > upperBound)
{
rejectReason.append(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
getName(), longValue, upperBound));
return false;
}
-
// If we've gotten here, then the value must be acceptable.
return true;
}
-
-
/**
* Converts the provided set of strings to a corresponding set of attribute
* values.
@@ -822,29 +757,21 @@
stringsToValues(List<String> valueStrings, boolean allowFailures)
throws ConfigException
{
- if ((valueStrings == null) || valueStrings.isEmpty())
+ if (valueStrings == null || valueStrings.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
- else
- {
- return new LinkedHashSet<>();
- }
+ return new LinkedHashSet<>();
}
-
int numValues = valueStrings.size();
- if ((! isMultiValued()) && (numValues > 1))
+ if (!isMultiValued() && numValues > 1)
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
-
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (String valueString : valueStrings)
{
@@ -857,70 +784,43 @@
{
logger.traceException(e);
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(
- valueString, getName(), e);
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(valueString, getName(), e));
+ continue;
}
-
- if (hasLowerBound && (longValue < lowerBound))
+ if (hasLowerBound && longValue < lowerBound)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- getName(), longValue, lowerBound);
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(getName(), longValue, lowerBound));
+ continue;
}
-
-
- if (hasUpperBound && (longValue > upperBound))
+ if (hasUpperBound && longValue > upperBound)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- getName(), longValue, upperBound);
-
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(getName(), longValue, upperBound));
+ continue;
}
valueSet.add(ByteString.valueOf(valueString));
}
-
// If this method was configured to continue on error, then it is possible
// that we ended up with an empty list. Check to see if this is a required
// attribute and if so deal with it accordingly.
- if ((isRequired()) && valueSet.isEmpty())
+ if (isRequired() && valueSet.isEmpty())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
-
return valueSet;
}
-
+ private void reportError(boolean allowFailures, LocalizableMessage message) throws ConfigException
+ {
+ if (!allowFailures)
+ {
+ throw new ConfigException(message);
+ }
+ logger.error(message);
+ }
/**
* Converts the set of active values for this configuration attribute into a
@@ -937,8 +837,6 @@
return toListOfString(activeValues);
}
-
-
/**
* Converts the set of pending values for this configuration attribute into a
* set of strings that may be stored in the configuration or represented over
@@ -956,30 +854,19 @@
{
return toListOfString(pendingValues);
}
- else
- {
- return null;
- }
+ return null;
}
-
-
- /**
- * @param pendingValues2
- * @return
- */
- private List<String> toListOfString(List<Long> pendingValues2)
+ private List<String> toListOfString(List<Long> values)
{
- ArrayList<String> valueStrings = new ArrayList<>(pendingValues2.size());
- for (long l : pendingValues2)
+ ArrayList<String> results = new ArrayList<>(values.size());
+ for (long l : values)
{
- valueStrings.add(String.valueOf(l));
+ results.add(String.valueOf(l));
}
- return valueStrings;
+ return results;
}
-
-
/**
* Retrieves a new configuration attribute of this type that will contain the
* values from the provided attribute.
@@ -1022,7 +909,6 @@
throw new ConfigException(message);
}
-
if (a.isEmpty())
{
if (isRequired())
@@ -1040,7 +926,7 @@
else
{
int numValues = a.size();
- if ((numValues > 1) && (! isMultiValued()))
+ if (numValues > 1 && !isMultiValued())
{
// This is illegal -- the attribute is single-valued.
LocalizableMessage message =
@@ -1063,16 +949,15 @@
throw new ConfigException(message, e);
}
-
// Check the bounds set for this attribute.
- if (hasLowerBound && (longValue < lowerBound))
+ if (hasLowerBound && longValue < lowerBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
a.getName(), longValue, lowerBound);
throw new ConfigException(message);
}
- if (hasUpperBound && (longValue > upperBound))
+ if (hasUpperBound && longValue > upperBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
a.getName(), longValue, upperBound);
@@ -1104,7 +989,6 @@
throw new ConfigException(message);
}
-
if (a.isEmpty())
{
if (isRequired())
@@ -1122,7 +1006,7 @@
else
{
int numValues = a.size();
- if ((numValues > 1) && (! isMultiValued()))
+ if (numValues > 1 && !isMultiValued())
{
// This is illegal -- the attribute is single-valued.
LocalizableMessage message =
@@ -1145,16 +1029,15 @@
throw new ConfigException(message, e);
}
-
// Check the bounds set for this attribute.
- if (hasLowerBound && (longValue < lowerBound))
+ if (hasLowerBound && longValue < lowerBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
a.getName(), longValue, lowerBound);
throw new ConfigException(message);
}
- if (hasUpperBound && (longValue > upperBound))
+ if (hasUpperBound && longValue > upperBound)
{
LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
a.getName(), longValue, upperBound);
@@ -1180,15 +1063,12 @@
pendingValues = activeValues;
}
-
return new IntegerConfigAttribute(getName(), getDescription(), isRequired(),
isMultiValued(), requiresAdminAction(),
hasLowerBound, lowerBound, hasUpperBound,
upperBound, activeValues, pendingValues);
}
-
-
/**
* Retrieves a JMX attribute containing the value set for this
* configuration attribute (active or pending).
@@ -1224,20 +1104,16 @@
return new javax.management.Attribute(name, values);
}
+ else if (requestedValues.isEmpty())
+ {
+ return null;
+ }
else
{
- if (requestedValues.isEmpty())
- {
- return null;
- }
- else
- {
- return new javax.management.Attribute(name, requestedValues.get(0));
- }
+ return new javax.management.Attribute(name, requestedValues.get(0));
}
}
-
/**
* Retrieves a JMX attribute containing the active value set for this
* configuration attribute.
@@ -1247,9 +1123,9 @@
* any active values.
*/
public javax.management.Attribute toJMXAttribute()
- {
- return _toJMXAttribute(false);
- }
+ {
+ return _toJMXAttribute(false);
+ }
/**
* Retrieves a JMX attribute containing the pending value set for this
@@ -1263,8 +1139,6 @@
return _toJMXAttribute(true);
}
-
-
/**
* Adds information about this configuration attribute to the provided JMX
* attribute list. If this configuration attribute requires administrative
@@ -1309,9 +1183,9 @@
}
}
-
- if (requiresAdminAction() && (pendingValues != null) &&
- (pendingValues != activeValues))
+ if (requiresAdminAction()
+ && pendingValues != null
+ && pendingValues != activeValues)
{
String name = getName() + ";" + OPTION_PENDING_VALUES;
@@ -1333,8 +1207,6 @@
}
}
-
-
/**
* Adds information about this configuration attribute to the provided list in
* the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
@@ -1366,7 +1238,6 @@
true, true, false));
}
-
if (requiresAdminAction())
{
String name = getName() + ";" + OPTION_PENDING_VALUES;
@@ -1388,8 +1259,6 @@
}
}
-
-
/**
* Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
* configuration attribute.
@@ -1411,8 +1280,6 @@
}
}
-
-
/**
* Attempts to set the value of this configuration attribute based on the
* information in the provided JMX attribute.
@@ -1521,8 +1388,6 @@
}
}
-
-
/**
* Creates a duplicate of this configuration attribute.
*
@@ -1536,4 +1401,3 @@
upperBound, activeValues, pendingValues);
}
}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java
index f3d34e3..37de244 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java
@@ -592,17 +592,13 @@
*
* @return The constructed value set.
*/
- private static LinkedHashSet<ByteString> getValueSet(long intValue,
- String unit)
+ private static LinkedHashSet<ByteString> getValueSet(long intValue, String unit)
{
- if (unit == null)
+ if (unit != null)
{
- return null;
+ return getValueSet(intValue + " " + unit);
}
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(intValue + " " + unit));
- return valueSet;
+ return null;
}
@@ -760,57 +756,33 @@
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
- else
- {
- return new LinkedHashSet<>();
- }
+ return new LinkedHashSet<>();
}
int numValues = valueStrings.size();
if ((! isMultiValued()) && (numValues > 1))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (String valueString : valueStrings)
{
- if ((valueString == null) || (valueString.length() == 0))
+ if (valueString == null || valueString.length() == 0)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
+ continue;
}
-
StringBuilder rejectReason = new StringBuilder();
- if (! valueIsAcceptable(valueString.toLowerCase(), rejectReason))
+ if (!valueIsAcceptable(valueString.toLowerCase(), rejectReason))
{
- LocalizableMessage message = ERR_CONFIG_ATTR_INVALID_VALUE_WITH_UNIT.get(
- valueString, getName(), rejectReason);
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_INVALID_VALUE_WITH_UNIT.get(valueString, getName(), rejectReason));
+ continue;
}
valueSet.add(ByteString.valueOf(valueString));
@@ -822,15 +794,21 @@
// attribute and if so deal with it accordingly.
if ((isRequired()) && valueSet.isEmpty())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
return valueSet;
}
-
+ private void reportError(boolean allowFailures, LocalizableMessage message) throws ConfigException
+ {
+ if (!allowFailures)
+ {
+ throw new ConfigException(message);
+ }
+ logger.error(message);
+ }
/**
* Converts the set of active values for this configuration attribute into a
@@ -908,86 +886,30 @@
if (a.hasOptions())
{
// This must be the pending value.
- if (a.hasOption(OPTION_PENDING_VALUES))
+ if (!a.hasOption(OPTION_PENDING_VALUES))
{
- if (pendingUnit != null)
- {
- // We cannot have multiple pending value sets.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
- }
-
-
- if (a.isEmpty())
- {
- // This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
- }
- else
- {
- Iterator<ByteString> iterator = a.iterator();
- String valueString = iterator.next().toString();
- if (iterator.hasNext())
- {
- // This is illegal -- the attribute is single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
- }
-
- try
- {
- int spacePos = valueString.indexOf(' ');
- pendingIntValue =
- Long.parseLong(valueString.substring(0, spacePos));
- pendingUnit = valueString.substring(spacePos+1).trim();
- }
- catch (Exception e)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.
- get(valueString, a.getName(), e));
- }
-
-
- // Get the unit and use it to determine the corresponding
- // multiplier.
- if (! units.containsKey(pendingUnit))
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, a.getName());
- throw new ConfigException(message);
- }
-
- double multiplier = units.get(activeUnit);
- pendingCalculatedValue = (long) (multiplier * pendingIntValue);
-
-
- // Check the bounds set for this attribute.
- if (hasLowerBound && (pendingCalculatedValue < lowerBound))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- a.getName(), pendingCalculatedValue, lowerBound);
- throw new ConfigException(message);
- }
-
- if (hasUpperBound && (pendingCalculatedValue > upperBound))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- a.getName(), pendingCalculatedValue, upperBound);
- throw new ConfigException(message);
- }
- }
+ // This is illegal -- only the pending option is allowed for configuration attributes.
+ throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()));
}
- else
+ if (pendingUnit != null)
{
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName());
- throw new ConfigException(message);
+ // We cannot have multiple pending value sets.
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()));
}
+
+ String valueString = getValue(a);
+ try
+ {
+ int spacePos = valueString.indexOf(' ');
+ pendingIntValue = Long.parseLong(valueString.substring(0, spacePos));
+ pendingUnit = valueString.substring(spacePos + 1).trim();
+ }
+ catch (Exception e)
+ {
+ throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(valueString, a.getName(), e));
+ }
+
+ pendingCalculatedValue = calculateValue(pendingIntValue, activeUnit, pendingUnit, a);
}
else
{
@@ -995,79 +917,29 @@
if (activeUnit != null)
{
// We cannot have multiple active value sets.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()));
}
-
- if (a.isEmpty())
+ String valueString = getValue(a);
+ try
{
- // This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ int spacePos = valueString.indexOf(' ');
+ activeIntValue = Long.parseLong(valueString.substring(0, spacePos));
+ activeUnit = valueString.substring(spacePos + 1).trim();
}
- else
+ catch (Exception e)
{
- Iterator<ByteString> iterator = a.iterator();
- String valueString = iterator.next().toString();
- if (iterator.hasNext())
- {
- // This is illegal -- the attribute is single-valued.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
- throw new ConfigException(message);
- }
-
- try
- {
- int spacePos = valueString.indexOf(' ');
- activeIntValue =
- Long.parseLong(valueString.substring(0, spacePos));
- activeUnit = valueString.substring(spacePos+1).trim();
- }
- catch (Exception e)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(
- valueString, a.getName(), e));
- }
-
-
- // Get the unit and use it to determine the corresponding multiplier.
- if (! units.containsKey(activeUnit))
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_INVALID_UNIT.get(activeUnit, a.getName());
- throw new ConfigException(message);
- }
-
- double multiplier = units.get(activeUnit);
- activeCalculatedValue = (long) (multiplier * activeIntValue);
-
-
- // Check the bounds set for this attribute.
- if (hasLowerBound && (activeCalculatedValue < lowerBound))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- a.getName(), activeCalculatedValue, lowerBound);
- throw new ConfigException(message);
- }
-
- if (hasUpperBound && (activeCalculatedValue > upperBound))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- a.getName(), activeCalculatedValue, upperBound);
- throw new ConfigException(message);
- }
+ throw new ConfigException(ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(valueString, a.getName(), e));
}
+
+ activeCalculatedValue = calculateValue(activeIntValue, activeUnit, activeUnit, a);
}
}
if (activeUnit == null)
{
// This is not OK. The value set must contain an active value.
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()));
}
if (pendingUnit == null)
@@ -1086,7 +958,46 @@
pendingIntValue, pendingUnit);
}
+ private String getValue(Attribute a) throws ConfigException
+ {
+ if (a.isEmpty())
+ {
+ // This is illegal -- it must have a value.
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
+ }
+ Iterator<ByteString> iterator = a.iterator();
+ String valueString = iterator.next().toString();
+ if (iterator.hasNext())
+ {
+ // This is illegal -- the attribute is single-valued.
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()));
+ }
+ return valueString;
+ }
+
+ private long calculateValue(long intValue, String activeUnit, String pendingUnit, Attribute a) throws ConfigException
+ {
+ // Get the unit and use it to determine the corresponding multiplier.
+ if (!units.containsKey(pendingUnit))
+ {
+ throw new ConfigException(ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, a.getName()));
+ }
+
+ double multiplier = units.get(activeUnit);
+ final long result = (long) (multiplier * intValue);
+
+ // Check the bounds set for this attribute.
+ if (hasLowerBound && result < lowerBound)
+ {
+ throw new ConfigException(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(a.getName(), result, lowerBound));
+ }
+ if (hasUpperBound && result > upperBound)
+ {
+ throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(a.getName(), result, upperBound));
+ }
+ return result;
+ }
/**
* Retrieves a JMX attribute containing the active value set for this
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java
index 5f09fd5..794196f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java
@@ -26,25 +26,26 @@
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
-
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+
import javax.management.AttributeList;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
import org.opends.server.util.CollectionUtils;
-import org.forgerock.opendj.ldap.ByteString;
-import static org.opends.server.config.ConfigConstants.*;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
+
import static org.opends.messages.ConfigMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
/**
* This class defines a multi-choice configuration attribute, which can hold
@@ -438,25 +439,22 @@
throws ConfigException
{
// First check if the set is empty and if that is allowed.
- if ((values == null) || (values.isEmpty()))
+ if (values == null || values.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
+ }
+
+ if (requiresAdminAction())
+ {
+ setPendingValues(new LinkedHashSet<ByteString>(0));
+ pendingValues = new ArrayList<>();
}
else
{
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- setActiveValues(new LinkedHashSet<ByteString>(0));
- activeValues.clear();
- }
+ setActiveValues(new LinkedHashSet<ByteString>(0));
+ activeValues.clear();
}
}
@@ -465,9 +463,7 @@
int numValues = values.size();
if ((! isMultiValued()) && (numValues > 1))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
@@ -476,26 +472,19 @@
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (String value : values)
{
- if ((value == null) || (value.length() == 0))
+ if (value == null || value.length() == 0)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
}
-
-
- if (! allowedValues.contains(value.toLowerCase()))
+ if (!allowedValues.contains(value.toLowerCase()))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(value, getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(value, getName()));
}
ByteString attrValue = ByteString.valueOf(value);
if (valueSet.contains(attrValue))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value);
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
}
valueSet.add(attrValue);
@@ -516,48 +505,6 @@
}
}
-
-
- /**
- * Creates the appropriate value set with the provided value.
- *
- * @param value The value to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(String value)
- {
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(value));
- return valueSet;
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided values.
- *
- * @param values The values to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(List<String> values)
- {
- if (values == null)
- {
- return null;
- }
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(values.size());
- for (String value : values)
- {
- valueSet.add(ByteString.valueOf(value));
- }
- return valueSet;
- }
-
-
-
/**
* Applies the set of pending values, making them the active values for this
* configuration attribute. This will not take any action if there are no
@@ -637,76 +584,58 @@
stringsToValues(List<String> valueStrings, boolean allowFailures)
throws ConfigException
{
- if ((valueStrings == null) || valueStrings.isEmpty())
+ if (valueStrings == null || valueStrings.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
return new LinkedHashSet<>();
}
-
int numValues = valueStrings.size();
- if ((! isMultiValued()) && (numValues > 1))
+ if (!isMultiValued() && numValues > 1)
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
-
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (String valueString : valueStrings)
{
- if ((valueString == null) || (valueString.length() == 0))
+ if (valueString == null || valueString.length() == 0)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
+ continue;
}
-
if (! allowedValues.contains(valueString.toLowerCase()))
{
- LocalizableMessage message = ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(
- valueString, getName());
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(valueString, getName()));
+ continue;
}
valueSet.add(ByteString.valueOf(valueString));
}
-
// If this method was configured to continue on error, then it is possible
// that we ended up with an empty list. Check to see if this is a required
// attribute and if so deal with it accordingly.
- if ((isRequired()) && valueSet.isEmpty())
+ if (isRequired() && valueSet.isEmpty())
{
LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
throw new ConfigException(message);
}
-
return valueSet;
}
-
+ private void reportError(boolean allowFailures, LocalizableMessage message) throws ConfigException
+ {
+ if (!allowFailures)
+ {
+ throw new ConfigException(message);
+ }
+ logger.error(message);
+ }
/**
* Converts the set of active values for this configuration attribute into a
@@ -715,8 +644,7 @@
* compatible with the decoding used by the <CODE>stringsToValues</CODE>
* method.
*
- * @return The string representations of the set of active values for this
- * configuration attribute.
+ * @return The string representations of the set of active values for this configuration attribute.
*/
public List<String> activeValuesToStrings()
{
@@ -1051,46 +979,14 @@
*/
public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
{
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, true,
- false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, true,
- false));
- }
-
+ attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
+ String.valueOf(getDescription()), true, true, false));
if (requiresAdminAction())
{
String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
+ attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
+ String.valueOf(getDescription()), true, false, false));
}
}
@@ -1105,19 +1001,13 @@
*/
public MBeanParameterInfo toJMXParameterInfo()
{
- if (isMultiValued())
- {
- return new MBeanParameterInfo(getName(), JMX_TYPE_STRING_ARRAY,
- String.valueOf(getDescription()));
- }
- else
- {
- return new MBeanParameterInfo(getName(), String.class.getName(),
- String.valueOf(getDescription()));
- }
+ return new MBeanParameterInfo(getName(), getType(), String.valueOf(getDescription()));
}
-
+ private String getType()
+ {
+ return isMultiValued() ? JMX_TYPE_STRING_ARRAY : String.class.getName();
+ }
/**
* Attempts to set the value of this configuration attribute based on the
@@ -1198,4 +1088,3 @@
activeValues, pendingValues);
}
}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java
index e454b5e..e9ebad1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java
@@ -26,23 +26,24 @@
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
-
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
+
import javax.management.AttributeList;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.ByteString;
+import static org.opends.messages.ConfigMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.CollectionUtils.*;
-import static org.opends.messages.ConfigMessages.*;
+
/**
* This class defines a configuration attribute that is only intended for use
* in displaying information. It will not allow its value to be altered.
@@ -240,11 +241,9 @@
*
* @throws ConfigException If the provided value is not acceptable.
*/
- public void setValue(String value)
- throws ConfigException
+ public void setValue(String value) throws ConfigException
{
- LocalizableMessage message = ERR_CONFIG_ATTR_READ_ONLY.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
}
@@ -257,45 +256,9 @@
* @throws ConfigException If the provided value set or any of the
* individual values are not acceptable.
*/
- public void setValues(List<String> values)
- throws ConfigException
+ public void setValues(List<String> values) throws ConfigException
{
- LocalizableMessage message = ERR_CONFIG_ATTR_READ_ONLY.get(getName());
- throw new ConfigException(message);
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided value.
- *
- * @param value The value to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(String value)
- {
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(value));
- return valueSet;
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided values.
- *
- * @param values The values to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(List<String> values)
- {
- if (values != null)
- {
- return toByteStrings(values);
- }
- return null;
+ throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
}
@@ -350,29 +313,16 @@
* @throws ConfigException If an unrecoverable problem occurs while
* performing the conversion.
*/
- public LinkedHashSet<ByteString>
- stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
+ public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings, boolean allowFailures)
+ throws ConfigException
{
- if ((valueStrings == null) || valueStrings.isEmpty())
+ if (valueStrings == null || valueStrings.isEmpty())
{
return new LinkedHashSet<>();
}
- return toByteStrings(valueStrings);
+ return getValueSet(valueStrings);
}
- private static LinkedHashSet<ByteString> toByteStrings(List<String> strings)
- {
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(strings.size());
- for (String valueString : strings)
- {
- valueSet.add(ByteString.valueOf(valueString));
- }
- return valueSet;
- }
-
-
-
/**
* Converts the set of active values for this configuration attribute into a
* set of strings that may be stored in the configuration or represented over
@@ -451,21 +401,16 @@
{
if (isMultiValued())
{
- String[] valueArray = new String[values.size()];
- values.toArray(valueArray);
-
+ String[] valueArray = values.toArray(new String[values.size()]);
return new javax.management.Attribute(getName(), valueArray);
}
+ else if (!values.isEmpty())
+ {
+ return new javax.management.Attribute(getName(), values.get(0));
+ }
else
{
- if (values.isEmpty())
- {
- return null;
- }
- else
- {
- return new javax.management.Attribute(getName(), values.get(0));
- }
+ return null;
}
}
@@ -478,9 +423,10 @@
* configuration attribute, or <CODE>null</CODE> if it does
* not have any active values.
*/
+ @Override
public javax.management.Attribute toJMXAttributePending()
{
- // Should never occurs !!!
+ // Should never occur !!!
return toJMXAttribute();
}
@@ -499,8 +445,7 @@
*/
public void toJMXAttribute(AttributeList attributeList)
{
- javax.management.Attribute jmxAttr = toJMXAttribute();
- attributeList.add(jmxAttr);
+ attributeList.add(toJMXAttribute());
}
@@ -519,22 +464,8 @@
*/
public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
{
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
+ attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
+ String.valueOf(getDescription()), true, false, false));
}
@@ -548,19 +479,13 @@
*/
public MBeanParameterInfo toJMXParameterInfo()
{
- if (isMultiValued())
- {
- return new MBeanParameterInfo(getName(), JMX_TYPE_STRING_ARRAY,
- String.valueOf(getDescription()));
- }
- else
- {
- return new MBeanParameterInfo(getName(), String.class.getName(),
- String.valueOf(getDescription()));
- }
+ return new MBeanParameterInfo(getName(), getType(), String.valueOf(getDescription()));
}
-
+ private String getType()
+ {
+ return isMultiValued() ? JMX_TYPE_STRING_ARRAY : String.class.getName();
+ }
/**
* Attempts to set the value of this configuration attribute based on the
@@ -576,8 +501,7 @@
public void setValue(javax.management.Attribute jmxAttribute)
throws ConfigException
{
- LocalizableMessage message = ERR_CONFIG_ATTR_READ_ONLY.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
}
@@ -589,8 +513,6 @@
*/
public ConfigAttribute duplicate()
{
- return new ReadOnlyConfigAttribute(getName(), getDescription(),
- activeValues());
+ return new ReadOnlyConfigAttribute(getName(), getDescription(), activeValues());
}
}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java b/opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java
index 6bace67..fb70fba 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java
@@ -26,7 +26,9 @@
*/
package org.opends.server.config;
-import org.forgerock.i18n.LocalizableMessage;
+import static org.opends.messages.ConfigMessages.*;
+import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.util.CollectionUtils.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
@@ -37,15 +39,12 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ByteString;
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.util.CollectionUtils.*;
-
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-import static org.opends.messages.ConfigMessages.*;
+import org.opends.server.types.Attribute;
/**
* This class defines a string configuration attribute, which can hold zero or
@@ -330,11 +329,10 @@
*/
public List<String> pendingValues()
{
- if (! hasPendingValues())
+ if (!hasPendingValues())
{
return activeValues;
}
-
return pendingValues;
}
@@ -350,10 +348,9 @@
public void setValue(String value)
throws ConfigException
{
- if ((value == null) || (value.length() == 0))
+ if (value == null || value.length() == 0)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
}
if (requiresAdminAction())
@@ -384,25 +381,22 @@
throws ConfigException
{
// First check if the set is empty and if that is allowed.
- if ((values == null) || (values.isEmpty()))
+ if (values == null || values.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
+ }
+
+ if (requiresAdminAction())
+ {
+ setPendingValues(new LinkedHashSet<ByteString>(0));
+ pendingValues = new ArrayList<>();
}
else
{
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- setActiveValues(new LinkedHashSet<ByteString>(0));
- activeValues.clear();
- }
+ setActiveValues(new LinkedHashSet<ByteString>(0));
+ activeValues.clear();
}
}
@@ -411,9 +405,7 @@
int numValues = values.size();
if ((! isMultiValued()) && (numValues > 1))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
@@ -424,16 +416,13 @@
{
if ((value == null) || (value.length() == 0))
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
}
ByteString attrValue = ByteString.valueOf(value);
if (valueSet.contains(attrValue))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value);
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
}
valueSet.add(attrValue);
@@ -457,46 +446,6 @@
/**
- * Creates the appropriate value set with the provided value.
- *
- * @param value The value to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(String value)
- {
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(1);
- valueSet.add(ByteString.valueOf(value));
- return valueSet;
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided values.
- *
- * @param values The values to use to create the value set.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(List<String> values)
- {
- if (values == null)
- {
- return null;
- }
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(values.size());
- for (String value : values)
- {
- valueSet.add(ByteString.valueOf(value));
- }
- return valueSet;
- }
-
-
-
- /**
* Applies the set of pending values, making them the active values for this
* configuration attribute. This will not take any action if there are no
* pending values.
@@ -559,50 +508,31 @@
* @throws ConfigException If an unrecoverable problem occurs while
* performing the conversion.
*/
- public LinkedHashSet<ByteString>
- stringsToValues(List<String> valueStrings,
- boolean allowFailures)
- throws ConfigException
+ public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings, boolean allowFailures)
+ throws ConfigException
{
- if ((valueStrings == null) || valueStrings.isEmpty())
+ if (valueStrings == null || valueStrings.isEmpty())
{
if (isRequired())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
- else
- {
- return new LinkedHashSet<>();
- }
+ return new LinkedHashSet<>();
}
-
int numValues = valueStrings.size();
if ((! isMultiValued()) && (numValues > 1))
{
- LocalizableMessage message =
- ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
}
-
LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
for (String valueString : valueStrings)
{
- if ((valueString == null) || (valueString.length() == 0))
+ if (valueString == null || valueString.length() == 0)
{
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
-
- if (allowFailures)
- {
- logger.error(message);
- continue;
- }
- else
- {
- throw new ConfigException(message);
- }
+ reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
+ continue;
}
valueSet.add(ByteString.valueOf(valueString));
@@ -611,16 +541,22 @@
// If this method was configured to continue on error, then it is possible
// that we ended up with an empty list. Check to see if this is a required
// attribute and if so deal with it accordingly.
- if ((isRequired()) && valueSet.isEmpty())
+ if (isRequired() && valueSet.isEmpty())
{
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
}
return valueSet;
}
-
+ private void reportError(boolean allowFailures, LocalizableMessage message) throws ConfigException
+ {
+ if (!allowFailures)
+ {
+ throw new ConfigException(message);
+ }
+ logger.error(message);
+ }
/**
* Converts the set of active values for this configuration attribute into a
@@ -656,10 +592,7 @@
{
return pendingValues;
}
- else
- {
- return null;
- }
+ return null;
}
@@ -701,9 +634,7 @@
if (pendingValues != null)
{
// We cannot have multiple pending value sets.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()));
}
@@ -712,14 +643,10 @@
if (isRequired())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
}
- else
- {
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
+ // This is fine. The pending value set can be empty.
+ pendingValues = new ArrayList<>(0);
}
else
{
@@ -743,9 +670,7 @@
{
// This is illegal -- only the pending option is allowed for
// configuration attributes.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()));
}
}
else
@@ -754,9 +679,7 @@
if (activeValues!= null)
{
// We cannot have multiple active value sets.
- LocalizableMessage message =
- ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()));
}
@@ -765,14 +688,10 @@
if (isRequired())
{
// This is illegal -- it must have a value.
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
- throw new ConfigException(message);
+ throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()));
}
- else
- {
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
+ // This is fine. The active value set can be empty.
+ activeValues = new ArrayList<>(0);
}
else
{
@@ -826,8 +745,8 @@
*/
private javax.management.Attribute _toJMXAttribute(boolean pending)
{
- List<String> requestedValues ;
- String name ;
+ List<String> requestedValues;
+ String name;
if (pending)
{
requestedValues = pendingValues ;
@@ -838,23 +757,19 @@
requestedValues = activeValues ;
name = getName() ;
}
+
if (isMultiValued())
{
- String[] values = new String[requestedValues.size()];
- requestedValues.toArray(values);
-
+ String[] values = requestedValues.toArray(new String[requestedValues.size()]);
return new javax.management.Attribute(name, values);
}
+ else if (!requestedValues.isEmpty())
+ {
+ return new javax.management.Attribute(name, requestedValues.get(0));
+ }
else
{
- if (requestedValues.isEmpty())
- {
- return null;
- }
- else
- {
- return new javax.management.Attribute(name, requestedValues.get(0));
- }
+ return null;
}
}
@@ -964,44 +879,14 @@
*/
public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
{
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, true, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, true, false));
- }
-
+ attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
+ String.valueOf(getDescription()), true, true, false));
if (requiresAdminAction())
{
String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- JMX_TYPE_STRING_ARRAY,
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(name,
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
+ attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
+ String.valueOf(getDescription()), true, false, false));
}
}
@@ -1016,19 +901,13 @@
*/
public MBeanParameterInfo toJMXParameterInfo()
{
- if (isMultiValued())
- {
- return new MBeanParameterInfo(getName(), JMX_TYPE_STRING_ARRAY,
- String.valueOf(getDescription()));
- }
- else
- {
- return new MBeanParameterInfo(getName(), String.class.getName(),
- String.valueOf(getDescription()));
- }
+ return new MBeanParameterInfo(getName(), getType(), String.valueOf(getDescription()));
}
-
+ private String getType()
+ {
+ return isMultiValued() ? JMX_TYPE_STRING_ARRAY : String.class.getName();
+ }
/**
* Attempts to set the value of this configuration attribute based on the
@@ -1108,4 +987,3 @@
activeValues, pendingValues);
}
}
-
--
Gitblit v1.10.0