KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 ObjectWeb Util CommandLine Package.
4 Copyright (C) 2003 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.Usage;
30 import org.objectweb.util.misc.lib.DefaultPrintableBase;
31
32
33 /**
34  * This is a default implementation of the
35  * org.objectweb.util.cmdline.api.Usage interface.
36  *
37  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
38  *
39  * @version 0.1
40  */

41
42 public class DefaultUsage
43      extends DefaultPrintableBase
44   implements Usage
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** The usage labels. */
53     protected String JavaDoc[] labels_;
54
55     /** The usage arguments. */
56     protected String JavaDoc[] arguments_;
57
58     /** The usage description. */
59     protected String JavaDoc[] description_;
60
61     /** To accept indifined number of arguments */
62     private boolean additionalArguments_;
63     
64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

70     /**
71      * The default constructor.
72      *
73      * It inits the Labels, Arguments, and Description properties
74      * with an empty string.
75      */

76     public
77     DefaultUsage()
78     {
79         this(new String JavaDoc[] { "" }, new String JavaDoc[0], null);
80     }
81
82     /**
83      * The constructor with the initial values for the Labels,
84      * Arguments, and Description properties.
85      *
86      * @param label The usage label.
87      * @param argument The usage argument.
88      * @param description The usage description.
89      */

90     public
91     DefaultUsage(String JavaDoc label,
92                  String JavaDoc argument,
93                  String JavaDoc[] description)
94     {
95         this(new String JavaDoc[] { label }, new String JavaDoc[] { argument }, description);
96     }
97
98     /**
99      * The constructor with the initial values for the Labels,
100      * Arguments, and Description properties.
101      *
102      * @param label The usage label.
103      * @param arguments The usage arguments.
104      * @param description The usage description.
105      */

106     public
107     DefaultUsage(String JavaDoc label,
108                  String JavaDoc[] arguments,
109                  String JavaDoc[] description)
110     {
111         this(new String JavaDoc[] { label }, arguments, description);
112     }
113
114     /**
115      * The constructor with the initial values for the Labels,
116      * Arguments, and Description properties.
117      *
118      * @param labels The usage labels.
119      * @param argument The usage argument.
120      * @param description The usage description.
121      */

122     public
123     DefaultUsage(String JavaDoc[] labels,
124                  String JavaDoc argument,
125                  String JavaDoc[] description)
126     {
127         this(labels, new String JavaDoc[] { argument }, description);
128     }
129
130     /**
131      * The constructor with the initial values for the Labels,
132      * Arguments, and Description properties.
133      *
134      * @param labels The usage labels.
135      * @param arguments The usage arguments.
136      * @param description The usage description.
137      */

138     public
139     DefaultUsage(String JavaDoc[] labels,
140                  String JavaDoc[] arguments,
141                  String JavaDoc[] description)
142     {
143         this(labels,arguments,false,description);
144     }
145
146     /**
147      * The constructor with the initial values for the Labels,
148      * Arguments, and Description properties.
149      *
150      * @param labels The usage labels.
151      * @param arguments The usage arguments.
152      * @param additional Additional arguments.
153      * @param description The usage description.
154      */

155     public
156     DefaultUsage(String JavaDoc[] labels,
157                  String JavaDoc[] arguments,
158                  boolean additional,
159                  String JavaDoc[] description) {
160         setLabels(labels);
161         setArguments(arguments);
162         setAdditionalArguments(additional);
163         setDescription(description);
164     }
165     
166     
167     // ==================================================================
168
//
169
// Internal methods.
170
//
171
// ==================================================================
172

173     // ==================================================================
174
//
175
// Internal methods for class org.objectweb.util.lib.DefaultPrintableBase
176
//
177
// ==================================================================
178

179     /**
180      * Appends internal state representation into the given string buffer.
181      *
182      * This method does not update the target object.
183      *
184      * @param sb The string buffer where pairs <name,value> are appended.
185      */

186     protected void
187     appendInternalState(StringBuffer JavaDoc sb)
188     {
189         append(sb, "labels", getLabels());
190         append(sb, "arguments", getArguments());
191         append(sb, "description", getDescription());
192     }
193
194     // ==================================================================
195
//
196
// Public methods for interface org.objectweb.util.cmdline.api.Usage
197
//
198
// ==================================================================
199

200     /**
201      * Gets the usage labels.
202      *
203      * @return The usage labels.
204      */

205     public String JavaDoc[]
206     getLabels()
207     {
208         return labels_;
209     }
210
211     /**
212      * Sets the usage labels.
213      *
214      * @param labels The usage labels.
215      */

216     public void
217     setLabels(String JavaDoc[] labels)
218     {
219         labels_ = labels;
220     }
221
222     /**
223      * Gets the usage arguments.
224      *
225      * @return The usage arguments.
226      */

227     public String JavaDoc[]
228     getArguments()
229     {
230         return arguments_;
231     }
232
233     /**
234      * Sets the usage arguments.
235      *
236      * @param arguments The usage arguments.
237      */

238     public void
239     setArguments(String JavaDoc[] arguments)
240     {
241         arguments_ = arguments;
242     }
243
244     /**
245      * Gets the additional arguments flag.
246      *
247      * @return True if additional (undefined) arguments are allowed.
248      */

249     public boolean
250     getAdditionalArguments() {
251         return additionalArguments_;
252     }
253     
254     /**
255      * Sets the additional arguments flag.
256      *
257      * @param args the additional arguments flag (true for allowing).
258      */

259     public void
260     setAdditionalArguments(boolean additional) {
261         additionalArguments_ = additional;
262     }
263     
264     /**
265      * Gets the usage description.
266      *
267      * @return The usage description.
268      */

269     public String JavaDoc[]
270     getDescription()
271     {
272         return description_;
273     }
274
275     /**
276      * Sets the usage description.
277      *
278      * @param description The usage description.
279      */

280     public void
281     setDescription(String JavaDoc[] description)
282     {
283         description_ = description;
284     }
285
286     // ==================================================================
287
//
288
// Other public methods.
289
//
290
// ==================================================================
291
}
292
Popular Tags