KickJava   Java API By Example, From Geeks To Geeks.

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


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): Romain Rouvoy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

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

43
44 public class DefaultRegExOptionArgument
45      extends DefaultOptionArgument
46   implements RegExOptionArgument
47 {
48     /** The checking pattern */
49     protected Pattern pattern;
50
51     
52     // ==================================================================
53
//
54
// Constructors.
55
//
56
// ==================================================================
57

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

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

79     public
80     DefaultRegExOptionArgument(String JavaDoc label,
81                                String JavaDoc arguments,
82                                String JavaDoc description,
83                                String JavaDoc argument,
84                                String JavaDoc pattern)
85     {
86         this(new String JavaDoc[] { label }, arguments,
87              new String JavaDoc[] { description }, argument, pattern);
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     DefaultRegExOptionArgument(String JavaDoc[] labels,
101                                String JavaDoc arguments,
102                                String JavaDoc description,
103                                String JavaDoc argument,
104                                String JavaDoc pattern)
105     {
106         this(labels, arguments, new String JavaDoc[]{description}, argument, pattern);
107     }
108
109     /**
110      * The constructor with the initial values for the Labels,
111      * Arguments, and Description usage properties.
112      *
113      * @param label The usage label.
114      * @param arguments The usage arguments.
115      * @param description The usage description.
116      * @param flag The initial flag value.
117      */

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

137     public
138     DefaultRegExOptionArgument(String JavaDoc[] labels,
139                                String JavaDoc arguments,
140                                String JavaDoc[] description,
141                                String JavaDoc argument,
142                                String JavaDoc pattern)
143     {
144         super(labels, arguments, description,argument);
145         setPattern(new Pattern(pattern));
146     }
147
148
149
150
151     // ==================================================================
152
//
153
// Public methods for interface org.objectweb.util.cmdline.api.Option
154
//
155
// ==================================================================
156

157     /**
158      * Consumes command line arguments from an iterator.
159      *
160      * @param iterator The command line argument iterator.
161      */

162     public void
163     consume(org.objectweb.util.cmdline.api.Iterator iterator)
164     {
165         checkAlreadySet(iterator);
166         String JavaDoc arg = consumeArgument(iterator);
167         if (getPattern().matches(arg))
168             setArgument(arg);
169     }
170
171     // ==================================================================
172
//
173
// Public methods for interface org.objectweb.util.cmdline.api.OptionRegExArgument
174
//
175
// ==================================================================
176

177     /**
178      * Gets the checking pattern
179      *
180      * @return The pattern used to check the CommandLine Argument
181      */

182     public Pattern
183     getPattern() { return pattern; }
184
185     /**
186      * Sets the checking pattern
187      *
188      * @param pattern - the pattern used to check the CommandLine Argument.
189      */

190     public void
191     setPattern(Pattern pattern) { this.pattern = pattern; }
192 }
193
Popular Tags