| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.util.args; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.messages.UtilityMessages.*; |
| | | |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import org.opends.messages.MessageBuilder; |
| | | |
| | | |
| | | /** |
| | |
| | | * be displayed in usage information, or |
| | | * <CODE>null</CODE> if this argument does not |
| | | * require a value. |
| | | * @param descriptionID The unique ID of the description for this |
| | | * @param description Message for the description of this |
| | | * argument. |
| | | * @param descriptionArgs The arguments that are to be used when generating |
| | | * the description for this argument. |
| | | * |
| | | * @throws ArgumentException If there is a problem with any of the |
| | | * parameters used to create this argument. |
| | |
| | | public IntegerArgument(String name, Character shortIdentifier, |
| | | String longIdentifier, boolean isRequired, |
| | | boolean needsValue, String valuePlaceholder, |
| | | int descriptionID, Object... descriptionArgs) |
| | | Message description) |
| | | throws ArgumentException |
| | | { |
| | | super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue, |
| | | valuePlaceholder, null, null, descriptionID, descriptionArgs); |
| | | valuePlaceholder, null, null, description); |
| | | |
| | | hasLowerBound = false; |
| | | hasUpperBound = false; |
| | |
| | | * enforced for values of this argument. |
| | | * @param upperBound The upper bound that should be enforced for |
| | | * values of this argument. |
| | | * @param descriptionID The unique ID of the description for this |
| | | * @param description Message for the description of this |
| | | * argument. |
| | | * @param descriptionArgs The arguments that are to be used when generating |
| | | * the description for this argument. |
| | | * |
| | | * @throws ArgumentException If there is a problem with any of the |
| | | * parameters used to create this argument. |
| | |
| | | boolean needsValue, String valuePlaceholder, |
| | | boolean hasLowerBound, int lowerBound, |
| | | boolean hasUpperBound, int upperBound, |
| | | int descriptionID, Object... descriptionArgs) |
| | | Message description) |
| | | throws ArgumentException |
| | | { |
| | | super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue, |
| | | valuePlaceholder, null, null, descriptionID, descriptionArgs); |
| | | valuePlaceholder, null, null, description); |
| | | |
| | | this.hasLowerBound = hasLowerBound; |
| | | this.hasUpperBound = hasUpperBound; |
| | |
| | | |
| | | if (hasLowerBound && hasUpperBound && (lowerBound > upperBound)) |
| | | { |
| | | int msgID = MSGID_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND; |
| | | String message = getMessage(msgID, name, lowerBound, upperBound); |
| | | throw new ArgumentException(msgID, message); |
| | | Message message = ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND.get( |
| | | name, lowerBound, upperBound); |
| | | throw new ArgumentException(message); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param propertyName The name of the property in a property file that |
| | | * may be used to override the default value but |
| | | * will be overridden by a command-line argument. |
| | | * @param descriptionID The unique ID of the description for this |
| | | * @param description Message for the description of this |
| | | * argument. |
| | | * @param descriptionArgs The arguments that are to be used when generating |
| | | * the description for this argument. |
| | | * |
| | | * @throws ArgumentException If there is a problem with any of the |
| | | * parameters used to create this argument. |
| | |
| | | String longIdentifier, boolean isRequired, |
| | | boolean isMultiValued, boolean needsValue, |
| | | String valuePlaceholder, int defaultValue, |
| | | String propertyName, int descriptionID, |
| | | Object... descriptionArgs) |
| | | String propertyName, |
| | | Message description) |
| | | throws ArgumentException |
| | | { |
| | | super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, |
| | | needsValue, valuePlaceholder, String.valueOf(defaultValue), |
| | | propertyName, descriptionID, descriptionArgs); |
| | | propertyName, description); |
| | | |
| | | hasLowerBound = false; |
| | | hasUpperBound = false; |
| | |
| | | * enforced for values of this argument. |
| | | * @param upperBound The upper bound that should be enforced for |
| | | * values of this argument. |
| | | * @param descriptionID The unique ID of the description for this |
| | | * @param description Message for the description of this |
| | | * argument. |
| | | * @param descriptionArgs The arguments that are to be used when generating |
| | | * the description for this argument. |
| | | * |
| | | * @throws ArgumentException If there is a problem with any of the |
| | | * parameters used to create this argument. |
| | |
| | | String valuePlaceholder, int defaultValue, |
| | | String propertyName, boolean hasLowerBound, |
| | | int lowerBound, boolean hasUpperBound, int upperBound, |
| | | int descriptionID, Object... descriptionArgs) |
| | | Message description) |
| | | throws ArgumentException |
| | | { |
| | | super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued, |
| | | needsValue, valuePlaceholder, String.valueOf(defaultValue), |
| | | propertyName, descriptionID, descriptionArgs); |
| | | propertyName, description); |
| | | |
| | | this.hasLowerBound = hasLowerBound; |
| | | this.hasUpperBound = hasUpperBound; |
| | |
| | | |
| | | if (hasLowerBound && hasUpperBound && (lowerBound > upperBound)) |
| | | { |
| | | int msgID = MSGID_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND; |
| | | String message = getMessage(msgID, name, lowerBound, upperBound); |
| | | throw new ArgumentException(msgID, message); |
| | | Message message = ERR_INTARG_LOWER_BOUND_ABOVE_UPPER_BOUND.get( |
| | | name, lowerBound, upperBound); |
| | | throw new ArgumentException(message); |
| | | } |
| | | } |
| | | |
| | |
| | | * <CODE>false</CODE> if it is not. |
| | | */ |
| | | public boolean valueIsAcceptable(String valueString, |
| | | StringBuilder invalidReason) |
| | | MessageBuilder invalidReason) |
| | | { |
| | | // First, the value must be decodable as an integer. |
| | | int intValue; |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_ARG_CANNOT_DECODE_AS_INT; |
| | | invalidReason.append(getMessage(msgID, valueString, getName())); |
| | | invalidReason.append(ERR_ARG_CANNOT_DECODE_AS_INT.get( |
| | | valueString, getName())); |
| | | return false; |
| | | } |
| | | |
| | |
| | | // to it. |
| | | if (hasLowerBound && (intValue < lowerBound)) |
| | | { |
| | | int msgID = MSGID_INTARG_VALUE_BELOW_LOWER_BOUND; |
| | | invalidReason.append(getMessage(msgID, getName(), intValue, lowerBound)); |
| | | invalidReason.append(ERR_INTARG_VALUE_BELOW_LOWER_BOUND.get( |
| | | getName(), intValue, lowerBound)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | // it. |
| | | if (hasUpperBound && (intValue > upperBound)) |
| | | { |
| | | int msgID = MSGID_INTARG_VALUE_ABOVE_UPPER_BOUND; |
| | | invalidReason.append(getMessage(msgID, getName(), intValue, upperBound)); |
| | | |
| | | invalidReason.append(ERR_INTARG_VALUE_ABOVE_UPPER_BOUND.get( |
| | | getName(), intValue, upperBound)); |
| | | return false; |
| | | } |
| | | |