001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.util.args;
028 import org.opends.messages.Message;
029
030 import org.opends.messages.MessageBuilder;
031
032
033 /**
034 * This class defines an argument type that will accept any string value.
035 */
036 public class StringArgument
037 extends Argument
038 {
039 /**
040 * Creates a new string argument with the provided information.
041 *
042 * @param name The generic name that should be used to refer to
043 * this argument.
044 * @param shortIdentifier The single-character identifier for this
045 * argument, or <CODE>null</CODE> if there is none.
046 * @param longIdentifier The long identifier for this argument, or
047 * <CODE>null</CODE> if there is none.
048 * @param isRequired Indicates whether this argument must be specified
049 * on the command line.
050 * @param needsValue Indicates whether this argument requires a value.
051 * @param valuePlaceholder The placeholder for the argument value that will
052 * be displayed in usage information, or
053 * <CODE>null</CODE> if this argument does not
054 * require a value.
055 * @param description Message for the description of this
056 * argument.
057 *
058 * @throws ArgumentException If there is a problem with any of the
059 * parameters used to create this argument.
060 */
061 public StringArgument(String name, Character shortIdentifier,
062 String longIdentifier, boolean isRequired,
063 boolean needsValue, Message valuePlaceholder,
064 Message description)
065 throws ArgumentException
066 {
067 super(name, shortIdentifier, longIdentifier, isRequired, false, needsValue,
068 valuePlaceholder, null, null, description);
069 }
070
071
072
073 /**
074 * Creates a new string argument with the provided information.
075 *
076 * @param name The generic name that should be used to refer to
077 * this argument.
078 * @param shortIdentifier The single-character identifier for this
079 * argument, or <CODE>null</CODE> if there is none.
080 * @param longIdentifier The long identifier for this argument, or
081 * <CODE>null</CODE> if there is none.
082 * @param isRequired Indicates whether this argument must be specified
083 * on the command line.
084 * @param isMultiValued Indicates whether this argument may be specified
085 * more than once to provide multiple values.
086 * @param needsValue Indicates whether this argument requires a value.
087 * @param valuePlaceholder The placeholder for the argument value that will
088 * be displayed in usage information, or
089 * <CODE>null</CODE> if this argument does not
090 * require a value.
091 * @param defaultValue The default value that should be used for this
092 * argument if none is provided in a properties file
093 * or on the command line. This may be
094 * <CODE>null</CODE> if there is no generic default.
095 * @param propertyName The name of the property in a property file that
096 * may be used to override the default value but
097 * will be overridden by a command-line argument.
098 * @param description Message for the description of this
099 * argument.
100 *
101 * @throws ArgumentException If there is a problem with any of the
102 * parameters used to create this argument.
103 */
104 public StringArgument(String name, Character shortIdentifier,
105 String longIdentifier, boolean isRequired,
106 boolean isMultiValued, boolean needsValue,
107 Message valuePlaceholder, String defaultValue,
108 String propertyName, Message description)
109 throws ArgumentException
110 {
111 super(name, shortIdentifier, longIdentifier, isRequired, isMultiValued,
112 needsValue, valuePlaceholder, defaultValue, propertyName,
113 description);
114 }
115
116
117
118 /**
119 * Indicates whether the provided value is acceptable for use in this
120 * argument.
121 *
122 * @param valueString The value for which to make the determination.
123 * @param invalidReason A buffer into which the invalid reason may be
124 * written if the value is not acceptable.
125 *
126 * @return <CODE>true</CODE> if the value is acceptable, or
127 * <CODE>false</CODE> if it is not.
128 */
129 public boolean valueIsAcceptable(String valueString,
130 MessageBuilder invalidReason)
131 {
132 // All values will be acceptable for this argument.
133 return true;
134 }
135 }
136