| | |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | |
| | | import com.sun.opends.sdk.util.Message; |
| | | import com.sun.opends.sdk.util.MessageBuilder; |
| | | import org.opends.sdk.LocalizableMessage; |
| | | import org.opends.sdk.LocalizableMessageBuilder; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | private Character shortIdentifier; |
| | | |
| | | // The unique ID of the description for this argument. |
| | | private Message description; |
| | | private LocalizableMessage description; |
| | | |
| | | // The set of values for this argument. |
| | | private LinkedList<String> values; |
| | |
| | | // The value placeholder for this argument, which will be used in |
| | | // usage |
| | | // information. |
| | | private Message valuePlaceholder; |
| | | private LocalizableMessage valuePlaceholder; |
| | | |
| | | // Indicates whether this argument was provided in the set of |
| | | // properties |
| | |
| | | * used to override the default value but will be overridden |
| | | * by a command-line argument. |
| | | * @param description |
| | | * Message for the description of this argument. |
| | | * LocalizableMessage for the description of this argument. |
| | | * @throws ArgumentException |
| | | * If there is a problem with any of the parameters used to |
| | | * create this argument. |
| | | */ |
| | | protected Argument(String name, Character shortIdentifier, |
| | | String longIdentifier, boolean isRequired, boolean isMultiValued, |
| | | boolean needsValue, Message valuePlaceholder, |
| | | String defaultValue, String propertyName, Message description) |
| | | boolean needsValue, LocalizableMessage valuePlaceholder, |
| | | String defaultValue, String propertyName, LocalizableMessage description) |
| | | throws ArgumentException |
| | | { |
| | | this.name = name; |
| | |
| | | |
| | | if ((shortIdentifier == null) && (longIdentifier == null)) |
| | | { |
| | | Message message = ERR_ARG_NO_IDENTIFIER.get(name); |
| | | LocalizableMessage message = ERR_ARG_NO_IDENTIFIER.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | | if (needsValue && (valuePlaceholder == null)) |
| | | { |
| | | Message message = ERR_ARG_NO_VALUE_PLACEHOLDER.get(name); |
| | | LocalizableMessage message = ERR_ARG_NO_VALUE_PLACEHOLDER.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | |
| | | * argument in the generated usage information, or |
| | | * <CODE>null</CODE> if there is none. |
| | | */ |
| | | public Message getValuePlaceholder() |
| | | public LocalizableMessage getValuePlaceholder() |
| | | { |
| | | return valuePlaceholder; |
| | | } |
| | |
| | | * The value placeholder that will be displayed for this |
| | | * argument in the generated usage information. |
| | | */ |
| | | public void setValuePlaceholder(Message valuePlaceholder) |
| | | public void setValuePlaceholder(LocalizableMessage valuePlaceholder) |
| | | { |
| | | this.valuePlaceholder = valuePlaceholder; |
| | | } |
| | |
| | | * |
| | | * @return The human-readable description for this argument. |
| | | */ |
| | | public Message getDescription() |
| | | public LocalizableMessage getDescription() |
| | | { |
| | | return description != null ? description : Message.EMPTY; |
| | | return description != null ? description : LocalizableMessage.EMPTY; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (values.isEmpty()) |
| | | { |
| | | Message message = ERR_ARG_NO_INT_VALUE.get(name); |
| | | LocalizableMessage message = ERR_ARG_NO_INT_VALUE.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name); |
| | | throw new ArgumentException(message, e); |
| | | } |
| | | |
| | | if (iterator.hasNext()) |
| | | { |
| | | Message message = ERR_ARG_INT_MULTIPLE_VALUES.get(name); |
| | | LocalizableMessage message = ERR_ARG_INT_MULTIPLE_VALUES.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | else |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name); |
| | | throw new ArgumentException(message, e); |
| | | } |
| | |
| | | { |
| | | if (values.isEmpty()) |
| | | { |
| | | Message message = ERR_ARG_NO_INT_VALUE.get(name); |
| | | LocalizableMessage message = ERR_ARG_NO_INT_VALUE.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name); |
| | | throw new ArgumentException(message, e); |
| | | } |
| | | |
| | | if (iterator.hasNext()) |
| | | { |
| | | Message message = ERR_ARG_INT_MULTIPLE_VALUES.get(name); |
| | | LocalizableMessage message = ERR_ARG_INT_MULTIPLE_VALUES.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | else |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_ARG_CANNOT_DECODE_AS_INT.get(valueString, name); |
| | | throw new ArgumentException(message, e); |
| | | } |
| | |
| | | { |
| | | if (values.isEmpty()) |
| | | { |
| | | Message message = ERR_ARG_NO_BOOLEAN_VALUE.get(name); |
| | | LocalizableMessage message = ERR_ARG_NO_BOOLEAN_VALUE.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | Message message = |
| | | LocalizableMessage message = |
| | | ERR_ARG_CANNOT_DECODE_AS_BOOLEAN.get(valueString, name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | |
| | | if (iterator.hasNext()) |
| | | { |
| | | Message message = ERR_ARG_BOOLEAN_MULTIPLE_VALUES.get(name); |
| | | LocalizableMessage message = ERR_ARG_BOOLEAN_MULTIPLE_VALUES.get(name); |
| | | throw new ArgumentException(message); |
| | | } |
| | | else |
| | |
| | | * <CODE>false</CODE> if it is not. |
| | | */ |
| | | public abstract boolean valueIsAcceptable(String valueString, |
| | | MessageBuilder invalidReason); |
| | | LocalizableMessageBuilder invalidReason); |
| | | |
| | | |
| | | |