| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.config; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ErrorLogCategory; |
| | | import org.opends.server.types.ErrorLogSeverity; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.server.messages.ConfigMessages.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | |
| | | |
| | | |
| | | import org.opends.server.loggers.ErrorLogger; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | /** |
| | | * This class defines a string configuration attribute, which can hold zero or |
| | | * more string values. |
| | |
| | | * configuration attribute require administrative |
| | | * action before they will take effect. |
| | | */ |
| | | public StringConfigAttribute(String name, String description, |
| | | public StringConfigAttribute(String name, Message description, |
| | | boolean isRequired, boolean isMultiValued, |
| | | boolean requiresAdminAction) |
| | | { |
| | |
| | | * @param value The value for this string configuration |
| | | * attribute. |
| | | */ |
| | | public StringConfigAttribute(String name, String description, |
| | | public StringConfigAttribute(String name, Message description, |
| | | boolean isRequired, boolean isMultiValued, |
| | | boolean requiresAdminAction, String value) |
| | | { |
| | |
| | | * @param values The set of values for this configuration |
| | | * attribute. |
| | | */ |
| | | public StringConfigAttribute(String name, String description, |
| | | public StringConfigAttribute(String name, Message description, |
| | | boolean isRequired, boolean isMultiValued, |
| | | boolean requiresAdminAction, List<String> values) |
| | | { |
| | |
| | | * @param pendingValues The set of pending values for this |
| | | * configuration attribute. |
| | | */ |
| | | public StringConfigAttribute(String name, String description, |
| | | public StringConfigAttribute(String name, Message description, |
| | | boolean isRequired, boolean isMultiValued, |
| | | boolean requiresAdminAction, |
| | | List<String> activeValues, |
| | |
| | | { |
| | | if ((activeValues == null) || activeValues.isEmpty()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_NO_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (activeValues.size() > 1) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_STRING_VALUES; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | return activeValues.get(0); |
| | |
| | | |
| | | if ((pendingValues == null) || pendingValues.isEmpty()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_NO_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_NO_STRING_VALUE.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (pendingValues.size() > 1) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_STRING_VALUES; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_MULTIPLE_STRING_VALUES.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | return pendingValues.get(0); |
| | |
| | | { |
| | | if ((value == null) || (value.length() == 0)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_EMPTY_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (requiresAdminAction()) |
| | |
| | | { |
| | | if (isRequired()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | int numValues = values.size(); |
| | | if ((! isMultiValued()) && (numValues > 1)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if ((value == null) || (value.length() == 0)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_EMPTY_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | AttributeValue attrValue = |
| | |
| | | |
| | | if (valueSet.contains(attrValue)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS; |
| | | String message = getMessage(msgID, getName(), value); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_ADD_VALUES_ALREADY_EXISTS.get(getName(), value); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | valueSet.add(attrValue); |
| | |
| | | // The only requirement is that the value is not null or empty. |
| | | if ((value == null) || (value.getStringValue().length() == 0)) |
| | | { |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_EMPTY_STRING_VALUE, |
| | | getName())); |
| | | rejectReason.append(ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName())); |
| | | return false; |
| | | } |
| | | |
| | |
| | | { |
| | | if (isRequired()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | int numValues = valueStrings.size(); |
| | | if ((! isMultiValued()) && (numValues > 1)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if ((valueString == null) || (valueString.length() == 0)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_EMPTY_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | Message message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()); |
| | | |
| | | if (allowFailures) |
| | | { |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.MILD_ERROR, |
| | | message, msgID); |
| | | ErrorLogger.logError(message); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | throw new ConfigException(msgID, message); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |
| | |
| | | // attribute and if so deal with it accordingly. |
| | | if ((isRequired()) && valueSet.isEmpty()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (pendingValues != null) |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | if ((numValues > 1) && (! isMultiValued())) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | pendingValues = new ArrayList<String>(numValues); |
| | |
| | | { |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | int msgID = MSGID_CONFIG_ATTR_OPTIONS_NOT_ALLOWED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | else |
| | |
| | | if (activeValues!= null) |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (isRequired()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | if ((numValues > 1) && (! isMultiValued())) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | activeValues = new ArrayList<String>(numValues); |
| | |
| | | if (activeValues == null) |
| | | { |
| | | // This is not OK. The value set must contain an active value. |
| | | int msgID = MSGID_CONFIG_ATTR_NO_ACTIVE_VALUE_SET; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (pendingValues == null) |
| | |
| | | { |
| | | attributeInfoList.add(new MBeanAttributeInfo(getName(), |
| | | JMX_TYPE_STRING_ARRAY, |
| | | getDescription(), true, true, |
| | | false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, true, false)); |
| | | } |
| | | else |
| | | { |
| | | attributeInfoList.add(new MBeanAttributeInfo(getName(), |
| | | String.class.getName(), |
| | | getDescription(), true, true, |
| | | false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, true, false)); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | attributeInfoList.add(new MBeanAttributeInfo(name, |
| | | JMX_TYPE_STRING_ARRAY, |
| | | getDescription(), true, |
| | | false, false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, false, false)); |
| | | } |
| | | else |
| | | { |
| | | attributeInfoList.add(new MBeanAttributeInfo(name, |
| | | String.class.getName(), |
| | | getDescription(), true, |
| | | false, false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, false, false)); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (isMultiValued()) |
| | | { |
| | | return new MBeanParameterInfo(getName(), JMX_TYPE_STRING_ARRAY, |
| | | getDescription()); |
| | | String.valueOf(getDescription())); |
| | | } |
| | | else |
| | | { |
| | | return new MBeanParameterInfo(getName(), String.class.getName(), |
| | | getDescription()); |
| | | String.valueOf(getDescription())); |
| | | } |
| | | } |
| | | |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_CONFIG_ATTR_INVALID_STRING_VALUE; |
| | | String message = getMessage(msgID, getName(), String.valueOf(value), |
| | | String.valueOf(e)); |
| | | throw new ConfigException(msgID, message, e); |
| | | Message message = ERR_CONFIG_ATTR_INVALID_STRING_VALUE.get( |
| | | getName(), String.valueOf(value), String.valueOf(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_STRING_INVALID_ARRAY_TYPE; |
| | | String message = getMessage(msgID, componentType); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_STRING_INVALID_ARRAY_TYPE.get( |
| | | String.valueOf(jmxAttribute), |
| | | String.valueOf(componentType)); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_STRING_INVALID_TYPE; |
| | | String message = getMessage(msgID, String.valueOf(value), getName(), |
| | | value.getClass().getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_STRING_INVALID_TYPE.get( |
| | | String.valueOf(value), getName(), value.getClass().getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |