001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: ODG.java,v 1.2 2002/04/17 09:29:39 per_nyfelt Exp $
008:
009: package org.ozoneDB.tools.OPP;
010:
011: import java.io.*;
012: import org.ozoneDB.DxLib.*;
013: import org.xml.sax.InputSource;
014: import org.exolab.castor.xml.Marshaller;
015: import org.exolab.castor.xml.Unmarshaller;
016: import org.ozoneDB.tools.OPP.castor.*;
017:
018: /**
019: * Command line driver for the ODG tool.
020: *
021: *
022: * @author <a href="http://www.softwarebuero.de/">SMB</a>
023: * @version $Revision: 1.2 $Date: 2002/04/17 09:29:39 $
024: */
025: public class ODG {
026:
027: public static void main(String[] args) {
028: boolean quiet = false;
029: String outputDirName = "." + File.separator;
030: boolean printStackTrace = false;
031:
032: if (args.length == 0) {
033: printUsage();
034: System.exit(0);
035: }
036:
037: for (int argCount = 0; argCount < args.length; argCount++) {
038: if (args[argCount].equals("-q")) {
039: quiet = true;
040: } else if (args[argCount].equals("-st")) {
041: printStackTrace = true;
042: } else if (args[argCount].equals("-version")) {
043: // else if (args[argCount].startsWith("-p")) {
044: // methodPattern = args[argCount].substring(2);
045: // }
046: System.out
047: .println("$Id: ODG.java,v 1.2 2002/04/17 09:29:39 per_nyfelt Exp $");
048: System.exit(0);
049: } else if (args[argCount].equals("-h")) {
050: printUsage();
051: System.exit(0);
052: } else if (args[argCount].startsWith("-o")) {
053: outputDirName = args[argCount].substring(2)
054: + File.separator;
055: } else {
056: if (args[argCount].startsWith("-")) {
057: System.out.println("Unknown option '"
058: + args[argCount] + "'!\n");
059: printUsage();
060: System.exit(0);
061: } else {
062: try {
063: if (args[argCount].endsWith(".xml")
064: || args[argCount].endsWith(".ocd")) {
065: OzoneClassDescriptor descriptor = CDHelper
066: .xml2Descriptor(args[argCount]);
067: CDHelper.showDescriptor(descriptor);
068: } else {
069: try {
070: OPPHelper.progressMsg(args[argCount]
071: + ":", quiet);
072:
073: Class cl = Class
074: .forName(args[argCount]);
075: PrintWriter out = new PrintWriter(
076: new FileOutputStream(
077: outputDirName
078: + OPPHelper
079: .classFileBasename(cl)
080: + ".ocd"), true);
081: // out.println ("<!-- Ozone Class Descriptor generated by ozone's odg tool. -->");
082: // out.println ("");
083: CDHelper.class2xml(cl, out, quiet);
084: } catch (ClassNotFoundException e) {
085: System.out.println(args[argCount]
086: + ": class not found.");
087: }
088: }
089: } catch (Exception e) {
090: System.out.println("Error: " + e.toString());
091: if (printStackTrace) {
092: e.printStackTrace(System.out);
093: }
094: }
095: }
096: }
097: }
098: }
099:
100: public static void printUsage() {
101: System.out.println("Ozone Descriptor Generator");
102: System.out
103: .println("usage: [-st] [-p<pattern>] [-q] [-h] [-o<directory>] class [class]*");
104: System.out.println(" -st print stack trace");
105: System.out
106: .println(" -p regular expression to specify update methods (not implemented)");
107: System.out
108: .println(" -q supress output of any messages");
109: System.out
110: .println(" -o out/input directory for class files and sources");
111: System.out.println(" -version shows version information");
112: System.out.println(" -h shows this help");
113: }
114:
115: }
|