2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Copyright (C) 2006 University of Waikato, Hamilton, New Zealand
24
import java.util.Enumeration;
25
import java.util.Vector;
28
* Lists the options of an OptionHandler
30
* @author fracpete (fracpete at waikato dot ac dot nz)
31
* @version $Revision: 1.1 $
33
public class ListOptions
34
implements OptionHandler {
37
protected String m_Classname = ListOptions.class.getName();
40
* Returns an enumeration describing the available options.
42
* @return an enumeration of all the available options.
44
public Enumeration listOptions() {
45
Vector result = new Vector();
47
result.addElement(new Option(
48
"\tThe class to load.",
49
"W", 1, "-W <classname>"));
51
return result.elements();
55
* Parses a given list of options.
57
* @param options the list of options as an array of strings
58
* @throws Exception if an option is not supported
60
public void setOptions(String[] options) throws Exception {
63
tmpStr = Utils.getOption('W', options);
64
if (tmpStr.length() > 0)
67
setClassname(this.getClass().getName());
71
* Gets the current settings of this object.
73
* @return an array of strings suitable for passing to setOptions
75
public String[] getOptions() {
78
result = new Vector();
81
result.add(getClassname());
83
return (String[]) result.toArray(new String[result.size()]);
87
* sets the classname of the class to generate the Javadoc for
89
* @param value the new classname
91
public void setClassname(String value) {
96
* returns the current classname
98
* @return the current classname
100
public String getClassname() {
105
* generates a string to print as help on the console
107
* @return the generated help
109
public String generateHelp() {
114
result = getClass().getName().replaceAll(".*\\.", "") + " Options:\n\n";
116
while (enm.hasMoreElements()) {
117
option = (Option) enm.nextElement();
118
result += option.synopsis() + "\n" + option.description() + "\n";
125
* generates the options string.
127
* @return the options string
128
* @throws Exception in case the generation fails
130
public String generate() throws Exception {
132
OptionHandler handler;
136
result = new StringBuffer();
138
handler = (OptionHandler) Class.forName(getClassname()).newInstance();
140
enm = ((OptionHandler) handler).listOptions();
141
while (enm.hasMoreElements()) {
142
option = (Option) enm.nextElement();
143
result.append(option.synopsis() + '\n');
144
result.append(option.description() + "\n");
147
return result.toString();
151
* runs the javadoc producer with the given commandline options
153
* @param options the commandline options
155
public static void main(String[] options) {
156
ListOptions list = new ListOptions();
160
if (Utils.getFlag('h', options))
161
throw new Exception("Help requested");
163
list.setOptions(options);
164
Utils.checkForRemainingOptions(options);
166
catch (Exception ex) {
167
String result = "\n" + ex.getMessage() + "\n\n" + list.generateHelp();
168
throw new Exception(result);
171
System.out.println("\n" + list.generate());
173
catch (Exception ex) {
174
System.err.println(ex.getMessage());