001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file ../GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.toolkit;
017:
018: import java.io.*;
019: import java.util.*;
020: import org.griphyn.common.util.*;
021: import gnu.getopt.*;
022:
023: /**
024: * This class deletes annotations for definition's and lfn's
025: *
026: * @author Jens-S. Vöckler
027: * @author Yong Zhao
028: * @version $Revision: 50 $
029: *
030: */
031: public class TestProps extends Toolkit {
032: /**
033: * String for usage
034: */
035: public static String m_usage = "";
036:
037: /**
038: * Constructor
039: */
040: public TestProps(String appName) {
041: super (appName);
042: }
043:
044: /**
045: * Print the usage string
046: */
047: public void showUsage() {
048: String linefeed = System.getProperty("line.separator", "\r\n");
049:
050: System.out
051: .println("$Id: TestProps.java 50 2007-05-19 00:48:32Z gmehta $"
052: + linefeed
053: + "VDS version "
054: + Version.instance().toString() + linefeed);
055:
056: System.out.println("Usage: " + this .m_application
057: + " [-c] [-u] | [-V]");
058: System.out
059: .println(linefeed
060: + "Options: "
061: + linefeed
062: + " -V|--version print version information and exit."
063: + linefeed
064: + " -h|--help print this message."
065: + linefeed
066: + " --verbose increases the verbosity level."
067: + linefeed
068: + " -c|--concise print in concise format instead of filling in blanks."
069: + linefeed
070: + " -u|--unsorted print in no particular sorting order."
071: + linefeed);
072: }
073:
074: /**
075: * Creates a set of options.
076: */
077: protected LongOpt[] generateValidOptions() {
078: LongOpt[] lo = new LongOpt[5];
079:
080: lo[0] = new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V');
081: lo[1] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
082: lo[2] = new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 1);
083:
084: lo[3] = new LongOpt("unsorted", LongOpt.NO_ARGUMENT, null, 'u');
085: lo[4] = new LongOpt("concise", LongOpt.NO_ARGUMENT, null, 'c');
086:
087: return lo;
088: }
089:
090: /**
091: * dump the properties after VDSProperties had parsed them.
092: */
093: public static void main(String[] args) {
094: int max = Integer.MIN_VALUE;
095: int min = Integer.MAX_VALUE;
096: boolean unsorted = false;
097: boolean concise = false;
098:
099: try {
100: // create an instance
101: TestProps me = new TestProps("show-properties");
102:
103: // parse CLI options
104: Getopt opts = new Getopt(me.m_application, args, "chuV", me
105: .generateValidOptions());
106: opts.setOpterr(false);
107: int option = 0;
108: while ((option = opts.getopt()) != -1) {
109: switch (option) {
110: case 1:
111: me.increaseVerbosity();
112: break;
113:
114: case 'V':
115: System.out
116: .println("$Id: TestProps.java 50 2007-05-19 00:48:32Z gmehta $");
117: System.out.println("VDS version "
118: + Version.instance().toString());
119: return;
120:
121: case 'c':
122: concise = true;
123: break;
124:
125: case 'u':
126: unsorted = true;
127: break;
128:
129: default:
130: case 'h':
131: me.showUsage();
132: return;
133: }
134: }
135:
136: // create and read all properties
137: VDSProperties v = VDSProperties.instance();
138:
139: // sort property keys into a tree set (sorted set)
140: // while obtaining minimum and maximum key lengths
141: Collection keys = null;
142: if (unsorted)
143: keys = new ArrayList();
144: else
145: keys = new TreeSet();
146:
147: for (Enumeration e = v.propertyNames(); e.hasMoreElements();) {
148: String key = (String) e.nextElement();
149: int len = key.length();
150: if (len > max)
151: max = len;
152: if (len < min)
153: min = len;
154: keys.add(key);
155: }
156:
157: // create sufficient spaces to accomodate the smallest key
158: StringBuffer space = new StringBuffer(max - min + 1);
159: for (int i = min; i <= max; ++i)
160: space.append(' ');
161:
162: // print all keys
163: for (Iterator i = keys.iterator(); i.hasNext();) {
164: String key = (String) i.next();
165: if (concise)
166: System.out.println(key + "=" + v.getProperty(key));
167: else
168: System.out.println(key
169: + space.substring(0, max - key.length())
170: + " " + v.getProperty(key));
171: }
172: } catch (Exception e) {
173: e.printStackTrace();
174: }
175: }
176: }
|