From a5dcae36c87eb5908dc57846b747c4704bc18110 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 04 Apr 2016 13:38:35 +0000
Subject: [PATCH] Remove ConfigAttribute, InvokableComponent and InvokableMethod
---
/dev/null | 990 ----------------------------------------------------------
1 files changed, 0 insertions(+), 990 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
deleted file mode 100644
index 2e383ba..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/BooleanConfigAttribute.java
+++ /dev/null
@@ -1,674 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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.AttributeDescription;
-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 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.*;
-
-/**
- * This class defines a Boolean configuration attribute, which can hold a single
- * Boolean value of <CODE>true</CODE> or <CODE>false</CODE>. Boolean
- * configuration attributes will always be required and will never be
- * multivalued.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class BooleanConfigAttribute
- extends ConfigAttribute
-{
- /** The active value for this attribute. */
- private boolean activeValue;
-
- /** The pending value for this attribute. */
- private boolean pendingValue;
-
-
-
- /**
- * Creates a new Boolean configuration attribute stub with the provided
- * information but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- */
- public BooleanConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction)
- {
- super(name, description, true, false, requiresAdminAction);
-
- }
-
-
-
- /**
- * Creates a new Boolean configuration attribute with the provided
- * information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param value The value for this Boolean configuration
- * attribute.
- */
- public BooleanConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction,
- boolean value)
- {
- super(name, description, true, false, requiresAdminAction,
- getValueSet(value));
-
- activeValue = value;
- pendingValue = value;
- }
-
-
-
- /**
- * Creates a new Boolean configuration attribute with the provided
- * information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param activeValue The active value for this Boolean
- * configuration attribute.
- * @param pendingValue The pending value for this Boolean
- * configuration attribute.
- */
- public BooleanConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction,
- boolean activeValue, boolean pendingValue)
- {
- super(name, description, true, false, requiresAdminAction,
- getValueSet(activeValue), true, getValueSet(pendingValue));
-
-
- this.activeValue = activeValue;
- this.pendingValue = pendingValue;
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- public String getDataType()
- {
- return "Boolean";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultBooleanSyntax();
- }
-
-
-
- /**
- * Retrieves the active boolean value for this configuration attribute.
- *
- * @return The active boolean value for this configuration attribute.
- */
- public boolean activeValue()
- {
- return activeValue;
- }
-
-
-
- /**
- * Retrieves the pending boolean value for this configuration attribute. If
- * there is no pending value, then the active value will be returned.
- *
- * @return The pending boolean value for this configuration attribute.
- */
- public boolean pendingValue()
- {
- if (hasPendingValues())
- {
- return pendingValue;
- }
- return activeValue;
- }
-
-
-
- /**
- * Specifies the boolean value for this configuration attribute.
- *
- * @param booleanValue The boolean value for this configuration attribute.
- */
- public void setValue(boolean booleanValue)
- {
- if (requiresAdminAction())
- {
- pendingValue = booleanValue;
- setPendingValues(getValueSet(booleanValue));
- }
- else
- {
- activeValue = booleanValue;
- setActiveValues(getValueSet(booleanValue));
- }
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided value.
- *
- * @param booleanValue The boolean value to use to create the value set.
- *
- * @return The value set constructed from the provided value.
- */
- private static LinkedHashSet<ByteString> getValueSet(boolean booleanValue)
- {
- return getValueSet(booleanValue ? CONFIG_VALUE_TRUE : CONFIG_VALUE_FALSE);
- }
-
-
-
- /**
- * 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.
- */
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- activeValue = pendingValue;
- }
-
-
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * attribute. If it is not acceptable, then the reason should be written into
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- public boolean valueIsAcceptable(ByteString value,
- StringBuilder rejectReason)
- {
- String stringValue = value.toString();
- if (stringValue.equalsIgnoreCase(CONFIG_VALUE_TRUE) ||
- stringValue.equalsIgnoreCase(CONFIG_VALUE_FALSE))
- {
- return true;
- }
-
- rejectReason.append(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
- getName(), stringValue));
- return false;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings,
- boolean allowFailures) throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
- }
-
-
- Iterator<String> iterator = valueStrings.iterator();
- String valueString = iterator.next().toLowerCase();
- if (iterator.hasNext())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName());
- throw new ConfigException(message);
- }
-
- if (valueString.equals("true") || valueString.equals("yes") ||
- valueString.equals("on") || valueString.equals("1"))
- {
- return getValueSet(true);
- }
- else if (valueString.equals("false") || valueString.equals("no") ||
- valueString.equals("off") || valueString.equals("0"))
- {
- return getValueSet(false);
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), valueString);
- throw new ConfigException(message);
- }
- }
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * 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.
- */
- public List<String> activeValuesToStrings()
- {
- return newArrayList(String.valueOf(activeValue));
- }
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the {@link #stringsToValues(List, boolean)}
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or {@code null} if there are no
- * pending values.
- */
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- return newArrayList(String.valueOf(pendingValue));
- }
- return null;
- }
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- boolean activeValue = false;
- boolean pendingValue = false;
- boolean activeValueSet = false;
- boolean pendingValueSet = false;
-
- for (Attribute a : attributeList)
- {
- final AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- if (pendingValueSet)
- {
- // We cannot have multiple pending values.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
- if (a.isEmpty())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
-
- // 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
- {
- // This is an illegal value.
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), valueString));
- }
-
- if (iterator.hasNext())
- {
- // This is illegal -- it must be single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
- }
- else
- {
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- }
- else
- {
- // This must be the active value.
- if (activeValueSet)
- {
- // We cannot have multiple active values.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
- if (a.isEmpty())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
-
- // 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
- {
- // This is an illegal value.
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), valueString));
- }
-
- if (iterator.hasNext())
- {
- // This is illegal -- it must be single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
- }
- }
-
- if (! activeValueSet)
- {
- // This is not OK. The value set must contain an active value.
- throw new ConfigException(ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()));
- }
-
- if (pendingValueSet)
- {
- return new BooleanConfigAttribute(getName(), getDescription(),
- requiresAdminAction(), activeValue,
- pendingValue);
- }
- else
- {
- return new BooleanConfigAttribute(getName(), getDescription(),
- requiresAdminAction(), activeValue);
- }
- }
-
-
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- public javax.management.Attribute toJMXAttribute()
- {
- return new javax.management.Attribute(getName(), activeValue);
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute.
- */
- public javax.management.Attribute toJMXAttributePending()
- {
- return new javax.management.Attribute(getName() + ";"
- + OPTION_PENDING_VALUES, pendingValue);
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- public void toJMXAttribute(AttributeList attributeList)
- {
- attributeList.add(new javax.management.Attribute(getName(), activeValue));
-
- if (requiresAdminAction() && pendingValue != activeValue)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeList.add(new javax.management.Attribute(name, pendingValue));
- }
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- Boolean.class.getName(),
- String.valueOf(
- getDescription()),
- true, true, false));
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeInfoList.add(new MBeanAttributeInfo(name,
- Boolean.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- public MBeanParameterInfo toJMXParameterInfo()
- {
- return new MBeanParameterInfo(getName(), Boolean.TYPE.getName(),
- String.valueOf(getDescription()));
- }
-
-
-
- /**
- * Attempts to set the value of this configuration attribute based on the
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value instanceof Boolean)
- {
- setValue(((Boolean) value).booleanValue());
- }
- else if (value instanceof String)
- {
- String stringValue = ((String) value).toLowerCase();
- if (stringValue.equals("true") || stringValue.equals("yes") ||
- stringValue.equals("on") || stringValue.equals("1"))
- {
- setValue(true);
- }
- else if (stringValue.equals("false") || stringValue.equals("no") ||
- stringValue.equals("off") || stringValue.equals("0"))
- {
- setValue(false);
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(getName(), stringValue);
- throw new ConfigException(message);
- }
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
- getName(), value.getClass().getName() + ":" + value));
- }
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- public ConfigAttribute duplicate()
- {
- return new BooleanConfigAttribute(getName(), getDescription(),
- requiresAdminAction(), activeValue,
- 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
deleted file mode 100644
index f1388f7..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigAttribute.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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;
-
-/**
- * This class defines a configuration attribute, which can hold zero or more
- * values associated with a configurable property within the Directory Server.
- * Subclasses should define and enforce actual data types.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=true,
- mayInvoke=true)
-public abstract class ConfigAttribute
-{
- /**
- * Indicates whether this configuration attribute has pending changes that
- * will be applied after appropriate administrative action has been performed.
- */
- private boolean hasPendingValues;
-
- /** Indicates whether this configuration attribute may have multiple values. */
- private boolean isMultiValued;
-
- /** Indicates whether this configuration attribute is required to have a value. */
- private boolean isRequired;
-
- /**
- * Indicates whether changes to this attribute require administrative action
- * before they will take effect.
- */
- private boolean requiresAdminAction;
-
- /**
- * The value or set of values that are currently in effect for this
- * configuration attribute.
- */
- private LinkedHashSet<ByteString> activeValues;
-
- /**
- * The value or set of values that will be in effect once the appropriate
- * administrative action has been taken.
- */
- private LinkedHashSet<ByteString> pendingValues;
-
- /** The description for this configuration attribute. */
- private LocalizableMessage description;
-
- /** The name for this configuration attribute. */
- private String name;
-
-
-
- /**
- * Creates a new configuration attribute stub with the provided information
- * but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- */
- protected ConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction)
- {
- this.name = name;
- this.description = description;
- this.isRequired = isRequired;
- this.isMultiValued = isMultiValued;
- this.requiresAdminAction = requiresAdminAction;
-
- hasPendingValues = false;
- activeValues = new LinkedHashSet<>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new configuration attribute with the provided information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param activeValues The set of values for this attribute that are
- * currently active.
- */
- protected ConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- LinkedHashSet<ByteString> activeValues)
- {
- this.name = name;
- this.description = description;
- this.isRequired = isRequired;
- this.isMultiValued = isMultiValued;
- this.requiresAdminAction = requiresAdminAction;
- this.hasPendingValues = false;
-
- this.activeValues = notNull(activeValues);
- this.pendingValues = this.activeValues;
- }
-
-
-
- /**
- * Creates a new configuration attribute with the provided information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param activeValues The set of values for this attribute that are
- * currently active.
- * @param hasPendingValues Indicates whether this attribute has any
- * pending values that will take effect after
- * appropriate administrative action.
- * @param pendingValues The set of values for this attribute that will
- * be in effect after the appropriate
- * administrative action is taken. This may be
- * <CODE>null</CODE> if changes will take effect
- * immediately.
- */
- protected ConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- LinkedHashSet<ByteString> activeValues,
- boolean hasPendingValues,
- LinkedHashSet<ByteString> pendingValues)
- {
- this.name = name;
- this.description = description;
- this.isRequired = isRequired;
- this.isMultiValued = isMultiValued;
- this.requiresAdminAction = requiresAdminAction;
- this.hasPendingValues = hasPendingValues;
-
- this.activeValues = notNull(activeValues);
-
- if (!hasPendingValues)
- {
- this.pendingValues = this.activeValues;
- }
- else
- {
- this.pendingValues = notNull(pendingValues);
- }
- }
-
-
-
- /**
- * Retrieves the name for this configuration attribute.
- *
- * @return The name for this configuration attribute.
- */
- public String getName()
- {
- return name;
- }
-
-
-
- /**
- * Retrieves the description for this configuration attribute.
- *
- * @return The description for this configuration attribute, or
- * <CODE>null</CODE> if there is no description.
- */
- public LocalizableMessage getDescription()
- {
- return description;
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- public abstract String getDataType();
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- public abstract Syntax getSyntax();
-
-
-
- /**
- * Indicates whether this configuration attribute is required to have at least
- * one value.
- *
- * @return <CODE>true</CODE> if this configuration attribute is required to
- * have at least one value, or <CODE>false</CODE> if not.
- */
- public boolean isRequired()
- {
- return isRequired;
- }
-
-
-
- /**
- * Indicates whether this configuration attribute may have multiple values.
- *
- * @return <CODE>true</CODE> if this configuration attribute may have
- * multiple values, or <CODE>false</CODE> if not.
- */
- public boolean isMultiValued()
- {
- return isMultiValued;
- }
-
-
-
- /**
- * Indicates whether changes to this configuration attribute require
- * administrative action before they will take effect.
- *
- * @return <CODE>true</CODE> if changes to this configuration attribute
- * require administrative action before they will take effect, or
- * <CODE>false</CODE> if changes will take effect immediately.
- */
- public boolean requiresAdminAction()
- {
- return requiresAdminAction;
- }
-
-
-
- /**
- * Retrieves the set of active values for this configuration attribute. This
- * must not be modified by the caller.
- *
- * @return The set of active values for this configuration attribute.
- */
- public LinkedHashSet<ByteString> getActiveValues()
- {
- return activeValues;
- }
-
-
-
- /**
- * Indicates whether this attribute has been altered and that there are a set
- * of pending values that will take effect after appropriate administrative
- * action.
- *
- * @return <CODE>true</CODE> if this attribute has pending values, or
- * <CODE>false</CODE> if not.
- */
- public boolean hasPendingValues()
- {
- return hasPendingValues;
- }
-
-
-
- /**
- * Retrieves the set of values that this configuration attribute will have on
- * restart or after any necessary administrative action is performed. For
- * attributes whose changes take effect immediately, this will always be the
- * same as the set of active values. This must not be modified by the caller.
- *
- * @return The set of values that this configuration attribute will have
- * after any appropriate administrative action is taken.
- */
- public LinkedHashSet<ByteString> getPendingValues()
- {
- if (requiresAdminAction)
- {
- return pendingValues;
- }
- return activeValues;
- }
-
-
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * attribute. If it is not acceptable, then the reason should be written into
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- public abstract boolean valueIsAcceptable(ByteString value,
- StringBuilder rejectReason);
-
-
-
- /**
- * Specifies the set of values for this configuration attribute. Each value
- * will be validated using the <CODE>valueIsAcceptable</CODE> method, and
- * only a single value will be allowed unless <CODE>isMultiValued</CODE>
- * returns <CODE>true</CODE>. If the set of values is acceptable, then it
- * will be set either as the active set of values if changes are to take
- * effect immediately, or if not then it will be applied to the set of
- * pending values.
- *
- * @param values The set of values to apply to this attribute.
- *
- * @throws ConfigException If the provided set of values is not acceptable
- * for some reason.
- */
- protected void setValues(LinkedHashSet<ByteString> values)
- throws ConfigException
- {
- // If no values are provided, then check to see if this is a required
- // attribute. If it is, then reject the change.
- if (values == null || values.isEmpty())
- {
- if (isRequired)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(name));
- }
-
- if (requiresAdminAction)
- {
- pendingValues = notNull(values);
- hasPendingValues = true;
- }
- else
- {
- activeValues = notNull(values);
-
- pendingValues = activeValues;
- hasPendingValues = false;
- }
-
- return;
- }
-
-
- // We know that we have at least one value, so get it and see if it is OK.
- Iterator<ByteString> iterator = values.iterator();
- ByteString value = iterator.next();
- StringBuilder rejectReason = new StringBuilder();
-
- if (! valueIsAcceptable(value, rejectReason))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_REJECTED_VALUE.get(
- value, name, rejectReason));
- }
-
-
- // If this is not a multivalued attribute but there were more values
- // provided, then reject it.
- if (! isMultiValued && iterator.hasNext())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(name);
- throw new ConfigException(message);
- }
-
-
- // Iterate through the remaining values to see if they are acceptable.
- while (iterator.hasNext())
- {
- value = iterator.next();
- if (! valueIsAcceptable(value, rejectReason))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_REJECTED_VALUE.get(
- value, name, rejectReason));
- }
- }
-
-
- // If we've gotten here, then everything is OK. Make this the new active or
- // pending value set depending on the configuration.
- if (requiresAdminAction)
- {
- pendingValues = values;
- hasPendingValues = true;
- }
- else
- {
- activeValues = values;
- pendingValues = activeValues;
- hasPendingValues = false;
-
- }
- }
-
- private LinkedHashSet<ByteString> notNull(LinkedHashSet<ByteString> values)
- {
- return values != null ? values : new LinkedHashSet<ByteString>();
- }
-
- /**
- * Specifies the set of active values for this configuration attribute. No
- * validation will be performed, and no checks will be made to determine if
- * administrative action is required.
- *
- * @param values The set of active values for this configuration attribute.
- */
- protected void setActiveValues(LinkedHashSet<ByteString> values)
- {
- activeValues = values;
- }
-
-
-
- /**
- * Specifies the set of pending values for this configuration attribute. No
- * validation will be performed, and no checks will be made to determine if
- * administrative action is required.
- *
- * @param values The set of pending values for this configuration attribute.
- */
- protected void setPendingValues(LinkedHashSet<ByteString> values)
- {
- pendingValues = values;
- hasPendingValues = true;
- }
-
-
-
- /**
- * Attempts to add the provided set of values to this configuration attribute.
- * All of the appropriate validity checks will be performed, and the changes
- * will be applied to either the active or pending values, depending on the
- * configuration of this attribute.
- *
- * @param values The set of values to add to this configuration attribute.
- *
- * @throws ConfigException If a problem occurs while attempting to add the
- * provided set of values to this configuration
- * attribute.
- */
- protected void addValues(List<ByteString> values) throws ConfigException
- {
- // If there are no values provided, then do nothing.
- if (values == null)
- {
- return;
- }
-
- int numValues = values.size();
- if (numValues == 0)
- {
- return;
- }
-
-
- // Make sure that the value limit will not be exceeded for a single-valued
- // attribute.
- if (!isMultiValued)
- {
- if (numValues > 1
- || (hasPendingValues && !pendingValues.isEmpty())
- || (!hasPendingValues && !activeValues.isEmpty()))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_IS_SINGLE_VALUED.get(name));
- }
- }
-
-
- // Create a temporary set of values that we will use for this change. It
- // may not actually be applied if an error occurs for some reason.
- final LinkedHashSet<ByteString> vals = getValues();
- LinkedHashSet<ByteString> tempValues = new LinkedHashSet<>(vals.size() + numValues);
-
- // Iterate through all of the provided values. Make sure that each is
- // acceptable for use and that it is not already contained in the value set.
- StringBuilder rejectReason = new StringBuilder();
- for (ByteString value : values)
- {
- if (tempValues.contains(value))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(
- name, value));
- }
-
- if (! valueIsAcceptable(value, rejectReason))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_REJECTED_VALUE.get(
- value, name, rejectReason));
- }
- }
-
-
- // If we have gotten here, then everything is OK, so go ahead and assign
- // the temporary value set to either the active or pending lists.
- if (requiresAdminAction)
- {
- pendingValues = tempValues;
- hasPendingValues = true;
- }
- else
- {
- activeValues = tempValues;
- pendingValues = tempValues;
- hasPendingValues = false;
- }
- }
-
- private LinkedHashSet<ByteString> getValues()
- {
- return requiresAdminAction && hasPendingValues
- ? pendingValues
- : activeValues;
- }
-
- /**
- * Attempts to remove the set of values from this configuration attribute.
- *
- * @param values The set of values to remove from this configuration
- * attribute.
- *
- * @throws ConfigException If any of the provided values are not in the
- * value set, or if this is a required attribute and
- * the resulting value list would be empty.
- */
- protected void removeValues(List<ByteString> values) throws ConfigException
- {
- // Create a temporary set of values that we will use for this change. It
- // may not actually be applied if an error occurs for some reason.
- LinkedHashSet<ByteString> tempValues = new LinkedHashSet<>(getValues());
-
- // Iterate through all the provided values and make sure that they are
- // contained in the list. If not, then throw an exception. If so, then
- // remove it.
- for (ByteString value : values)
- {
- if (! tempValues.remove(value))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_SUCH_VALUE.get(name, value));
- }
- }
-
-
- // If this is a required attribute, then make sure that it will have at
- // least one value.
- if (isRequired && tempValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(name);
- throw new ConfigException(message);
- }
-
-
- // If we have gotten here, then everything is OK, so go ahead and assign
- // the temporary value set to either the active or pending lists.
- if (requiresAdminAction)
- {
- pendingValues = tempValues;
- hasPendingValues = true;
- }
- else
- {
- activeValues = tempValues;
- pendingValues = tempValues;
- hasPendingValues = false;
- }
- }
-
-
-
- /**
- * Removes all values from this configuration attribute.
- *
- * @throws ConfigException If this is a required attribute that must have at
- * least one value.
- */
- protected void removeAllValues()
- throws ConfigException
- {
- if (isRequired)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_IS_REQUIRED.get(name);
- throw new ConfigException(message);
- }
-
-
- if (requiresAdminAction)
- {
- if (pendingValues == null)
- {
- pendingValues = new LinkedHashSet<>();
- }
- else
- {
- pendingValues.clear();
- }
-
- hasPendingValues = true;
- }
- else
- {
- activeValues.clear();
- pendingValues = activeValues;
- hasPendingValues = false;
- }
- }
-
-
-
- /**
- * Assigns the initial values to this configuration attribute. This will wipe
- * out any previous active or pending values that may have been assigned, and
- * it will not perform any validation on those values. This method must only
- * be used to set the initial values for this attribute from the configuration
- * repository and must not be called any other time.
- *
- * @param values The initial set of values to assign to this configuration
- * attribute.
- */
- public void setInitialValues(LinkedHashSet<ByteString> values)
- {
- if (values == null)
- {
- values = new LinkedHashSet<>();
- }
-
- activeValues = values;
- pendingValues = values;
- hasPendingValues = false;
- }
-
-
-
- /**
- * 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.
- */
- public void applyPendingValues()
- {
- if (hasPendingValues)
- {
- activeValues = pendingValues;
- hasPendingValues = false;
- }
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- public abstract LinkedHashSet<ByteString> stringsToValues(
- List<String> valueStrings, boolean allowFailures) throws ConfigException;
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * 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.
- */
- public abstract List<String> activeValuesToStrings();
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- public abstract List<String> pendingValuesToStrings();
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- public abstract ConfigAttribute getConfigAttribute(List<Attribute>
- attributeList)
- throws ConfigException;
-
-
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute.
- */
- public abstract javax.management.Attribute toJMXAttribute();
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute.
- */
- public abstract javax.management.Attribute toJMXAttributePending();
-
-
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- public abstract void toJMXAttribute(AttributeList attributeList);
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- public abstract void toJMXAttributeInfo(List<MBeanAttributeInfo>
- attributeInfoList);
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- public abstract MBeanParameterInfo toJMXParameterInfo();
-
-
-
- /**
- * Attempts to set the value of this configuration attribute based on the
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- public abstract void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException;
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @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.valueOfUtf8(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.valueOfUtf8(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
deleted file mode 100644
index 5208045..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/DNConfigAttribute.java
+++ /dev/null
@@ -1,1149 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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;
-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.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.AttributeDescription;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DN;
-import org.forgerock.opendj.ldap.schema.Syntax;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.Attribute;
-
-/**
- * This class defines a DN configuration attribute, which can hold zero or more
- * DN values.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class DNConfigAttribute
- extends ConfigAttribute
-{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
- /** The set of active values for this attribute. */
- private List<DN> activeValues;
-
- /** The set of pending values for this attribute. */
- private List<DN> pendingValues;
-
-
-
- /**
- * Creates a new DN configuration attribute stub with the provided information
- * but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- */
- public DNConfigAttribute(String name, LocalizableMessage description, boolean isRequired,
- boolean isMultiValued, boolean requiresAdminAction)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction);
-
-
- activeValues = new ArrayList<>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new DN configuration attribute with the provided information. No
- * validation will be performed on the provided value.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param value The value for this DN configuration attribute.
- */
- public DNConfigAttribute(String name, LocalizableMessage description, boolean isRequired,
- boolean isMultiValued, boolean requiresAdminAction,
- DN value)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getDNValueSet(value));
-
-
- if (value == null)
- {
- activeValues = new ArrayList<>();
- }
- else
- {
- activeValues = newArrayList(value);
- }
-
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new DN configuration attribute with the provided information. No
- * validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param values The set of values for this configuration
- * attribute.
- */
- public DNConfigAttribute(String name, LocalizableMessage description, boolean isRequired,
- boolean isMultiValued, boolean requiresAdminAction,
- List<DN> values)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getDNValueSet(values));
-
- activeValues = values != null ? values : new ArrayList<DN>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new DN configuration attribute with the provided information. No
- * validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param activeValues The set of active values for this
- * configuration attribute.
- * @param pendingValues The set of pending values for this
- * configuration attribute.
- */
- public DNConfigAttribute(String name, LocalizableMessage description, boolean isRequired,
- boolean isMultiValued, boolean requiresAdminAction,
- List<DN> activeValues, List<DN> pendingValues)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getDNValueSet(activeValues), pendingValues != null,
- getDNValueSet(pendingValues));
-
-
- if (activeValues == null)
- {
- this.activeValues = new ArrayList<>();
- }
- else
- {
- this.activeValues = activeValues;
- }
-
- if (pendingValues == null)
- {
- this.pendingValues = this.activeValues;
- }
- else
- {
- this.pendingValues = pendingValues;
- }
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- @Override
- public String getDataType()
- {
- return "DN";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- @Override
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultStringSyntax();
- }
-
-
-
- /**
- * Retrieves the active value for this configuration attribute as a DN. This
- * is only valid for single-valued attributes that have a value.
- *
- * @return The active value for this configuration attribute as a DN.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * active value.
- */
- public DN activeValue()
- throws ConfigException
- {
- if (activeValues == null || activeValues.isEmpty())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()));
- }
- if (activeValues.size() > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()));
- }
-
- return activeValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of active values for this configuration attribute.
- *
- * @return The set of active values for this configuration attribute.
- */
- public List<DN> activeValues()
- {
- return activeValues;
- }
-
-
-
- /**
- * Retrieves the pending value for this configuration attribute as a DN.
- * This is only valid for single-valued attributes that have a value. If this
- * attribute does not have any pending values, then the active value will be
- * returned.
- *
- * @return The pending value for this configuration attribute as a DN.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * pending value.
- */
- public DN pendingValue()
- throws ConfigException
- {
- if (! hasPendingValues())
- {
- return activeValue();
- }
-
- if (pendingValues == null || pendingValues.isEmpty())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()));
- }
- if (pendingValues.size() > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()));
- }
-
- return pendingValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of pending values for this configuration attribute. If
- * there are no pending values, then the set of active values will be
- * returned.
- *
- * @return The set of pending values for this configuration attribute.
- */
- public List<DN> pendingValues()
- {
- if (! hasPendingValues())
- {
- return activeValues;
- }
-
- return pendingValues;
- }
-
-
-
- /**
- * Sets the value for this DN configuration attribute.
- *
- * @param value The value for this DN configuration attribute.
- *
- * @throws ConfigException If the provided value is not acceptable.
- */
- public void setValue(DN value)
- throws ConfigException
- {
- if (value == null)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_NULL.get(getName());
- throw new ConfigException(message);
- }
-
- if (requiresAdminAction())
- {
- pendingValues = newArrayList(value);
- setPendingValues(getDNValueSet(value));
- }
- else
- {
- activeValues.clear();
- activeValues.add(value);
- pendingValues = activeValues;
- setActiveValues(getDNValueSet(value));
- }
- }
-
-
-
- /**
- * Sets the values for this DN configuration attribute.
- *
- * @param values The set of values for this DN configuration attribute.
- *
- * @throws ConfigException If the provided value set or any of the
- * individual values are not acceptable.
- */
- public void setValues(List<DN> values)
- throws ConfigException
- {
- // First check if the set is empty and if that is allowed.
- if (values == null || values.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
-
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- 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)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
- }
-
-
- // Iterate through all the provided values, make sure that they are
- // acceptable, and build the value set.
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
- for (DN value : values)
- {
- if (value == null)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_DN_NULL.get(getName()));
- }
-
- ByteString attrValue = ByteString.valueOfUtf8(value.toString());
- if (valueSet.contains(attrValue))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
- }
-
- valueSet.add(attrValue);
- }
-
-
- // Apply this value set to the new active or pending value set.
- if (requiresAdminAction())
- {
- pendingValues = values;
- setPendingValues(valueSet);
- }
- else
- {
- activeValues = values;
- pendingValues = activeValues;
- setActiveValues(valueSet);
- }
- }
-
-
-
- /**
- * 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> getDNValueSet(DN value)
- {
- if (value == null)
- {
- return new LinkedHashSet<>(0);
- }
- return newLinkedHashSet(ByteString.valueOfUtf8(value.toString()));
- }
-
-
-
- /**
- * 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> getDNValueSet(List<DN> values)
- {
- if (values == null)
- {
- return null;
- }
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(values.size());
- for (DN value : values)
- {
- valueSet.add(ByteString.valueOfUtf8(value.toString()));
- }
- 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.
- */
- @Override
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- 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
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- @Override
- public boolean valueIsAcceptable(ByteString value, StringBuilder rejectReason)
- {
- // Make sure that the value is not null.
- if (value == null)
- {
- rejectReason.append(ERR_CONFIG_ATTR_DN_NULL.get(getName()));
- return false;
- }
-
-
- // Make sure that it can be parsed as a DN.
- try
- {
- DN.valueOf(value.toString());
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- rejectReason.append(ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(value, getName(), e));
- return false;
- }
- return true;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- @Override
- public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
- return new LinkedHashSet<>();
- }
-
-
- int numValues = valueStrings.size();
- if (!isMultiValued() && numValues > 1)
- {
- 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)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_DN_NULL.get(getName()));
- continue;
- }
-
-
- DN dn;
- try
- {
- dn = DN.valueOf(valueString);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- reportError(allowFailures, ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(valueString, getName(), e));
- continue;
- }
-
- valueSet.add(ByteString.valueOfUtf8(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())
- {
- 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
- * set of strings that may be stored in the configuration or represented over
- * protocol. The string representation used by this method should be
- * 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.
- */
- @Override
- public List<String> activeValuesToStrings()
- {
- ArrayList<String> valueStrings = new ArrayList<>(activeValues.size());
- for (DN dn : activeValues)
- {
- valueStrings.add(dn.toString());
- }
-
- return valueStrings;
- }
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- @Override
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- ArrayList<String> valueStrings = new ArrayList<>(pendingValues.size());
- for (DN dn : pendingValues)
- {
- valueStrings.add(dn.toString());
- }
- return valueStrings;
- }
- return null;
- }
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- @Override
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- ArrayList<DN> activeValues = null;
- ArrayList<DN> pendingValues = null;
-
- for (Attribute a : attributeList)
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- if (pendingValues != null)
- {
- // We cannot have multiple pending value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- pendingValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- DN dn;
- try
- {
- dn = DN.valueOf(v.toString());
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(v, getName(), e);
- throw new ConfigException(message, e);
- }
-
- pendingValues.add(dn);
- }
- }
- }
- else
- {
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- }
- else
- {
- // This must be the active value.
- if (activeValues!= null)
- {
- // We cannot have multiple active value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- activeValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- DN dn;
- try
- {
- dn = DN.valueOf(v.toString());
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(v, getName(), e);
- throw new ConfigException(message, e);
- }
-
- activeValues.add(dn);
- }
- }
- }
- }
-
- if (activeValues == 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);
- }
-
- if (pendingValues == null)
- {
- // This is OK. We'll just use the active value set.
- pendingValues = activeValues;
- }
-
- return new DNConfigAttribute(getName(), getDescription(), isRequired(),
- isMultiValued(), requiresAdminAction(),
- activeValues, pendingValues);
- }
-
-
-
- /**
- * Retrieves a JMX attribute containing the requested value set for this
- * configuration attribute (active or pending).
- *
- * @param pending indicates if pending or active values are required.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- private javax.management.Attribute _toJMXAttribute(boolean pending)
- {
- List<DN> requestedValues ;
- String name ;
- if (pending)
- {
- requestedValues = pendingValues ;
- name = getName() + ";" + OPTION_PENDING_VALUES ;
- }
- else
- {
- requestedValues = activeValues ;
- name = getName() ;
- }
-
- if (isMultiValued())
- {
- String[] values = new String[requestedValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = requestedValues.get(i).toString();
- }
-
- 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
- {
- return null;
- }
- }
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttribute()
- {
- return _toJMXAttribute(false) ;
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- return _toJMXAttribute(true) ;
- }
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- @Override
- public void toJMXAttribute(AttributeList attributeList)
- {
- if (!activeValues.isEmpty())
- {
- if (isMultiValued())
- {
- String[] values = new String[activeValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = activeValues.get(i).toString();
- }
-
- attributeList.add(new javax.management.Attribute(getName(), values));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(),
- activeValues.get(0).toString()));
- }
- }
- else
- {
- if (isMultiValued())
- {
- attributeList.add(new javax.management.Attribute(getName(),
- new String[0]));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(), null));
- }
- }
-
-
- if (requiresAdminAction() && pendingValues != null && pendingValues != activeValues)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- String[] values = new String[pendingValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = pendingValues.get(i).toString();
- }
-
- attributeList.add(new javax.management.Attribute(name, values));
- }
- else if (! pendingValues.isEmpty())
- {
- attributeList.add(new javax.management.Attribute(name,
- pendingValues.get(0).toString()));
- }
- }
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- @Override
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
- String.valueOf(getDescription()), true, true, false));
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
- String.valueOf(getDescription()), true, false, false));
- }
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- @Override
- public MBeanParameterInfo toJMXParameterInfo()
- {
- 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
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- @Override
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value == null)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_DN_NULL.get(getName()));
- }
- else if (value instanceof DN)
- {
- setValue((DN) value);
- }
- if (value instanceof String)
- {
- DN dn;
- try
- {
- dn = DN.valueOf((String) value);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(value, getName(), e);
- throw new ConfigException(message, e);
- }
-
- setValue(dn);
- }
- else if (value.getClass().isArray())
- {
- String componentType = value.getClass().getComponentType().getName();
- int length = Array.getLength(value);
-
- if (componentType.equals(DN.class.getName()))
- {
- ArrayList<DN> dnList = new ArrayList<>(length);
- for (int i=0; i < length; i++)
- {
- dnList.add((DN) Array.get(value, i));
- }
-
- setValues(dnList);
- }
- else if (componentType.equals(String.class.getName()))
- {
- try
- {
- ArrayList<DN> values = new ArrayList<>(length);
- for (int i=0; i < length; i++)
- {
- String valueStr = (String) Array.get(value, i);
-
- DN dn;
- try
- {
- dn = DN.valueOf(valueStr);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_DN_CANNOT_PARSE.get(valueStr, getName(), e);
- throw new ConfigException(message, e);
- }
-
- values.add(dn);
- }
-
- setValues(values);
- }
- catch (ConfigException ce)
- {
- logger.traceException(ce);
-
- throw ce;
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_INVALID_DN_VALUE.get(
- getName(), value, e);
- throw new ConfigException(message, e);
- }
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_DN_INVALID_ARRAY_TYPE.get(jmxAttribute, componentType);
- throw new ConfigException(message);
- }
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_DN_INVALID_TYPE.get(
- value, getName(), value.getClass().getName()));
- }
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- @Override
- public ConfigAttribute duplicate()
- {
- return new DNConfigAttribute(getName(), getDescription(), isRequired(),
- isMultiValued(), requiresAdminAction(),
- activeValues, pendingValues);
- }
-}
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
deleted file mode 100644
index 896e4fe..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerConfigAttribute.java
+++ /dev/null
@@ -1,1386 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-import java.lang.reflect.Array;
-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.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.AttributeDescription;
-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.opends.server.util.CollectionUtils;
-
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.messages.ConfigMessages.*;
-
-/**
- * This class defines an integer configuration attribute, which can hold zero or
- * more integer values. For scalability, the actual values will be stored as
- * <CODE>long</CODE> elements, although it will be possible to interact with
- * them as integers in cases where that scalability is not required.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class IntegerConfigAttribute
- extends ConfigAttribute
-{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
- /** 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
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for values of this attribute.
- * @param lowerBound The lower bound that will be enforced for
- * values of this attribute.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for values of this attribute.
- * @param upperBound The upper bound that will be enforced for
- * values of this attribute.
- */
- public IntegerConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction);
-
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
-
- activeValues = new ArrayList<>();
- pendingValues = activeValues;
- }
-
- /**
- * Creates a new integer configuration attribute with the provided
- * information. No validation will be performed on the provided value.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for values of this attribute.
- * @param lowerBound The lower bound that will be enforced for
- * values of this attribute.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for values of this attribute.
- * @param upperBound The upper bound that will be enforced for
- * values of this attribute.
- * @param value The value for this integer configuration
- * attribute.
- */
- public IntegerConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound,
- long value)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getLongValueSet(value));
-
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
-
- activeValues = CollectionUtils.newArrayList(value);
- pendingValues = activeValues;
- }
-
- /**
- * Creates a new integer configuration attribute with the provided
- * information. No validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for values of this attribute.
- * @param lowerBound The lower bound that will be enforced for
- * values of this attribute.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for values of this attribute.
- * @param upperBound The upper bound that will be enforced for
- * values of this attribute.
- * @param values The set of values for this configuration
- * attribute.
- */
- public IntegerConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound,
- List<Long> values)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getLongValueSet(values));
-
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
-
- activeValues = values != null ? values : new ArrayList<Long>();
- pendingValues = activeValues;
- }
-
- /**
- * Creates a new integer configuration attribute with the provided
- * information. No validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for values of this attribute.
- * @param lowerBound The lower bound that will be enforced for
- * values of this attribute.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for values of this attribute.
- * @param upperBound The upper bound that will be enforced for
- * values of this attribute.
- * @param activeValues The set of active values for this
- * configuration attribute.
- * @param pendingValues The set of pending values for this
- * configuration attribute.
- */
- public IntegerConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound,
- List<Long> activeValues,
- List<Long> pendingValues)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getLongValueSet(activeValues), (pendingValues != null),
- getLongValueSet(pendingValues));
-
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
-
- if (activeValues == null)
- {
- this.activeValues = new ArrayList<>();
- }
- else
- {
- this.activeValues = activeValues;
- }
-
- if (pendingValues == null)
- {
- this.pendingValues = this.activeValues;
- }
- else
- {
- this.pendingValues = pendingValues;
- }
- }
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- @Override
- public String getDataType()
- {
- return "Integer";
- }
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- @Override
- public Syntax getSyntax()
- {
- 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.
- *
- * @return The active value for this configuration attribute as a long.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * active value.
- */
- public long activeValue()
- throws ConfigException
- {
- if (activeValues == null || activeValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
- throw new ConfigException(message);
- }
-
- if (activeValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_INT_VALUES.get(getName());
- throw new ConfigException(message);
- }
-
- 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
- * the integer range.
- *
- * @return The active value for this configuration attribute as an integer.
- *
- * @throws ConfigException If the active value of this attribute cannot be
- * retrieved as an integer, including if there are
- * no values, if there are multiple values, or if
- * the value is not in the range of an integer.
- */
- public int activeIntValue()
- throws ConfigException
- {
- if (activeValues == null || activeValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
- throw new ConfigException(message);
- }
-
- if (activeValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_INT_VALUES.get(getName());
- throw new ConfigException(message);
- }
-
- long longValue = activeValues.get(0);
- int intValue = (int) longValue;
- if (intValue == longValue)
- {
- return intValue;
- }
- else
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_VALUE_OUT_OF_INT_RANGE.get(getName());
- throw new ConfigException(message);
- }
- }
-
- /**
- * Retrieves the set of active values for this configuration attribute.
- *
- * @return The set of active values for this configuration attribute.
- */
- public List<Long> activeValues()
- {
- 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
- * attribute does not have any pending values, then the active value will be
- * returned.
- *
- * @return The pending value for this configuration attribute as a long.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * pending value.
- */
- public long pendingValue()
- throws ConfigException
- {
- if (! hasPendingValues())
- {
- return activeValue();
- }
-
- if (pendingValues == null || pendingValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
- throw new ConfigException(message);
- }
-
- if (pendingValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_INT_VALUES.get(getName());
- throw new ConfigException(message);
- }
-
- 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
- * the integer range. If this attribute does not have any pending values,
- * then t he active value will be returned.
- *
- * @return The pending value for this configuration attribute as an integer.
- *
- * @throws ConfigException If the pending value of this attribute cannot be
- * retrieved as an integer, including if there are
- * no values, if there are multiple values, or if
- * the value is not in the range of an integer.
- */
- public int pendingIntValue()
- throws ConfigException
- {
- if (! hasPendingValues())
- {
- return activeIntValue();
- }
-
- if (pendingValues == null || pendingValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_INT_VALUE.get(getName());
- throw new ConfigException(message);
- }
-
- if (pendingValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_INT_VALUES.get(getName());
- throw new ConfigException(message);
- }
-
- long longValue = pendingValues.get(0);
- int intValue = (int) longValue;
- if (intValue == longValue)
- {
- return intValue;
- }
- else
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_VALUE_OUT_OF_INT_RANGE.get(getName());
- throw new ConfigException(message);
- }
- }
-
- /**
- * Retrieves the set of pending values for this configuration attribute. If
- * there are no pending values, then the set of active values will be
- * returned.
- *
- * @return The set of pending values for this configuration attribute.
- */
- public List<Long> pendingValues()
- {
- if (! hasPendingValues())
- {
- return activeValues;
- }
-
- return pendingValues;
- }
-
- /**
- * Indicates whether a lower bound will be enforced for the value of this
- * configuration attribute.
- *
- * @return <CODE>true</CODE> if a lower bound will be enforced for the
- * value of this configuration attribute, or <CODE>false</CODE> if
- * not.
- */
- public boolean hasLowerBound()
- {
- return hasLowerBound;
- }
-
- /**
- * Retrieves the lower bound for the value of this configuration attribute.
- *
- * @return The lower bound for the value of this configuration attribute.
- */
- public long getLowerBound()
- {
- return lowerBound;
- }
-
- /**
- * Indicates whether an upper bound will be enforced for the calculated value
- * of this configuration attribute.
- *
- * @return <CODE>true</CODE> if an upper bound will be enforced for the
- * calculated value of this configuration attribute, or
- * <CODE>false</CODE> if not.
- */
- public boolean hasUpperBound()
- {
- return hasUpperBound;
- }
-
- /**
- * Retrieves the upper bound for the calculated value of this configuration
- * attribute.
- *
- * @return The upper bound for the calculated value of this configuration
- * attribute.
- */
- public long getUpperBound()
- {
- return upperBound;
- }
-
- /**
- * Sets the value for this integer configuration attribute.
- *
- * @param value The value for this integer configuration attribute.
- *
- * @throws ConfigException If the provided value is not acceptable.
- */
- public void setValue(long value)
- throws ConfigException
- {
- 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)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- getName(), value, upperBound);
- throw new ConfigException(message);
- }
-
- if (requiresAdminAction())
- {
- pendingValues = CollectionUtils.newArrayList(value);
- setPendingValues(getLongValueSet(value));
- }
- else
- {
- activeValues.clear();
- activeValues.add(value);
- pendingValues = activeValues;
- setActiveValues(getLongValueSet(value));
- }
- }
-
- /**
- * Sets the values for this integer configuration attribute.
- *
- * @param values The set of values for this integer configuration attribute.
- *
- * @throws ConfigException If the provided value set or any of the
- * individual values are not acceptable.
- */
- public void setValues(List<Long> values)
- throws ConfigException
- {
- // First check if the set is empty and if that is allowed.
- if (values == null || values.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
-
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- 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)
- {
- 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)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- getName(), value, lowerBound);
- throw new ConfigException(message);
- }
-
- if (hasUpperBound && value > upperBound)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- getName(), value, upperBound);
- throw new ConfigException(message);
- }
-
- String valueString = String.valueOf(value);
- ByteString attrValue = ByteString.valueOfUtf8(valueString);
- if (valueSet.contains(attrValue))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(
- getName(), valueString);
- throw new ConfigException(message);
- }
-
- valueSet.add(attrValue);
- }
-
- // Apply this value set to the new active or pending value set.
- if (requiresAdminAction())
- {
- pendingValues = values;
- setPendingValues(valueSet);
- }
- else
- {
- activeValues = values;
- pendingValues = activeValues;
- setActiveValues(valueSet);
- }
- }
-
- /**
- * 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> getLongValueSet(long value)
- {
- return getValueSet(String.valueOf(value));
- }
-
- /**
- * 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> getLongValueSet(List<Long> values)
- {
- if (values == null)
- {
- return null;
- }
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(values.size());
- for (long value : values)
- {
- valueSet.add(ByteString.valueOfUtf8(String.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.
- */
- @Override
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- 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
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- @Override
- public boolean valueIsAcceptable(ByteString value, StringBuilder rejectReason)
- {
- // First, make sure we can represent it as a long.
- String stringValue = value.toString();
- long longValue;
- try
- {
- longValue = Long.parseLong(stringValue);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- rejectReason.append(ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
- getName(), stringValue, e));
- return false;
- }
-
- // Perform any necessary bounds checking.
- if (hasLowerBound && longValue < lowerBound)
- {
- rejectReason.append(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- getName(), longValue, lowerBound));
- return false;
- }
-
- 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.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- @Override
- public LinkedHashSet<ByteString>
- stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
- return new LinkedHashSet<>();
- }
-
- int numValues = valueStrings.size();
- if (!isMultiValued() && numValues > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
- }
-
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
- for (String valueString : valueStrings)
- {
- long longValue;
- try
- {
- longValue = Long.parseLong(valueString);
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- reportError(allowFailures, ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(valueString, getName(), e));
- continue;
- }
-
- if (hasLowerBound && longValue < lowerBound)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(getName(), longValue, lowerBound));
- continue;
- }
- if (hasUpperBound && longValue > upperBound)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(getName(), longValue, upperBound));
- continue;
- }
-
- valueSet.add(ByteString.valueOfUtf8(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())
- {
- 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
- * set of strings that may be stored in the configuration or represented over
- * protocol. The string representation used by this method should be
- * 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.
- */
- @Override
- public List<String> activeValuesToStrings()
- {
- 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- @Override
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- return toListOfString(pendingValues);
- }
- return null;
- }
-
- private List<String> toListOfString(List<Long> values)
- {
- ArrayList<String> results = new ArrayList<>(values.size());
- for (long l : values)
- {
- results.add(String.valueOf(l));
- }
- return results;
- }
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- @Override
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- ArrayList<Long> activeValues = null;
- ArrayList<Long> pendingValues = null;
-
- for (Attribute a : attributeList)
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- if (pendingValues != null)
- {
- // We cannot have multiple pending value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- else
- {
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- pendingValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- long longValue;
- try
- {
- longValue = Long.parseLong(v.toString());
- }
- catch (Exception e)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(v, attrDesc, e);
- throw new ConfigException(message, e);
- }
-
- // Check the bounds set for this attribute.
- if (hasLowerBound && longValue < lowerBound)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(attrDesc, longValue, lowerBound));
- }
-
- if (hasUpperBound && longValue > upperBound)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(attrDesc, longValue, upperBound));
- }
-
- pendingValues.add(longValue);
- }
- }
- }
- else
- {
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- }
- else
- {
- // This must be the active value.
- if (activeValues!= null)
- {
- // We cannot have multiple active value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- else
- {
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- activeValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- long longValue;
- try
- {
- longValue = Long.parseLong(v.toString());
- }
- catch (Exception e)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(v, attrDesc, e), e);
- }
-
- // Check the bounds set for this attribute.
- if (hasLowerBound && longValue < lowerBound)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(attrDesc, longValue, lowerBound));
- }
-
- if (hasUpperBound && longValue > upperBound)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(attrDesc, longValue, upperBound));
- }
-
- activeValues.add(longValue);
- }
- }
- }
- }
-
- if (activeValues == 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);
- }
-
- if (pendingValues == null)
- {
- // This is OK. We'll just use the active value set.
- 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).
- *
- * @param pending indicates if pending or active values are required.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- private javax.management.Attribute _toJMXAttribute(boolean pending)
- {
- List<Long> requestedValues ;
- String name ;
- if (pending)
- {
- requestedValues = pendingValues ;
- name = getName() + ";" + OPTION_PENDING_VALUES ;
- }
- else
- {
- requestedValues = activeValues ;
- name = getName() ;
- }
-
- if (isMultiValued())
- {
- long[] values = new long[requestedValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = requestedValues.get(i);
- }
-
- return new javax.management.Attribute(name, values);
- }
- else if (requestedValues.isEmpty())
- {
- return null;
- }
- else
- {
- return new javax.management.Attribute(name, requestedValues.get(0));
- }
- }
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttribute()
- {
- return _toJMXAttribute(false);
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- return _toJMXAttribute(true);
- }
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- @Override
- public void toJMXAttribute(AttributeList attributeList)
- {
- if (!activeValues.isEmpty())
- {
- if (isMultiValued())
- {
- long[] values = new long[activeValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = activeValues.get(i);
- }
-
- attributeList.add(new javax.management.Attribute(getName(), values));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(),
- activeValues.get(0)));
- }
- }
- else
- {
- if (isMultiValued())
- {
- attributeList.add(new javax.management.Attribute(getName(),
- new String[0]));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(), null));
- }
- }
-
- if (requiresAdminAction()
- && pendingValues != null
- && pendingValues != activeValues)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- long[] values = new long[pendingValues.size()];
- for (int i=0; i < values.length; i++)
- {
- values[i] = pendingValues.get(i);
- }
-
- attributeList.add(new javax.management.Attribute(name, values));
- }
- else if (! pendingValues.isEmpty())
- {
- attributeList.add(new javax.management.Attribute(name,
- pendingValues.get(0)));
- }
- }
- }
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- @Override
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- JMX_TYPE_LONG_ARRAY,
- String.valueOf(
- getDescription()),
- true, true, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- Long.class.getName(),
- String.valueOf(
- getDescription()),
- true, true, false));
- }
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- attributeInfoList.add(new MBeanAttributeInfo(name, JMX_TYPE_LONG_ARRAY,
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- else
- {
- attributeInfoList.add(new MBeanAttributeInfo(name, Long.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- }
- }
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- @Override
- public MBeanParameterInfo toJMXParameterInfo()
- {
- if (isMultiValued())
- {
- return new MBeanParameterInfo(getName(), JMX_TYPE_LONG_ARRAY,
- String.valueOf(getDescription()));
- }
- else
- {
- return new MBeanParameterInfo(getName(), Long.TYPE.getName(),
- String.valueOf(getDescription()));
- }
- }
-
- /**
- * Attempts to set the value of this configuration attribute based on the
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- @Override
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value instanceof Long)
- {
- setValue(((Long) value).longValue());
- }
- else if (value instanceof Integer)
- {
- setValue(((Integer) value).intValue());
- }
- else if (value instanceof String)
- {
- try
- {
- setValue(Long.parseLong((String) value));
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(value, getName(), e);
- throw new ConfigException(message, e);
- }
- }
- else if (value.getClass().isArray())
- {
- String componentType = value.getClass().getComponentType().getName();
- int length = Array.getLength(value);
-
- try
- {
- if (componentType.equals(Long.class.getName()))
- {
- ArrayList<Long> values = new ArrayList<>();
-
- for (int i=0; i < length; i++)
- {
- values.add(Array.getLong(value, i));
- }
-
- setValues(values);
- }
- else if (componentType.equals(Integer.class.getName()))
- {
- ArrayList<Long> values = new ArrayList<>();
-
- for (int i=0; i < length; i++)
- {
- values.add((long) Array.getInt(value, i));
- }
-
- setValues(values);
- }
- else if (componentType.equals(String.class.getName()))
- {
- ArrayList<Long> values = new ArrayList<>();
-
- for (int i=0; i < length; i++)
- {
- String s = (String) Array.get(value, i);
- values.add(Long.parseLong(s));
- }
-
- setValues(values);
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_INT_INVALID_ARRAY_TYPE.get(
- jmxAttribute.getName(), componentType);
- throw new ConfigException(message);
- }
- }
- catch (ConfigException ce)
- {
- logger.traceException(ce);
-
- throw ce;
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(
- componentType + "[" + length + "]", getName(), e);
- throw new ConfigException(message, e);
- }
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_INVALID_TYPE.get(
- value, getName(), value.getClass().getName()));
- }
- }
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- @Override
- public ConfigAttribute duplicate()
- {
- return new IntegerConfigAttribute(getName(), getDescription(), isRequired(),
- isMultiValued(), requiresAdminAction(),
- hasLowerBound, lowerBound, hasUpperBound,
- 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
deleted file mode 100644
index 2b09373..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/IntegerWithUnitConfigAttribute.java
+++ /dev/null
@@ -1,1142 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-import static org.opends.messages.ConfigMessages.*;
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.util.CollectionUtils.*;
-
-import java.util.HashMap;
-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.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.AttributeDescription;
-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;
-
-/**
- * This class defines a configuration attribute that stores both an integer
- * value and an associated unit. The unit will contain both a string and a
- * floating-point value. When a unit is selected, then the associated value
- * will be used as a multiplier for the integer value to achieve the actual
- * value for this parameter. For example, the attribute could be used to
- * specify a size in bytes, but a value with a unit of "kb" could multiply that
- * value by 1024, or "mb" by 1048576, or "gb" by 1073741824. In this case, a
- * value of "50 gb" would be the logical equivalent of "53687091200 b". Upper
- * and lower bounds may be imposed, and in that case they will be imposed on
- * the actual value not on merely the integer portion. This attribute may only
- * hold a single value and it will always be required.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class IntegerWithUnitConfigAttribute
- extends ConfigAttribute
-{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
-
-
-
- /**
- * Indicates whether this configuration attribute should impose a lower bound
- * for the calculated value.
- */
- private boolean hasLowerBound;
-
- /**
- * Indicates whether this configuration attribute should impose an upper bound
- * for the calculated value.
- */
- private boolean hasUpperBound;
-
- /** The set of unit names and associated multipliers. */
- private HashMap<String,Double> units;
-
- /** The active calculated value for this attribute. */
- private long activeCalculatedValue;
-
- /** The active value for this attribute. */
- private long activeIntValue;
-
- /** The lower bound for the calculated value. */
- private long lowerBound;
-
- /** The pending calculated value for this attribute. */
- private long pendingCalculatedValue;
-
- /** The the pending value for this attribute. */
- private long pendingIntValue;
-
- /** The upper bound for the calculated value. */
- private long upperBound;
-
- /** The active unit for this attribute. */
- private String activeUnit;
-
- /** The pending unit for this attribute. */
- private String pendingUnit;
-
-
-
- /**
- * Creates a new integer with unit configuration attribute stub with the
- * provided information but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method. Mo validation will be performed on
- * the set of allowed units.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param units The set of units and their associated
- * multipliers for this configuration attribute.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for the calculated value.
- * @param lowerBound The lower bound for the calculated value.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for the calculated value.
- * @param upperBound The upper bound for the calculated value.
- */
- public IntegerWithUnitConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction,
- HashMap<String,Double> units,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound)
- {
- super(name, description, true, false, requiresAdminAction);
-
-
- this.units = units;
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
- }
-
-
-
- /**
- * Creates a new integer with unit configuration attribute with the provided
- * information. No validation will be performed on the provided value or
- * unit, or on the set of allowed units.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param units The set of units and their associated
- * multipliers for this configuration attribute.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for the calculated value.
- * @param lowerBound The lower bound for the calculated value.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for the calculated value.
- * @param upperBound The upper bound for the calculated value.
- * @param intValue The selected value for this configuration
- * attribute.
- * @param selectedUnit The selected unit for this configuration
- * attribute.
- */
- public IntegerWithUnitConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction,
- HashMap<String,Double> units,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound,
- long intValue, String selectedUnit)
- {
- super(name, description, true, false, requiresAdminAction,
- getValueSet(intValue, selectedUnit));
-
-
-
- this.units = units;
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
- this.activeIntValue = intValue;
- this.activeUnit = selectedUnit;
-
- pendingIntValue = activeIntValue;
- pendingUnit = activeUnit;
-
- if (units.containsKey(selectedUnit))
- {
- activeCalculatedValue = (long) (activeIntValue * units.get(selectedUnit));
- }
-
- pendingCalculatedValue = activeCalculatedValue;
- }
-
-
-
- /**
- * Creates a new integer with unit configuration attribute with the provided
- * information. No validation will be performed on the provided value or
- * unit, or on the set of allowed units.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param units The set of units and their associated
- * multipliers for this configuration attribute.
- * @param hasLowerBound Indicates whether a lower bound will be
- * enforced for the calculated value.
- * @param lowerBound The lower bound for the calculated value.
- * @param hasUpperBound Indicates whether an upper bound will be
- * enforced for the calculated value.
- * @param upperBound The upper bound for the calculated value.
- * @param activeIntValue The active selected value for this
- * configuration attribute.
- * @param activeSelectedUnit The active selected unit for this
- * configuration attribute.
- * @param pendingIntValue The pending selected value for this
- * configuration attribute.
- * @param pendingSelectedUnit The pending selected unit for this
- * configuration attribute.
- */
- public IntegerWithUnitConfigAttribute(String name, LocalizableMessage description,
- boolean requiresAdminAction,
- HashMap<String,Double> units,
- boolean hasLowerBound, long lowerBound,
- boolean hasUpperBound, long upperBound,
- long activeIntValue,
- String activeSelectedUnit,
- long pendingIntValue,
- String pendingSelectedUnit)
- {
- super(name, description, true, false, requiresAdminAction,
- getValueSet(activeIntValue, activeSelectedUnit),
- (pendingSelectedUnit != null),
- getValueSet(pendingIntValue,pendingSelectedUnit));
-
-
-
- this.units = units;
- this.hasLowerBound = hasLowerBound;
- this.lowerBound = lowerBound;
- this.hasUpperBound = hasUpperBound;
- this.upperBound = upperBound;
- this.activeIntValue = activeIntValue;
- this.activeUnit = activeSelectedUnit;
-
- if (pendingSelectedUnit == null)
- {
- this.pendingIntValue = activeIntValue;
- this.pendingUnit = activeUnit;
- }
- else
- {
- this.pendingIntValue = pendingIntValue;
- this.pendingUnit = pendingSelectedUnit;
- }
-
- if (units.containsKey(activeUnit))
- {
- activeCalculatedValue = (long) (activeIntValue*units.get(activeUnit));
- }
-
-
- if (units.containsKey(pendingUnit))
- {
- pendingCalculatedValue = (long) (pendingIntValue*units.get(pendingUnit));
- }
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- @Override
- public String getDataType()
- {
- return "IntegerWithUnit";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- @Override
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultStringSyntax();
- }
-
-
-
- /**
- * Retrieves the integer component of the active value for this configuration
- * attribute.
- *
- * @return The integer component of the active value for this configuration
- * attribute.
- */
- public long activeIntValue()
- {
- return activeIntValue;
- }
-
-
-
- /**
- * Retrieves the name of the active unit for this configuration attribute.
- *
- * @return The name of the active unit for this configuration attribute.
- */
- public String activeUnit()
- {
- return activeUnit;
- }
-
-
-
- /**
- * Retrieves the calculated active value for this configuration attribute.
- * This will be the product of the active int value and the multiplier for the
- * associated active unit.
- *
- * @return The calculated active value for this configuration attribute.
- */
- public long activeCalculatedValue()
- {
- return activeCalculatedValue;
- }
-
-
-
- /**
- * Retrieves the integer component of the pending value for this configuration
- * attribute. If there is no pending value, then the integer component of the
- * active value will be returned.
- *
- * @return The integer component of the pending value for this configuration
- * attribute.
- */
- public long pendingIntValue()
- {
- if (hasPendingValues())
- {
- return pendingIntValue;
- }
- else
- {
- return activeIntValue;
- }
- }
-
-
-
- /**
- * Retrieves the name of the pending unit for this configuration attribute.
- * If there is no pending value, then the unit for the active value will be
- * returned.
- *
- * @return The name of the pending unit for this configuration attribute.
- */
- public String pendingUnit()
- {
- if (hasPendingValues())
- {
- return pendingUnit;
- }
- else
- {
- return activeUnit;
- }
- }
-
-
-
- /**
- * Retrieves the calculated pending value for this configuration attribute.
- * This will be the product of the pending int value and the multiplier for
- * the associated pending unit. If there is no pending value, then the
- * calculated active value will be returned.
- *
- * @return The calculated pending value for this configuration attribute.
- */
- public long pendingCalculatedValue()
- {
- if (hasPendingValues())
- {
- return pendingCalculatedValue;
- }
- else
- {
- return activeCalculatedValue;
- }
- }
-
-
-
- /**
- * Retrieves the mapping between the allowed names for the units and their
- * multipliers for this configuration attribute.
- *
- * @return The mapping between the allowed names for the units and their
- * multipliers for this configuration attribute.
- */
- public HashMap<String,Double> getUnits()
- {
- return units;
- }
-
-
-
- /**
- * Indicates whether a lower bound will be enforced for the calculated value
- * of this configuration attribute.
- *
- * @return <CODE>true</CODE> if a lower bound will be enforced for the
- * calculated value of this configuration attribute, or
- * <CODE>false</CODE> if not.
- */
- public boolean hasLowerBound()
- {
- return hasLowerBound;
- }
-
-
-
- /**
- * Retrieves the lower bound for the calculated value of this configuration
- * attribute.
- *
- * @return The lower bound for the calculated value of this configuration
- * attribute.
- */
- public long getLowerBound()
- {
- return lowerBound;
- }
-
-
-
- /**
- * Indicates whether an upper bound will be enforced for the calculated value
- * of this configuration attribute.
- *
- * @return <CODE>true</CODE> if an upper bound will be enforced for the
- * calculated value of this configuration attribute, or
- * <CODE>false</CODE> if not.
- */
- public boolean hasUpperBound()
- {
- return hasUpperBound;
- }
-
-
-
- /**
- * Retrieves the upper bound for the calculated value of this configuration
- * attribute.
- *
- * @return The upper bound for the calculated value of this configuration
- * attribute.
- */
- public long getUpperBound()
- {
- return upperBound;
- }
-
-
-
- /**
- * Sets the value for this configuration attribute.
- *
- * @param intValue The integer component for the value of this configuration
- * attribute.
- * @param unit The unit for the value of this configuration attribute.
- *
- * @throws ConfigException If the provided unit is not recognized, or if the
- * resulting calculated value is outside the
- * acceptable bounds.
- */
- public void setValue(long intValue, String unit)
- throws ConfigException
- {
- if (unit == null || !units.containsKey(unit))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_UNIT.get(unit, getName()));
- }
-
-
- long calculatedValue = (long) (intValue * units.get(unit));
- if (hasLowerBound && calculatedValue < lowerBound)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- getName(), calculatedValue, lowerBound);
- throw new ConfigException(message);
- }
- if (hasUpperBound && calculatedValue > upperBound)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- getName(), calculatedValue, upperBound);
- throw new ConfigException(message);
- }
-
-
- if (requiresAdminAction())
- {
- pendingCalculatedValue = calculatedValue;
- pendingIntValue = intValue;
- pendingUnit = unit;
- setPendingValues(getValueSet(intValue, unit));
- }
- else
- {
- activeCalculatedValue = calculatedValue;
- activeIntValue = intValue;
- activeUnit = unit;
- setActiveValues(getValueSet(intValue, unit));
- }
- }
-
-
-
- /**
- * Sets the value for this configuration attribute.
- *
- * @param value The string representation of the value to use for this
- * configuration attribute.
- *
- * @throws ConfigException If the provided value is invalid for some reason.
- */
- public void setValue(String value)
- throws ConfigException
- {
- int spacePos = value.indexOf(' ');
- if (spacePos <= 0)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_UNIT_DELIMITER.get(value, getName()));
- }
-
-
- long longValue;
- try
- {
- longValue = Long.parseLong(value.substring(0, spacePos));
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- LocalizableMessage message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(value, getName(), e);
- throw new ConfigException(message, e);
- }
-
- setValue(longValue, value.substring(spacePos+1));
- }
-
-
-
- /**
- * Creates the appropriate value set with the provided value.
- *
- * @param intValue The integer component for the value to construct.
- * @param unit The unit name for the value to construct.
- *
- * @return The constructed value set.
- */
- private static LinkedHashSet<ByteString> getValueSet(long intValue, String unit)
- {
- if (unit != null)
- {
- return getValueSet(intValue + " " + unit);
- }
- return null;
- }
-
-
-
- /**
- * 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.
- */
- @Override
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- activeCalculatedValue = pendingCalculatedValue;
- activeIntValue = pendingIntValue;
- activeUnit = pendingUnit;
- }
-
-
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * attribute. If it is not acceptable, then the reason should be written into
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- @Override
- public boolean valueIsAcceptable(ByteString value,
- StringBuilder rejectReason)
- {
- // Get a string representation of the value and convert it to lowercase.
- String lowerValue = value.toString().toLowerCase();
- return valueIsAcceptable(lowerValue, rejectReason);
- }
-
-
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * attribute. If it is not acceptable, then the reason should be written into
- * the provided buffer.
- *
- * @param lowerValue The lowercase version of the value for which to make
- * the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- public boolean valueIsAcceptable(String lowerValue,
- StringBuilder rejectReason)
- {
- // Find the first space in the value, since it should separate the integer
- // from the unit.
- int spacePos = lowerValue.indexOf(' ');
- if (spacePos < 0)
- {
- rejectReason.append(ERR_CONFIG_ATTR_NO_UNIT_DELIMITER.get(
- lowerValue, getName()));
- return false;
- }
-
-
- // The part up to the space should be the integer component.
- long longValue;
- try
- {
- longValue = Long.parseLong(lowerValue.substring(0, spacePos));
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- rejectReason.append(ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get(lowerValue, getName(), e));
- return false;
- }
-
-
- // The rest of the value should be the unit. See if it is in the set of
- // available units.
- String unit = lowerValue.substring(spacePos+1);
- if (!units.containsKey(unit))
- {
- rejectReason.append(ERR_CONFIG_ATTR_INVALID_UNIT.get(unit, getName()));
- return false;
- }
-
-
- // Multiply the int value by the unit multiplier and see if that is within
- // the specified bounds.
- double multiplier = units.get(unit);
- long calculatedValue = (long) (longValue * multiplier);
- if (hasLowerBound && calculatedValue < lowerBound)
- {
- rejectReason.append(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
- getName(), calculatedValue, lowerBound));
- return false;
- }
- if (hasUpperBound && calculatedValue > upperBound)
- {
- rejectReason.append(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
- getName(), calculatedValue, upperBound));
- return false;
- }
-
-
- // If we've gotten here, then the value is OK.
- return true;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- @Override
- public LinkedHashSet<ByteString>
- stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
- return new LinkedHashSet<>();
- }
-
-
- int numValues = valueStrings.size();
- if (!isMultiValued() && numValues > 1)
- {
- 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)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- continue;
- }
-
- StringBuilder rejectReason = new StringBuilder();
- if (!valueIsAcceptable(valueString.toLowerCase(), rejectReason))
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_INVALID_VALUE_WITH_UNIT.get(valueString, getName(), rejectReason));
- continue;
- }
-
- valueSet.add(ByteString.valueOfUtf8(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())
- {
- 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
- * set of strings that may be stored in the configuration or represented over
- * protocol. The string representation used by this method should be
- * 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.
- */
- @Override
- public List<String> activeValuesToStrings()
- {
- return newArrayList(activeIntValue + " " + activeUnit);
- }
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- @Override
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- return newArrayList(pendingIntValue + " " + pendingUnit);
- }
- return null;
- }
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- @Override
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- long activeIntValue = 0;
- long pendingIntValue = 0;
- String activeUnit = null;
- String pendingUnit = null;
-
- for (Attribute a : attributeList)
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (!attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- // This is illegal -- only the pending option is allowed for configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- if (pendingUnit != null)
- {
- // We cannot have multiple pending value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
-
- 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, attrDesc, e));
- }
-
- pendingCalculatedValue = calculateValue(pendingIntValue, activeUnit, pendingUnit, a);
- }
- else
- {
- // This must be the active value.
- if (activeUnit != null)
- {
- // We cannot have multiple active value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
-
- String valueString = getValue(a);
- 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, attrDesc, e));
- }
-
- activeCalculatedValue = calculateValue(activeIntValue, activeUnit, activeUnit, a);
- }
- }
-
- if (activeUnit == null)
- {
- // This is not OK. The value set must contain an active value.
- throw new ConfigException(ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()));
- }
-
- if (pendingUnit == null)
- {
- // This is OK. We'll just use the active value set.
- pendingIntValue = activeIntValue;
- pendingUnit = activeUnit;
- }
-
-
- return new IntegerWithUnitConfigAttribute(getName(), getDescription(),
- requiresAdminAction(), units,
- hasLowerBound, lowerBound,
- hasUpperBound, upperBound,
- activeIntValue, activeUnit,
- pendingIntValue, pendingUnit);
- }
-
- private String getValue(Attribute a) throws ConfigException
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (a.isEmpty())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
-
- 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(attrDesc));
- }
- 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.
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (!units.containsKey(pendingUnit))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, attrDesc));
- }
-
- 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(attrDesc, result, lowerBound));
- }
- if (hasUpperBound && result > upperBound)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(attrDesc, result, upperBound));
- }
- return result;
- }
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttribute()
- {
- return new javax.management.Attribute(getName(),
- activeIntValue + " " + activeUnit);
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- return new javax.management.Attribute(getName() + ";"
- + OPTION_PENDING_VALUES, pendingIntValue + " " + pendingUnit);
- }
-
-
- /**
- * Adds information about this configuration attribute to the provided
- * JMX attribute list. If this configuration attribute requires
- * administrative action before changes take effect and it has a set of
- * pending values, then two attributes should be added to the list --
- * one for the active value and one for the pending value. The pending
- * value should be named with the pending option.
- *
- * @param attributeList
- * The attribute list to which the JMX attribute(s) should
- * be added.
- */
- @Override
- public void toJMXAttribute(AttributeList attributeList)
- {
- String activeValue = activeIntValue + " " + activeUnit;
- attributeList.add(new javax.management.Attribute(getName(), activeValue));
-
- if (requiresAdminAction() && pendingCalculatedValue != activeCalculatedValue)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- String pendingValue = pendingIntValue + " " + pendingUnit;
- attributeList.add(new javax.management.Attribute(name, pendingValue));
- }
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- @Override
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(),
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, true, false));
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeInfoList.add(new MBeanAttributeInfo(name,
- String.class.getName(),
- String.valueOf(
- getDescription()),
- true, false, false));
- }
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- @Override
- public MBeanParameterInfo toJMXParameterInfo()
- {
- return new MBeanParameterInfo(getName(), String.class.getName(),
- String.valueOf(getDescription()));
- }
-
-
-
- /**
- * Attempts to set the value of this configuration attribute based on the
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- @Override
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value instanceof String)
- {
- setValue((String) value);
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_INT_WITH_UNIT_INVALID_TYPE.get(
- value, getName(), value.getClass().getName()));
- }
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- @Override
- public ConfigAttribute duplicate()
- {
- return new IntegerWithUnitConfigAttribute(getName(), getDescription(),
- requiresAdminAction(), units,
- hasLowerBound, lowerBound,
- hasUpperBound, upperBound,
- activeIntValue, activeUnit,
- pendingIntValue, pendingUnit);
- }
-}
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
deleted file mode 100644
index f3c97fe..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/MultiChoiceConfigAttribute.java
+++ /dev/null
@@ -1,1074 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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.AttributeDescription;
-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.opends.server.util.CollectionUtils;
-
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.messages.ConfigMessages.*;
-
-/**
- * This class defines a multi-choice configuration attribute, which can hold
- * zero or more string values. A user-defined set of allowed values will be
- * enforced.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class MultiChoiceConfigAttribute
- extends ConfigAttribute
-{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
- /** The set of active values for this attribute. */
- private List<String> activeValues;
-
- /** The set of pending values for this attribute. */
- private List<String> pendingValues;
-
- /** The set of allowed values for this attribute. */
- private Set<String> allowedValues;
-
-
-
- /**
- * Creates a new multi-choice configuration attribute stub with the provided
- * information but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method. No validation will be performed on
- * the set of allowed values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param allowedValues The set of allowed values for this attribute.
- * All values in this set should be represented
- * entirely in lowercase characters.
- */
- public MultiChoiceConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- Set<String> allowedValues)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction);
-
-
- this.allowedValues = allowedValues;
-
- activeValues = new ArrayList<>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new multi-choice configuration attribute with the provided
- * information. No validation will be performed on the provided value or the
- * set of allowed values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param allowedValues The set of allowed values for this attribute.
- * All values in this set should be represented
- * entirely in lowercase characters.
- * @param value The value for this string configuration
- * attribute.
- */
- public MultiChoiceConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- Set<String> allowedValues, String value)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(value));
-
-
- this.allowedValues = allowedValues;
-
- if (value == null)
- {
- activeValues = new ArrayList<>();
- }
- else
- {
- activeValues = CollectionUtils.newArrayList(value);
- }
-
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new multi-choice configuration attribute with the provided
- * information. No validation will be performed on the provided values or the
- * set of allowed values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param allowedValues The set of allowed values for this attribute.
- * All values in this set should be represented
- * entirely in lowercase characters.
- * @param values The set of values for this configuration
- * attribute.
- */
- public MultiChoiceConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- Set<String> allowedValues,
- List<String> values)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(values));
-
-
- this.allowedValues = allowedValues;
-
- activeValues = values != null ? values : new ArrayList<String>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new multi-choice configuration attribute with the provided
- * information. No validation will be performed on the provided values or the
- * set of allowed values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param allowedValues The set of allowed values for this attribute.
- * All values in this set should be represented
- * entirely in lowercase characters.
- * @param activeValues The set of active values for this
- * configuration attribute.
- * @param pendingValues The set of pending values for this
- * configuration attribute.
- */
- public MultiChoiceConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- Set<String> allowedValues,
- List<String> activeValues,
- List<String> pendingValues)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(activeValues), (pendingValues != null),
- getValueSet(pendingValues));
-
-
- this.allowedValues = allowedValues;
-
- if (activeValues == null)
- {
- this.activeValues = new ArrayList<>();
- }
- else
- {
- this.activeValues = activeValues;
- }
-
- if (pendingValues == null)
- {
- this.pendingValues = this.activeValues;
- }
- else
- {
- this.pendingValues = pendingValues;
- }
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- @Override
- public String getDataType()
- {
- return "MultiChoice";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- @Override
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultStringSyntax();
- }
-
-
-
- /**
- * Retrieves the active value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value.
- *
- * @return The active value for this configuration attribute as a string.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * active value.
- */
- public String activeValue() throws ConfigException
- {
- if (activeValues == null || activeValues.isEmpty())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()));
- }
- if (activeValues.size() > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()));
- }
-
- return activeValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of active values for this configuration attribute.
- *
- * @return The set of active values for this configuration attribute.
- */
- public List<String> activeValues()
- {
- return activeValues;
- }
-
-
-
- /**
- * Retrieves the pending value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value. If this
- * attribute does not have any pending values, then the active value will be
- * returned.
- *
- * @return The pending value for this configuration attribute as a string.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * pending value.
- */
- public String pendingValue()
- throws ConfigException
- {
- if (! hasPendingValues())
- {
- return activeValue();
- }
-
- if (pendingValues == null || pendingValues.isEmpty())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()));
- }
- if (pendingValues.size() > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()));
- }
-
- return pendingValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of pending values for this configuration attribute. If
- * there are no pending values, then the set of active values will be
- * returned.
- *
- * @return The set of pending values for this configuration attribute.
- */
- public List<String> pendingValues()
- {
- if (! hasPendingValues())
- {
- return activeValues;
- }
-
- return pendingValues;
- }
-
-
-
- /**
- * Retrieves the set of allowed values that may be used for this configuration
- * attribute. The set of allowed values may be modified by the caller.
- *
- * @return The set of allowed values that may be used for this configuration
- * attribute.
- */
- public Set<String> allowedValues()
- {
- return allowedValues;
- }
-
-
-
- /**
- * Sets the value for this string configuration attribute.
- *
- * @param value The value for this string configuration attribute.
- *
- * @throws ConfigException If the provided value is not acceptable.
- */
- public void setValue(String value)
- throws ConfigException
- {
- if (value == null || value.length() == 0)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName());
- throw new ConfigException(message);
- }
-
- if (! allowedValues.contains(value.toLowerCase()))
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(value, getName());
- throw new ConfigException(message);
- }
-
- if (requiresAdminAction())
- {
- pendingValues = CollectionUtils.newArrayList(value);
- setPendingValues(getValueSet(value));
- }
- else
- {
- activeValues.clear();
- activeValues.add(value);
- pendingValues = activeValues;
- setActiveValues(getValueSet(value));
- }
- }
-
-
-
- /**
- * Sets the values for this string configuration attribute.
- *
- * @param values The set of values for this string configuration attribute.
- *
- * @throws ConfigException If the provided value set or any of the
- * individual values are not acceptable.
- */
- public void setValues(List<String> values)
- throws ConfigException
- {
- // First check if the set is empty and if that is allowed.
- if (values == null || values.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
-
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- 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)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
- }
-
-
- // Iterate through all the provided values, make sure that they are
- // acceptable, and build the value set.
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
- for (String value : values)
- {
- if (value == null || value.length() == 0)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- }
- if (!allowedValues.contains(value.toLowerCase()))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(value, getName()));
- }
-
- ByteString attrValue = ByteString.valueOfUtf8(value);
- if (valueSet.contains(attrValue))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
- }
-
- valueSet.add(attrValue);
- }
-
-
- // Apply this value set to the new active or pending value set.
- if (requiresAdminAction())
- {
- pendingValues = values;
- setPendingValues(valueSet);
- }
- else
- {
- activeValues = values;
- pendingValues = activeValues;
- setActiveValues(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.
- */
- @Override
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- 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
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- @Override
- public boolean valueIsAcceptable(ByteString value,
- StringBuilder rejectReason)
- {
- // Make sure that the value is non-empty.
- String stringValue;
- if (value == null || (stringValue = value.toString()).length() == 0)
- {
- rejectReason.append(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- return false;
- }
-
-
- // Make sure that the value is in the allowed value set.
- if (! allowedValues.contains(stringValue.toLowerCase()))
- {
- rejectReason.append(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(stringValue, getName()));
- return false;
- }
-
-
- return true;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- @Override
- public LinkedHashSet<ByteString>
- stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
- return new LinkedHashSet<>();
- }
-
- int numValues = valueStrings.size();
- if (!isMultiValued() && numValues > 1)
- {
- 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)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- continue;
- }
- if (! allowedValues.contains(valueString.toLowerCase()))
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(valueString, getName()));
- continue;
- }
-
- valueSet.add(ByteString.valueOfUtf8(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())
- {
- 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
- * set of strings that may be stored in the configuration or represented over
- * protocol. The string representation used by this method should be
- * 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.
- */
- @Override
- public List<String> activeValuesToStrings()
- {
- return 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- @Override
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- return pendingValues;
- }
- return null;
- }
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- @Override
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- ArrayList<String> activeValues = null;
- ArrayList<String> pendingValues = null;
-
- for (Attribute a : attributeList)
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- if (pendingValues != null)
- {
- // We cannot have multiple pending value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- pendingValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- String lowerValue = v.toString().toLowerCase();
- if (! allowedValues.contains(lowerValue))
- {
- // This is illegal -- the value is not allowed.
- throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, attrDesc));
- }
-
- pendingValues.add(v.toString());
- }
- }
- }
- else
- {
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- }
- else
- {
- // This must be the active value.
- if (activeValues!= null)
- {
- // We cannot have multiple active value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && ! isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- activeValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- String lowerValue = v.toString().toLowerCase();
- if (! allowedValues.contains(lowerValue))
- {
- // This is illegal -- the value is not allowed.
- throw new ConfigException(ERR_CONFIG_ATTR_VALUE_NOT_ALLOWED.get(v, attrDesc));
- }
-
- activeValues.add(v.toString());
- }
- }
- }
- }
-
- if (activeValues == 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);
- }
-
- if (pendingValues == null)
- {
- // This is OK. We'll just use the active value set.
- pendingValues = activeValues;
- }
-
- return new MultiChoiceConfigAttribute(getName(), getDescription(),
- isRequired(), isMultiValued(),
- requiresAdminAction(), allowedValues,
- activeValues, pendingValues);
- }
-
-
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute (active or pending).
- *
- * @param pending indicates if pending or active values are required.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- private javax.management.Attribute _toJMXAttribute(boolean pending)
- {
- List<String> requestedValues ;
- String name ;
- if (pending)
- {
- requestedValues = pendingValues ;
- name = getName() + ";" + OPTION_PENDING_VALUES ;
- }
- else
- {
- requestedValues = activeValues ;
- name = getName() ;
- }
-
- if (isMultiValued())
- {
- String[] values = new String[requestedValues.size()];
- requestedValues.toArray(values);
-
- return new javax.management.Attribute(name, values);
- }
- else if (!requestedValues.isEmpty())
- {
- return new javax.management.Attribute(name, requestedValues.get(0));
- }
- return null;
- }
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttribute()
- {
- return _toJMXAttribute(false) ;
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- return _toJMXAttribute(true) ;
- }
-
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- @Override
- public void toJMXAttribute(AttributeList attributeList)
- {
- if (!activeValues.isEmpty())
- {
- if (isMultiValued())
- {
- String[] values = new String[activeValues.size()];
- activeValues.toArray(values);
-
- attributeList.add(new javax.management.Attribute(getName(), values));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(),
- activeValues.get(0)));
- }
- }
- else
- {
- if (isMultiValued())
- {
- attributeList.add(new javax.management.Attribute(getName(),
- new String[0]));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(), null));
- }
- }
-
-
- if (requiresAdminAction() && pendingValues != null && pendingValues != activeValues)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- String[] values = new String[pendingValues.size()];
- pendingValues.toArray(values);
-
- attributeList.add(new javax.management.Attribute(name, values));
- }
- else if (! pendingValues.isEmpty())
- {
- attributeList.add(new javax.management.Attribute(name, pendingValues.get(0)));
- }
- }
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- @Override
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
- String.valueOf(getDescription()), true, true, false));
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
- String.valueOf(getDescription()), true, false, false));
- }
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- @Override
- public MBeanParameterInfo toJMXParameterInfo()
- {
- 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
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- @Override
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value instanceof String)
- {
- setValue((String) value);
- }
- else if (value.getClass().isArray())
- {
- String componentType = value.getClass().getComponentType().getName();
- int length = Array.getLength(value);
-
- if (componentType.equals(String.class.getName()))
- {
- try
- {
- ArrayList<String> values = new ArrayList<>(length);
-
- for (int i=0; i < length; i++)
- {
- values.add((String) Array.get(value, i));
- }
-
- setValues(values);
- }
- catch (ConfigException ce)
- {
- logger.traceException(ce);
-
- throw ce;
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_STRING_VALUE.get(getName(), value, e), e);
- }
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_STRING_INVALID_ARRAY_TYPE.get(
- getName(), componentType);
- throw new ConfigException(message);
- }
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_STRING_INVALID_TYPE.get(value, getName(), value.getClass().getName()));
- }
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- @Override
- public ConfigAttribute duplicate()
- {
- return new MultiChoiceConfigAttribute(getName(), getDescription(),
- isRequired(), isMultiValued(),
- requiresAdminAction(), allowedValues,
- 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
deleted file mode 100644
index f18c646..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/ReadOnlyConfigAttribute.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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 static org.opends.messages.ConfigMessages.*;
-import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.util.CollectionUtils.*;
-
-/**
- * This class defines a configuration attribute that is only intended for use
- * in displaying information. It will not allow its value to be altered.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class ReadOnlyConfigAttribute
- extends ConfigAttribute
-{
- /** The set of values for this attribute. */
- private List<String> values;
-
-
-
- /**
- * Creates a new read-only configuration attribute stub with the provided
- * information but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration attribute.
- * @param isMultiValued Indicates whether this configuration attribute may
- * have multiple values.
- */
- public ReadOnlyConfigAttribute(String name, LocalizableMessage description,
- boolean isMultiValued)
- {
- super(name, description, false, isMultiValued, false);
-
-
- values = new ArrayList<>();
- }
-
-
-
- /**
- * Creates a new read-only configuration attribute with the provided
- * information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration attribute.
- * @param value The value for this configuration attribute.
- */
- public ReadOnlyConfigAttribute(String name, LocalizableMessage description, String value)
- {
- super(name, description, false, false, false, getValueSet(value));
-
-
- if (value == null)
- {
- values = new ArrayList<>(0);
- }
- else
- {
- values = newArrayList(value);
- }
- }
-
-
-
- /**
- * Creates a new read-only configuration attribute with the provided
- * information.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration attribute.
- * @param values The set of values for this configuration attribute.
- */
- public ReadOnlyConfigAttribute(String name, LocalizableMessage description,
- List<String> values)
- {
- super(name, description, false, true, false, getValueSet(values));
-
-
- if (values == null)
- {
- this.values = new ArrayList<>();
- }
- else
- {
- this.values = values;
- }
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- public String getDataType()
- {
- return "ReadOnly";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultStringSyntax();
- }
-
-
-
- /**
- * Retrieves the active value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value.
- *
- * @return The active value for this configuration attribute as a string.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * active value.
- */
- public String activeValue()
- throws ConfigException
- {
- if (values == null || values.isEmpty())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()));
- }
- if (values.size() > 1)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()));
- }
-
- return values.get(0);
- }
-
-
-
- /**
- * Retrieves the set of active values for this configuration attribute.
- *
- * @return The set of active values for this configuration attribute.
- */
- public List<String> activeValues()
- {
- return values;
- }
-
-
-
- /**
- * Retrieves the pending value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value. If this
- * attribute does not have any pending values, then the active value will be
- * returned.
- *
- * @return The pending value for this configuration attribute as a string.
- *
- * @throws ConfigException If this attribute does not have exactly one
- * pending value.
- */
- public String pendingValue()
- throws ConfigException
- {
- return activeValue();
- }
-
-
-
- /**
- * Retrieves the set of pending values for this configuration attribute. If
- * there are no pending values, then the set of active values will be
- * returned.
- *
- * @return The set of pending values for this configuration attribute.
- */
- public List<String> pendingValues()
- {
- return activeValues();
- }
-
-
-
- /**
- * Sets the value for this string configuration attribute.
- *
- * @param value The value for this string configuration attribute.
- *
- * @throws ConfigException If the provided value is not acceptable.
- */
- public void setValue(String value) throws ConfigException
- {
- throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
- }
-
-
-
- /**
- * Sets the values for this string configuration attribute.
- *
- * @param values The set of values for this string configuration attribute.
- *
- * @throws ConfigException If the provided value set or any of the
- * individual values are not acceptable.
- */
- public void setValues(List<String> values) throws ConfigException
- {
- throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
- }
-
-
-
- /**
- * 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.
- */
- public void applyPendingValues()
- {
- }
-
-
-
- /**
- * Indicates whether the provided value is acceptable for use in this
- * attribute. If it is not acceptable, then the reason should be written into
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- public boolean valueIsAcceptable(ByteString value, StringBuilder rejectReason)
- {
- rejectReason.append(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
- return false;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- return new LinkedHashSet<>();
- }
- return getValueSet(valueStrings);
- }
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * 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.
- */
- public List<String> activeValuesToStrings()
- {
- return values;
- }
-
-
-
- /**
- * 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- public List<String> pendingValuesToStrings()
- {
- return activeValuesToStrings();
- }
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- // The attribute won't be present in the entry, so we'll just return a
- // reference to this attribute.
- return duplicate();
- }
-
-
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- public javax.management.Attribute toJMXAttribute()
- {
- if (isMultiValued())
- {
- 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
- {
- return null;
- }
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute. As this an read only attribute, this method
- * should never be called
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute, or <CODE>null</CODE> if it does
- * not have any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- // Should never occur !!!
- return toJMXAttribute();
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- public void toJMXAttribute(AttributeList attributeList)
- {
- attributeList.add(toJMXAttribute());
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
- String.valueOf(getDescription()), true, false, false));
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- public MBeanParameterInfo toJMXParameterInfo()
- {
- 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
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- throw new ConfigException(ERR_CONFIG_ATTR_READ_ONLY.get(getName()));
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- public ConfigAttribute duplicate()
- {
- 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
deleted file mode 100644
index ea8d5ae..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/config/StringConfigAttribute.java
+++ /dev/null
@@ -1,990 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.config;
-
-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;
-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.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.AttributeDescription;
-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;
-
-/**
- * This class defines a string configuration attribute, which can hold zero or
- * more string values.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class StringConfigAttribute
- extends ConfigAttribute
-{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
- /** The set of active values for this attribute. */
- private List<String> activeValues;
-
- /** The set of pending values for this attribute. */
- private List<String> pendingValues;
-
-
-
- /**
- * Creates a new string configuration attribute stub with the provided
- * information but no values. The values will be set using the
- * <CODE>setInitialValue</CODE> method.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- */
- public StringConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction);
-
-
- activeValues = new ArrayList<>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new string configuration attribute with the provided information.
- * No validation will be performed on the provided value.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param value The value for this string configuration
- * attribute.
- */
- public StringConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction, String value)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(value));
-
-
- if (value == null)
- {
- activeValues = new ArrayList<>();
- }
- else
- {
- activeValues = newArrayList(value);
- }
-
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new string configuration attribute with the provided information.
- * No validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param values The set of values for this configuration
- * attribute.
- */
- public StringConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction, List<String> values)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(values));
-
-
- activeValues = values != null ? values : new ArrayList<String>();
- pendingValues = activeValues;
- }
-
-
-
- /**
- * Creates a new string configuration attribute with the provided information.
- * No validation will be performed on the provided values.
- *
- * @param name The name for this configuration attribute.
- * @param description The description for this configuration
- * attribute.
- * @param isRequired Indicates whether this configuration attribute
- * is required to have at least one value.
- * @param isMultiValued Indicates whether this configuration attribute
- * may have multiple values.
- * @param requiresAdminAction Indicates whether changes to this
- * configuration attribute require administrative
- * action before they will take effect.
- * @param activeValues The set of active values for this
- * configuration attribute.
- * @param pendingValues The set of pending values for this
- * configuration attribute.
- */
- public StringConfigAttribute(String name, LocalizableMessage description,
- boolean isRequired, boolean isMultiValued,
- boolean requiresAdminAction,
- List<String> activeValues,
- List<String> pendingValues)
- {
- super(name, description, isRequired, isMultiValued, requiresAdminAction,
- getValueSet(activeValues), (pendingValues != null),
- getValueSet(pendingValues));
-
-
- if (activeValues == null)
- {
- this.activeValues = new ArrayList<>();
- }
- else
- {
- this.activeValues = activeValues;
- }
-
- if (pendingValues == null)
- {
- this.pendingValues = this.activeValues;
- }
- else
- {
- this.pendingValues = pendingValues;
- }
- }
-
-
-
- /**
- * Retrieves the name of the data type for this configuration attribute. This
- * is for informational purposes (e.g., inclusion in method signatures and
- * other kinds of descriptions) and does not necessarily need to map to an
- * actual Java type.
- *
- * @return The name of the data type for this configuration attribute.
- */
- @Override
- public String getDataType()
- {
- return "String";
- }
-
-
-
- /**
- * Retrieves the attribute syntax for this configuration attribute.
- *
- * @return The attribute syntax for this configuration attribute.
- */
- @Override
- public Syntax getSyntax()
- {
- return DirectoryServer.getDefaultStringSyntax();
- }
-
-
-
- /**
- * Retrieves the active value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value.
- *
- * @return The active value for this configuration attribute as a string.
- * @throws org.forgerock.opendj.config.server.ConfigException
- * If this attribute does not have exactly one active value.
- */
- public String activeValue()
- throws org.forgerock.opendj.config.server.ConfigException
- {
- if (activeValues == null || activeValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName());
- throw new org.forgerock.opendj.config.server.ConfigException(message);
- }
-
- if (activeValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName());
- throw new org.forgerock.opendj.config.server.ConfigException(message);
- }
-
- return activeValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of active values for this configuration attribute.
- *
- * @return The set of active values for this configuration attribute.
- */
- public List<String> activeValues()
- {
- return activeValues;
- }
-
-
-
- /**
- * Retrieves the pending value for this configuration attribute as a string.
- * This is only valid for single-valued attributes that have a value. If this
- * attribute does not have any pending values, then the active value will be
- * returned.
- *
- * @return The pending value for this configuration attribute as a string.
- * @throws org.forgerock.opendj.config.server.ConfigException
- * If this attribute does not have exactly one pending value.
- */
- public String pendingValue()
- throws org.forgerock.opendj.config.server.ConfigException
- {
- if (! hasPendingValues())
- {
- return activeValue();
- }
-
- if (pendingValues == null || pendingValues.isEmpty())
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName());
- throw new org.forgerock.opendj.config.server.ConfigException(message);
- }
-
- if (pendingValues.size() > 1)
- {
- LocalizableMessage message = ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName());
- throw new org.forgerock.opendj.config.server.ConfigException(message);
- }
-
- return pendingValues.get(0);
- }
-
-
-
- /**
- * Retrieves the set of pending values for this configuration attribute. If
- * there are no pending values, then the set of active values will be
- * returned.
- *
- * @return The set of pending values for this configuration attribute.
- */
- public List<String> pendingValues()
- {
- if (!hasPendingValues())
- {
- return activeValues;
- }
- return pendingValues;
- }
-
-
-
- /**
- * Sets the value for this string configuration attribute.
- *
- * @param value The value for this string configuration attribute.
- *
- * @throws ConfigException If the provided value is not acceptable.
- */
- public void setValue(String value)
- throws ConfigException
- {
- if (value == null || value.length() == 0)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- }
-
- if (requiresAdminAction())
- {
- pendingValues = newArrayList(value);
- setPendingValues(getValueSet(value));
- }
- else
- {
- activeValues.clear();
- activeValues.add(value);
- pendingValues = activeValues;
- setActiveValues(getValueSet(value));
- }
- }
-
-
-
- /**
- * Sets the values for this string configuration attribute.
- *
- * @param values The set of values for this string configuration attribute.
- *
- * @throws ConfigException If the provided value set or any of the
- * individual values are not acceptable.
- */
- public void setValues(List<String> values)
- throws ConfigException
- {
- // First check if the set is empty and if that is allowed.
- if (values == null || values.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
-
- if (requiresAdminAction())
- {
- setPendingValues(new LinkedHashSet<ByteString>(0));
- pendingValues = new ArrayList<>();
- }
- else
- {
- 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)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()));
- }
-
-
- // Iterate through all the provided values, make sure that they are
- // acceptable, and build the value set.
- LinkedHashSet<ByteString> valueSet = new LinkedHashSet<>(numValues);
- for (String value : values)
- {
- if (value == null || value.length() == 0)
- {
- throw new ConfigException(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- }
-
- ByteString attrValue = ByteString.valueOfUtf8(value);
- if (valueSet.contains(attrValue))
- {
- throw new ConfigException(ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value));
- }
-
- valueSet.add(attrValue);
- }
-
-
- // Apply this value set to the new active or pending value set.
- if (requiresAdminAction())
- {
- pendingValues = values;
- setPendingValues(valueSet);
- }
- else
- {
- activeValues = values;
- pendingValues = activeValues;
- setActiveValues(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.
- */
- @Override
- public void applyPendingValues()
- {
- if (! hasPendingValues())
- {
- return;
- }
-
- super.applyPendingValues();
- 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
- * the provided buffer.
- *
- * @param value The value for which to make the determination.
- * @param rejectReason A buffer into which a human-readable reason for the
- * reject may be written.
- *
- * @return <CODE>true</CODE> if the provided value is acceptable for use in
- * this attribute, or <CODE>false</CODE> if not.
- */
- @Override
- public boolean valueIsAcceptable(ByteString value,
- StringBuilder rejectReason)
- {
- // The only requirement is that the value is not null or empty.
- if (value == null || value.toString().length() == 0)
- {
- rejectReason.append(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- return false;
- }
- return true;
- }
-
-
-
- /**
- * Converts the provided set of strings to a corresponding set of attribute
- * values.
- *
- * @param valueStrings The set of strings to be converted into attribute
- * values.
- * @param allowFailures Indicates whether the decoding process should allow
- * any failures in which one or more values could be
- * decoded but at least one could not. If this is
- * <CODE>true</CODE> and such a condition is acceptable
- * for the underlying attribute type, then the returned
- * set of values should simply not include those
- * undecodable values.
- *
- * @return The set of attribute values converted from the provided strings.
- *
- * @throws ConfigException If an unrecoverable problem occurs while
- * performing the conversion.
- */
- @Override
- public LinkedHashSet<ByteString> stringsToValues(List<String> valueStrings, boolean allowFailures)
- throws ConfigException
- {
- if (valueStrings == null || valueStrings.isEmpty())
- {
- if (isRequired())
- {
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()));
- }
- return new LinkedHashSet<>();
- }
-
- int numValues = valueStrings.size();
- if (!isMultiValued() && numValues > 1)
- {
- 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)
- {
- reportError(allowFailures, ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()));
- continue;
- }
-
- valueSet.add(ByteString.valueOfUtf8(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())
- {
- 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
- * set of strings that may be stored in the configuration or represented over
- * protocol. The string representation used by this method should be
- * 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.
- */
- @Override
- public List<String> activeValuesToStrings()
- {
- return 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
- * protocol. The string representation used by this method should be
- * compatible with the decoding used by the <CODE>stringsToValues</CODE>
- * method.
- *
- * @return The string representations of the set of pending values for this
- * configuration attribute, or <CODE>null</CODE> if there are no
- * pending values.
- */
- @Override
- public List<String> pendingValuesToStrings()
- {
- if (hasPendingValues())
- {
- return pendingValues;
- }
- return null;
- }
-
-
-
- /**
- * Retrieves a new configuration attribute of this type that will contain the
- * values from the provided attribute.
- *
- * @param attributeList The list of attributes to use to create the config
- * attribute. The list must contain either one or two
- * elements, with both attributes having the same base
- * name and the only option allowed is ";pending" and
- * only if this attribute is one that requires admin
- * action before a change may take effect.
- *
- * @return The generated configuration attribute.
- *
- * @throws ConfigException If the provided attribute cannot be treated as a
- * configuration attribute of this type (e.g., if
- * one or more of the values of the provided
- * attribute are not suitable for an attribute of
- * this type, or if this configuration attribute is
- * single-valued and the provided attribute has
- * multiple values).
- */
- @Override
- public ConfigAttribute getConfigAttribute(List<Attribute> attributeList)
- throws ConfigException
- {
- ArrayList<String> activeValues = null;
- ArrayList<String> pendingValues = null;
-
- for (Attribute a : attributeList)
- {
- AttributeDescription attrDesc = a.getAttributeDescription();
- if (attrDesc.hasOptions())
- {
- // This must be the pending value.
- if (attrDesc.hasOption(OPTION_PENDING_VALUES))
- {
- if (pendingValues != null)
- {
- // We cannot have multiple pending value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The pending value set can be empty.
- pendingValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- pendingValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- pendingValues.add(v.toString());
- }
- }
- }
- else
- {
- // This is illegal -- only the pending option is allowed for
- // configuration attributes.
- throw new ConfigException(ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(attrDesc));
- }
- }
- else
- {
- // This must be the active value.
- if (activeValues!= null)
- {
- // We cannot have multiple active value sets.
- throw new ConfigException(ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(attrDesc));
- }
-
-
- if (a.isEmpty())
- {
- if (isRequired())
- {
- // This is illegal -- it must have a value.
- throw new ConfigException(ERR_CONFIG_ATTR_IS_REQUIRED.get(attrDesc));
- }
- // This is fine. The active value set can be empty.
- activeValues = new ArrayList<>(0);
- }
- else
- {
- int numValues = a.size();
- if (numValues > 1 && !isMultiValued())
- {
- // This is illegal -- the attribute is single-valued.
- throw new ConfigException(ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(attrDesc));
- }
-
- activeValues = new ArrayList<>(numValues);
- for (ByteString v : a)
- {
- activeValues.add(v.toString());
- }
- }
- }
- }
-
- if (activeValues == 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);
- }
-
- if (pendingValues == null)
- {
- // This is OK. We'll just use the active value set.
- pendingValues = activeValues;
- }
-
- return new StringConfigAttribute(getName(), getDescription(), isRequired(),
- isMultiValued(), requiresAdminAction(),
- activeValues, pendingValues);
- }
-
-
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @param pending indicates if pending or active values are required.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- private javax.management.Attribute _toJMXAttribute(boolean pending)
- {
- List<String> requestedValues;
- String name;
- if (pending)
- {
- requestedValues = pendingValues ;
- name = getName() + ";" + OPTION_PENDING_VALUES ;
- }
- else
- {
- requestedValues = activeValues ;
- name = getName() ;
- }
-
- if (isMultiValued())
- {
- 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
- {
- return null;
- }
- }
-
- /**
- * Retrieves a JMX attribute containing the active value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the active value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttribute()
- {
- return _toJMXAttribute(false) ;
- }
-
- /**
- * Retrieves a JMX attribute containing the pending value set for this
- * configuration attribute.
- *
- * @return A JMX attribute containing the pending value set for this
- * configuration attribute, or <CODE>null</CODE> if it does not have
- * any active values.
- */
- @Override
- public javax.management.Attribute toJMXAttributePending()
- {
- return _toJMXAttribute(true) ;
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided JMX
- * attribute list. If this configuration attribute requires administrative
- * action before changes take effect and it has a set of pending values, then
- * two attributes should be added to the list -- one for the active value
- * and one for the pending value. The pending value should be named with
- * the pending option.
- *
- * @param attributeList The attribute list to which the JMX attribute(s)
- * should be added.
- */
- @Override
- public void toJMXAttribute(AttributeList attributeList)
- {
- if (!activeValues.isEmpty())
- {
- if (isMultiValued())
- {
- String[] values = new String[activeValues.size()];
- activeValues.toArray(values);
-
- attributeList.add(new javax.management.Attribute(getName(), values));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(),
- activeValues.get(0)));
- }
- }
- else
- {
- if (isMultiValued())
- {
- attributeList.add(new javax.management.Attribute(getName(),
- new String[0]));
- }
- else
- {
- attributeList.add(new javax.management.Attribute(getName(), null));
- }
- }
-
-
- if (requiresAdminAction() && pendingValues != null && pendingValues != activeValues)
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
-
- if (isMultiValued())
- {
- String[] values = new String[pendingValues.size()];
- pendingValues.toArray(values);
-
- attributeList.add(new javax.management.Attribute(name, values));
- }
- else if (! pendingValues.isEmpty())
- {
- attributeList.add(new javax.management.Attribute(name, pendingValues.get(0)));
- }
- }
- }
-
-
-
- /**
- * Adds information about this configuration attribute to the provided list in
- * the form of a JMX <CODE>MBeanAttributeInfo</CODE> object. If this
- * configuration attribute requires administrative action before changes take
- * effect and it has a set of pending values, then two attribute info objects
- * should be added to the list -- one for the active value (which should be
- * read-write) and one for the pending value (which should be read-only). The
- * pending value should be named with the pending option.
- *
- * @param attributeInfoList The list to which the attribute information
- * should be added.
- */
- @Override
- public void toJMXAttributeInfo(List<MBeanAttributeInfo> attributeInfoList)
- {
- attributeInfoList.add(new MBeanAttributeInfo(getName(), getType(),
- String.valueOf(getDescription()), true, true, false));
-
- if (requiresAdminAction())
- {
- String name = getName() + ";" + OPTION_PENDING_VALUES;
- attributeInfoList.add(new MBeanAttributeInfo(name, getType(),
- String.valueOf(getDescription()), true, false, false));
- }
- }
-
-
-
- /**
- * Retrieves a JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- *
- * @return A JMX <CODE>MBeanParameterInfo</CODE> object that describes this
- * configuration attribute.
- */
- @Override
- public MBeanParameterInfo toJMXParameterInfo()
- {
- 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
- * information in the provided JMX attribute.
- *
- * @param jmxAttribute The JMX attribute to use to attempt to set the value
- * of this configuration attribute.
- *
- * @throws ConfigException If the provided JMX attribute does not have an
- * acceptable value for this configuration
- * attribute.
- */
- @Override
- public void setValue(javax.management.Attribute jmxAttribute)
- throws ConfigException
- {
- Object value = jmxAttribute.getValue();
- if (value instanceof String)
- {
- setValue((String) value);
- }
- else if (value.getClass().isArray())
- {
- String componentType = value.getClass().getComponentType().getName();
- int length = Array.getLength(value);
-
- if (componentType.equals(String.class.getName()))
- {
- try
- {
- ArrayList<String> values = new ArrayList<>(length);
-
- for (int i=0; i < length; i++)
- {
- values.add((String) Array.get(value, i));
- }
-
- setValues(values);
- }
- catch (ConfigException ce)
- {
- logger.traceException(ce);
-
- throw ce;
- }
- catch (Exception e)
- {
- logger.traceException(e);
-
- throw new ConfigException(ERR_CONFIG_ATTR_INVALID_STRING_VALUE.get(getName(), value, e), e);
- }
- }
- else
- {
- LocalizableMessage message =
- ERR_CONFIG_ATTR_STRING_INVALID_ARRAY_TYPE.get(jmxAttribute, componentType);
- throw new ConfigException(message);
- }
- }
- else
- {
- throw new ConfigException(ERR_CONFIG_ATTR_STRING_INVALID_TYPE.get(
- value, getName(), value.getClass().getName()));
- }
- }
-
-
-
- /**
- * Creates a duplicate of this configuration attribute.
- *
- * @return A duplicate of this configuration attribute.
- */
- @Override
- public ConfigAttribute duplicate()
- {
- return new StringConfigAttribute(getName(), getDescription(), isRequired(),
- isMultiValued(), requiresAdminAction(),
- activeValues, pendingValues);
- }
-}
--
Gitblit v1.10.0