if (a.hasOption(OPTION_PENDING_VALUES))
{
if (pendingUnit != null)
{
// We cannot have multiple pending value sets.
Message message =
ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName());
throw new ConfigException(message);
}
if (a.isEmpty())
{
// This is illegal -- it must have a value.
Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
throw new ConfigException(message);
}
else
{
Iterator<AttributeValue> iterator = a.iterator();
String valueString = iterator.next().getValue().toString();
if (iterator.hasNext())
{
// This is illegal -- the attribute is single-valued.
Message message =
ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
throw new ConfigException(message);
}
try
{
int spacePos = valueString.indexOf(' ');
pendingIntValue =
Long.parseLong(valueString.substring(0, spacePos));
pendingUnit = valueString.substring(spacePos+1).trim();
}
catch (Exception e)
{
Message message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.
get(valueString, a.getName(), String.valueOf(e));
throw new ConfigException(message);
}
// Get the unit and use it to determine the corresponding
// multiplier.
if (! units.containsKey(pendingUnit))
{
Message message =
ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, a.getName());
throw new ConfigException(message);
}
double multiplier = units.get(activeUnit);
pendingCalculatedValue = (long) (multiplier * pendingIntValue);
// Check the bounds set for this attribute.
if (hasLowerBound && (pendingCalculatedValue < lowerBound))
{
Message message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
a.getName(), pendingCalculatedValue, lowerBound);
throw new ConfigException(message);
}
if (hasUpperBound && (pendingCalculatedValue > upperBound))
{
Message message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
a.getName(), pendingCalculatedValue, upperBound);
throw new ConfigException(message);
}
}
}
else
{
// This is illegal -- only the pending option is allowed for
// configuration attributes.
Message message =
ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName());
throw new ConfigException(message);
}
}
else
{
// This must be the active value.
if (activeUnit != null)
{
// We cannot have multiple active value sets.
Message message =
ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName());
throw new ConfigException(message);
}
if (a.isEmpty())
{
// This is illegal -- it must have a value.
Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName());
throw new ConfigException(message);
}
else
{
Iterator<AttributeValue> iterator = a.iterator();
String valueString = iterator.next().getValue().toString();
if (iterator.hasNext())
{
// This is illegal -- the attribute is single-valued.
Message message =
ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName());
throw new ConfigException(message);
}
try
{
int spacePos = valueString.indexOf(' ');
activeIntValue =
Long.parseLong(valueString.substring(0, spacePos));
activeUnit = valueString.substring(spacePos+1).trim();
}
catch (Exception e)
{
Message message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get(
valueString, a.getName(), String.valueOf(e));
throw new ConfigException(message);
}
// Get the unit and use it to determine the corresponding multiplier.
if (! units.containsKey(activeUnit))
{
Message message =
ERR_CONFIG_ATTR_INVALID_UNIT.get(activeUnit, a.getName());
throw new ConfigException(message);
}
double multiplier = units.get(activeUnit);
activeCalculatedValue = (long) (multiplier * activeIntValue);
// Check the bounds set for this attribute.
if (hasLowerBound && (activeCalculatedValue < lowerBound))
{
Message message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(
a.getName(), activeCalculatedValue, lowerBound);
throw new ConfigException(message);
}
if (hasUpperBound && (activeCalculatedValue > upperBound))
{
Message message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(
a.getName(), activeCalculatedValue, upperBound);
throw new ConfigException(message);
}
}
}
}
if (activeUnit == null)
{
// This is not OK. The value set must contain an active value.
Message message = ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName());
throw new ConfigException(message);
}
if (pendingUnit == null)
{