KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > packaging > cmdline > OptionBase


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@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 Contreras
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.packaging.cmdline;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.lib.DefaultOptionBase;
31
32
33 /**
34  * Base abstract implementation for Tools Option objects.
35  *
36  * Subclasses must implement the consume method.
37  *
38  * @author <a HREF="mailto:christophe.contreras@lifl.fr">Christophe Contreras</a>
39  *
40  */

41
42 public abstract class OptionBase
43               extends DefaultOptionBase
44 {
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The application. */
52     private PATApplication application_;
53
54     // ==================================================================
55
//
56
// Constructors.
57
//
58
// ==================================================================
59

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

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

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

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

112     public void
113     consume(org.objectweb.util.cmdline.api.Iterator iterator)
114     {
115         // Nothing to do.
116
}
117
118     /**
119      * Obtains the associated application.
120      *
121      * @return The associated application.
122      */

123     public PATApplication
124     getApplication()
125     {
126         return application_;
127     }
128
129     /**
130      * Sets the associated application.
131      *
132      * @param preprocessor The associated application.
133      */

134     public void
135     setApplication(PATApplication application)
136     {
137         application_ = application;
138     }
139
140     /**
141      * Gets the base option label.
142      *
143      * @return The base option label.
144      */

145     abstract public String JavaDoc
146     getBaseOptionLabel();
147
148     /**
149      * Consumes the option.
150      *
151      * @param current The option value.
152      */

153     abstract public void
154     consumeOption(String JavaDoc current);
155
156 }
Popular Tags