KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > cmdline > lib > DefaultOptionArgument


1 /*====================================================================
2
3 ObjectWeb Util CommandLine Package.
4 Copyright (C) 2002 INRIA & USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.cmdline.lib;
28
29 import org.objectweb.util.cmdline.api.OptionArgument ;
30
31 /**
32  * This is a default implementation of the
33  * org.objectweb.util.cmdline.api.OptionArgument interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  *
37  * @version 0.1
38  */

39
40 public class DefaultOptionArgument
41      extends DefaultOptionBase
42   implements OptionArgument
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /** The option argument. */
51     protected String JavaDoc argument_;
52
53     // ==================================================================
54
//
55
// Constructors.
56
//
57
// ==================================================================
58

59     /**
60      * The default constructor.
61      *
62      * It inits the Labels, Arguments, and Description usage properties
63      * with an empty string.
64      */

65     public
66     DefaultOptionArgument()
67     {
68         this("", "", (String JavaDoc[])null, null);
69     }
70
71     /**
72      * The constructor with the initial values for the Labels,
73      * Arguments, and Description usage properties.
74      *
75      * @param label The usage label.
76      * @param arguments The usage arguments.
77      * @param description The usage description.
78      * @param flag The initial flag value.
79      */

80     public
81     DefaultOptionArgument(String JavaDoc label,
82                           String JavaDoc arguments,
83                           String JavaDoc description,
84                           String JavaDoc argument)
85     {
86         this(new String JavaDoc[] { label }, arguments,
87              new String JavaDoc[] { description }, argument);
88     }
89
90     /**
91      * The constructor with the initial values for the Labels,
92      * Arguments, and Description usage properties.
93      *
94      * @param labels The usage labels.
95      * @param arguments The usage arguments.
96      * @param description The usage description.
97      * @param flag The initial flag value.
98      */

99     public
100     DefaultOptionArgument(String JavaDoc[] labels,
101                           String JavaDoc arguments,
102                           String JavaDoc description,
103                           String JavaDoc argument)
104     {
105         this(labels, arguments, new String JavaDoc[] { description }, argument);
106     }
107
108     /**
109      * The constructor with the initial values for the Labels,
110      * Arguments, and Description usage properties.
111      *
112      * @param label The usage label.
113      * @param arguments The usage arguments.
114      * @param description The usage description.
115      * @param flag The initial flag value.
116      */

117     public
118     DefaultOptionArgument(String JavaDoc label,
119                           String JavaDoc arguments,
120                           String JavaDoc[] description,
121                           String JavaDoc argument)
122     {
123         this(new String JavaDoc[] { label }, arguments, description, argument);
124     }
125
126     /**
127      * The constructor with the initial values for the Labels,
128      * Arguments, and Description usage properties.
129      *
130      * @param labels The usage labels.
131      * @param arguments The usage arguments.
132      * @param description The usage description.
133      * @param flag The initial flag value.
134      */

135     public
136     DefaultOptionArgument(String JavaDoc[] labels,
137                           String JavaDoc arguments,
138                           String JavaDoc[] description,
139                           String JavaDoc argument)
140     {
141         super(labels, arguments, description);
142         setArgument(argument);
143     }
144
145     // ==================================================================
146
//
147
// Internal methods.
148
//
149
// ==================================================================
150

151     // ==================================================================
152
//
153
// Internal methods for class org.objectweb.util.lib.DefaultPrintableBase
154
//
155
// ==================================================================
156

157     /**
158      * Appends internal state representation into the given string buffer.
159      *
160      * This method does not update the target object.
161      *
162      * @param sb The string buffer where pairs <name,value> are appended.
163      */

164     protected void
165     appendInternalState(StringBuffer JavaDoc sb)
166     {
167         super.appendInternalState(sb);
168         append(sb, "argument", getArgument());
169     }
170
171     // ==================================================================
172
//
173
// Public methods for interface org.objectweb.util.cmdline.api.Option
174
//
175
// ==================================================================
176

177     /**
178      * Consumes command line arguments from an iterator.
179      *
180      * @param iterator The command line argument iterator.
181      */

182     public void
183     consume(org.objectweb.util.cmdline.api.Iterator iterator)
184     {
185         checkAlreadySet(iterator);
186         setArgument(consumeArgument(iterator));
187     }
188
189     // ==================================================================
190
//
191
// Public methods for interface org.objectweb.util.cmdline.api.OptionArgument
192
//
193
// ==================================================================
194

195     /**
196      * Gets the command line option argument.
197      *
198      * @return The command line option argument.
199      */

200     public String JavaDoc
201     getArgument()
202     {
203         return argument_;
204     }
205
206     /**
207      * Sets the command line option argument.
208      *
209      * @param argument The command line option argument.
210      */

211     public void
212     setArgument(String JavaDoc argument)
213     {
214         argument_ = argument;
215     }
216
217     // ==================================================================
218
//
219
// Other public methods.
220
//
221
// ==================================================================
222
}
223
Popular Tags