KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Package dependencies.
30
import org.objectweb.util.cmdline.api.OptionApplication;
31 import org.objectweb.util.cmdline.api.Application;
32
33 /**
34  * Default implementation of the
35  * the command line --version option.
36  *
37  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
38  *
39  * @version 0.1
40  */

41
42 public class DefaultOptionVersion
43      extends DefaultOptionBase
44   implements OptionApplication
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** The associated application. */
53     Application application_;
54
55     // ==================================================================
56
//
57
// Constructor.
58
//
59
// ==================================================================
60

61     /**
62      * The constructor with the associated application.
63      *
64      * @param application The associated application.
65      */

66     public
67     DefaultOptionVersion(Application application)
68     {
69         // Calls the DefaultOptionBase constructor.
70
super(new String JavaDoc[] { "--version"},
71               new String JavaDoc[0],
72               "Output version information and exit");
73
74     // Inits internal state.
75
application_ = application;
76     }
77
78     // ==================================================================
79
//
80
// Internal methods.
81
//
82
// ==================================================================
83

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

90     /**
91      * Consumes command line arguments from an iterator.
92      *
93      * @param iterator The command line argument iterator.
94      *
95      * @return true if the option has consumed arguments.
96      */

97     public void
98     consume(org.objectweb.util.cmdline.api.Iterator iterator)
99     {
100         // Obtains the standard output stream of the application console.
101
java.io.PrintStream JavaDoc output = application_.getConsole().getOutputStream();
102
103         // Obtains the application version information.
104
String JavaDoc[] versionInformation = application_.getVersionInformation();
105
106         // Outputs the application version information.
107
for(int i=0; i<versionInformation.length; i++)
108             output.println(versionInformation[i]);
109
110         // Then exits.
111
System.exit(0);
112     }
113
114     // ==================================================================
115
//
116
// Public methods for interface org.objectweb.util.cmdline.api.ApplicationHolder
117
//
118
// ==================================================================
119

120     /**
121      * Obtains the associated application.
122      *
123      * @return The associated application.
124      */

125     public Application
126     getApplication()
127     {
128         return application_;
129     }
130
131     /**
132      * Sets the associated application.
133      *
134      * @param console The associated application.
135      */

136     public void
137     setApplication(Application application)
138     {
139         application_ = application;
140     }
141
142     // ==================================================================
143
//
144
// Public methods for interface org.objectweb.util.cmdline.api.OptionApplication
145
//
146
// ==================================================================
147

148     // ==================================================================
149
//
150
// Other public methods.
151
//
152
// ==================================================================
153
}
154
Popular Tags