01: /*
02: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.tools.jstat;
27:
28: import java.util.*;
29: import java.net.*;
30: import java.io.*;
31:
32: /**
33: * A class for listing the available options in the jstat_options file.
34: *
35: * @author Brian Doherty
36: * @version 1.9, 05/09/07
37: * @since 1.5
38: */
39: public class OptionLister {
40: private static final boolean debug = false;
41: private URL[] sources;
42:
43: public OptionLister(URL[] sources) {
44: this .sources = sources;
45: }
46:
47: public void print(PrintStream ps) {
48: Comparator<OptionFormat> c = new Comparator<OptionFormat>() {
49: public int compare(OptionFormat o1, OptionFormat o2) {
50: OptionFormat of1 = o1;
51: OptionFormat of2 = o2;
52: return (of1.getName().compareTo(of2.getName()));
53: }
54: };
55:
56: Set<OptionFormat> options = new TreeSet<OptionFormat>(c);
57:
58: for (int i = 0; i < sources.length; i++) {
59: try {
60: URL u = sources[i];
61: Reader r = new BufferedReader(new InputStreamReader(u
62: .openStream()));
63: Set<OptionFormat> s = new Parser(r).parseOptions();
64: options.addAll(s);
65: } catch (IOException e) {
66: if (debug) {
67: System.err.println(e.getMessage());
68: e.printStackTrace();
69: }
70: } catch (ParserException e) {
71: // Exception in parsing the options file.
72: System.err.println(sources[i] + ": " + e.getMessage());
73: System.err.println("Parsing of " + sources[i]
74: + " aborted");
75: }
76: }
77:
78: for (OptionFormat of : options) {
79: if (of.getName().compareTo("timestamp") == 0) {
80: // ignore the special timestamp OptionFormat.
81: continue;
82: }
83: ps.println("-" + of.getName());
84: }
85: }
86: }
|