KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-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): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.cmdline.lib;
28
29 // Package dependencies.
30
import java.util.List JavaDoc;
31
32
33 /**
34  * This is a default implementation of the
35  * org.objectweb.util.cmdline.api.OptionArguments interface.
36  * It specifies an option that can be repeated several times.
37  * Each option argument will be saved in a list.
38  *
39  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
40  *
41  * @version 0.1
42  */

43 public class DefaultOptionArguments
44      extends DefaultOptionBase
45   implements org.objectweb.util.cmdline.api.OptionArguments
46 {
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ==================================================================
52

53     /** The option arguments. */
54     protected List JavaDoc arguments_;
55
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /**
63      * The default constructor.
64      *
65      * It inits the Labels, Arguments, and Description usage properties
66      * with an empty string.
67      */

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

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

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

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

131     public
132     DefaultOptionArguments(String JavaDoc[] labels,
133                            String JavaDoc arguments,
134                            String JavaDoc[] description)
135     {
136         super(labels, arguments, description);
137
138         // Init Internal State
139
arguments_ = new java.util.ArrayList JavaDoc();
140     }
141
142     // ==================================================================
143
//
144
// Internal methods.
145
//
146
// ==================================================================
147

148     // ==================================================================
149
//
150
// Internal methods for class org.objectweb.util.lib.DefaultPrintableBase
151
//
152
// ==================================================================
153

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

161     protected void
162     appendInternalState(StringBuffer JavaDoc sb)
163     {
164         super.appendInternalState(sb);
165     }
166
167     // ==================================================================
168
//
169
// Public methods for interface org.objectweb.util.cmdline.api.Option
170
//
171
// ==================================================================
172

173     /**
174      * Consumes command line arguments from an iterator.
175      *
176      * @param iterator The command line argument iterator.
177      */

178     public void
179     consume(org.objectweb.util.cmdline.api.Iterator iterator)
180     {
181         addOptionValue(consumeArgument(iterator));
182     }
183
184     // ==================================================================
185
//
186
// Public methods for interface org.objectweb.util.cmdline.api.OptionArguments
187
//
188
// ==================================================================
189

190     /**
191      * Gets the command line option arguments.
192      *
193      * @return The command line option arguments.
194      */

195     public String JavaDoc[]
196     getOptionValues()
197     {
198         return (String JavaDoc[]) arguments_.toArray(new String JavaDoc[0]);
199     }
200
201     /**
202      * Add the command line option argument.
203      *
204      * @param argument - The command line option argument.
205      */

206     public void
207     addOptionValue(String JavaDoc argument)
208     {
209         arguments_.add(argument);
210     }
211
212     // ==================================================================
213
//
214
// Other public methods.
215
//
216
// ==================================================================
217
}
218
Popular Tags