KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > cpp > lib > PreprocessorOptionBase


1 /*====================================================================
2
3 ObjectWeb Util Preprocessor Package.
4 Copyright (C) 2004 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 $Id: PreprocessorOptionBase.java,v 1.1 2004/02/05 20:29:57 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.cpp.lib;
30
31 import org.objectweb.util.cmdline.lib.DefaultOptionBase;
32 import org.objectweb.util.cpp.api.Preprocessor;
33 import org.objectweb.util.cpp.api.PreprocessorOption;
34
35 /**
36  * Base abstract implementation for Preprocessor Option objects.
37  *
38  * Subclasses must implement the consume method.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
41  *
42  * @version 0.1
43  */

44
45 public abstract class PreprocessorOptionBase
46               extends DefaultOptionBase
47            implements PreprocessorOption
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     /** The preprocessor. */
56     private Preprocessor preprocessor_;
57
58     // ==================================================================
59
//
60
// Constructors.
61
//
62
// ==================================================================
63

64     /** The default constructor. */
65     public PreprocessorOptionBase() {
66         // Calls the DefaultOptionBase constructor.
67
super();
68
69         setArguments(new String JavaDoc[0]);
70         setMandatory(false);
71
72         // Inits internal state.
73
preprocessor_ = null;
74     }
75
76     // ==================================================================
77
//
78
// Internal methods.
79
//
80
// ==================================================================
81

82     // ==================================================================
83
//
84
// Public methods for interface org.objectweb.util.cmdline.api.Option
85
//
86
// ==================================================================
87

88     /**
89      * Checks the current command line argument.
90      *
91      * @param current The current command line argument.
92      *
93      * @return true if the option accepts this argument.
94      */

95     public boolean check(String JavaDoc current) {
96       String JavaDoc baseOptionLabel = getBaseOptionLabel();
97
98         if (!current.startsWith(baseOptionLabel)) {
99             return false;
100         }
101
102         consumeOption(current.substring(baseOptionLabel.length()));
103         return true;
104     }
105
106     /**
107      * Consumes command line arguments from an iterator.
108      *
109      * @param iterator The command line argument iterator.
110      */

111     public void
112     consume(org.objectweb.util.cmdline.api.Iterator iterator) {
113         // Nothing to do.
114
}
115
116     // ==================================================================
117
//
118
// Public methods for org.objectweb.util.cpp.api.PreprocessorHolder
119
//
120
// ==================================================================
121

122     /**
123      * Obtains the associated preprocessor.
124      *
125      * @return The associated preprocessor.
126      */

127     public Preprocessor getPreprocessor() {
128         return preprocessor_;
129     }
130
131     /**
132      * Sets the associated preprocessor.
133      *
134      * @param preprocessor The associated preprocessor.
135      */

136     public void setPreprocessor(Preprocessor preprocessor) {
137         preprocessor_ = preprocessor;
138     }
139
140     // ==================================================================
141
//
142
// Public methods for org.objectweb.util.cpp.api.PreprocessorOption
143
//
144
// ==================================================================
145

146     /**
147      * Gets the base option label.
148      *
149      * @return The base option label.
150      */

151     public abstract String JavaDoc getBaseOptionLabel();
152
153     /**
154      * Consumes the option.
155      *
156      * @param current The option value.
157      */

158     public abstract void consumeOption(String JavaDoc current);
159
160     // ==================================================================
161
//
162
// Other public methods.
163
//
164
// ==================================================================
165
}
166
Popular Tags