KickJava   Java API By Example, From Geeks To Geeks.

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


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.OptionFlag ;
30
31 /**
32  * This is a default implementation of the
33  * org.objectweb.util.cmdline.api.OptionFlag interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  *
37  * @version 0.1
38  */

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

50     /** The option flag. */
51     protected boolean flag_;
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     DefaultOptionFlag()
67     {
68         this("", (String JavaDoc[])null, false);
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 description The usage description.
77      * @param flag The initial flag value.
78      */

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

95     public
96     DefaultOptionFlag(String JavaDoc[] labels,
97                       String JavaDoc description,
98                       boolean flag)
99     {
100         this(labels, new String JavaDoc[] { description }, flag);
101     }
102
103     /**
104      * The constructor with the initial values for the Labels,
105      * Arguments, and Description usage properties.
106      *
107      * @param label The usage label.
108      * @param description The usage description.
109      * @param flag The initial flag value.
110      */

111     public
112     DefaultOptionFlag(String JavaDoc label,
113                       String JavaDoc[] description,
114                       boolean flag)
115     {
116         this(new String JavaDoc[] { label }, description, flag);
117     }
118
119     /**
120      * The constructor with the initial values for the Labels,
121      * Arguments, and Description usage properties.
122      *
123      * @param labels The usage labels.
124      * @param description The usage description.
125      * @param flag The initial flag value.
126      */

127     public
128     DefaultOptionFlag(String JavaDoc[] labels,
129                       String JavaDoc[] description,
130                       boolean flag)
131     {
132         super(labels, new String JavaDoc[0], description);
133         setFlag(flag);
134     }
135
136     // ==================================================================
137
//
138
// Internal methods.
139
//
140
// ==================================================================
141

142     // ==================================================================
143
//
144
// Internal methods for class org.objectweb.util.lib.DefaultPrintableBase
145
//
146
// ==================================================================
147

148     /**
149      * Appends internal state representation into the given string buffer.
150      *
151      * This method does not update the target object.
152      *
153      * @param sb The string buffer where pairs <name,value> are appended.
154      */

155     protected void
156     appendInternalState(StringBuffer JavaDoc sb)
157     {
158         super.appendInternalState(sb);
159         append(sb, "flag", getFlag());
160     }
161
162     // ==================================================================
163
//
164
// Public methods for interface org.objectweb.util.cmdline.api.Option
165
//
166
// ==================================================================
167

168     /**
169      * Consumes command line arguments from an iterator.
170      *
171      * @param iterator The command line argument iterator.
172      */

173     public void
174     consume(org.objectweb.util.cmdline.api.Iterator iterator)
175     {
176         checkAlreadySet(iterator);
177         flag_ = true;
178     }
179
180     // ==================================================================
181
//
182
// Public methods for interface org.objectweb.util.cmdline.api.OptionFlag
183
//
184
// ==================================================================
185

186     /**
187      * Gets the flag status.
188      *
189      * @return The flag status.
190      */

191     public boolean
192     getFlag()
193     {
194         return flag_;
195     }
196
197     /**
198      * Sets the flag status.
199      *
200      * @param flag The flag status.
201      */

202     public void
203     setFlag(boolean flag)
204     {
205         flag_ = flag;
206     }
207
208     // ==================================================================
209
//
210
// Other public methods.
211
//
212
// ==================================================================
213
}
214
Popular Tags