KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > ODG


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8
package org.ozoneDB.tools.OPP;
9
10 import java.io.*;
11
12 import org.ozoneDB.tools.OPP.message.MessageWriter;
13 import org.ozoneDB.tools.OPP.message.SummaryMessageWriterDecorator;
14 import org.ozoneDB.tools.OPP.message.StdOutMessageWriter;
15 import org.ozoneDB.tools.OPP.srcgen.ClassBuilder;
16 import org.ozoneDB.tools.OPP.srcgen.ClassDirector;
17 import org.ozoneDB.tools.OPP.castor.*;
18
19 /**
20  * Command line driver for the ODG tool.
21  *
22  *
23  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
24  * @version $Revision$Date$
25  */

26 public class ODG {
27     private static OPPBean oppBean = new OPPBean();
28
29     public static void main(String JavaDoc[] args) {
30         oppBean.setGenerateFactory(false);
31         oppBean.setGenerateProxy(false);
32         oppBean.setGenerateOcd(true);
33         String JavaDoc outputDirName = "." + File.separator;
34
35         //boolean printStackTrace = false;
36
if (args.length == 0) {
37             printUsage();
38             System.exit(0);
39         }
40         MessageWriter genListener = new SummaryMessageWriterDecorator(new StdOutMessageWriter(false, false));
41         for (int argCount = 0; argCount < args.length; argCount++) {
42             if (args[argCount].equals("-st")) {
43                 oppBean.setPrintStackTrace(true);
44             } else if (args[argCount].equals("-version")) {
45                 System.out.println("$Id$");
46                 System.exit(0);
47             } else if (args[argCount].equals("-h")) {
48                 printUsage();
49                 System.exit(0);
50             } else if (args[argCount].startsWith("-o")) {
51                 outputDirName = args[argCount].substring(2) + File.separator;
52             } else {
53                 if (args[argCount].startsWith("-")) {
54                     System.out.println("Unknown option '" + args[argCount] + "'!\n");
55                     printUsage();
56                     System.exit(0);
57                 } else {
58                     try {
59                         if (args[argCount].endsWith(".xml") || args[argCount].endsWith(".ocd")) {
60                             OzoneClassDescriptor descriptor = CDHelper.xml2Descriptor(args[argCount]);
61                             showDescriptor(descriptor);
62                         } else {
63                             genListener.info(args[argCount] + ":");
64                             ClassBuilder builder = oppBean.createBuilder(new File(outputDirName), null, null);
65                             ClassDirector director = oppBean.createDirector(new File(outputDirName));
66                             director.build(args[argCount], builder);
67                         }
68                     } catch (Exception JavaDoc e) {
69                         System.out.println("Error: " + e.toString());
70                         e.printStackTrace(System.out);
71                     }
72                 }
73             }
74         }
75     }
76
77     public static void printUsage() {
78         System.out.println("Ozone Descriptor Generator");
79         System.out.println("usage: [-p<pattern>] [-q] [-h] [-o<directory>] class [class]*");
80         System.out.println(" -p regular expression to specify update methods (not implemented)");
81         System.out.println(" -o out/input directory for class files and sources");
82         System.out.println(" -version shows version information");
83         System.out.println(" -h shows this help");
84     }
85
86     protected static void showDescriptor(OzoneClassDescriptor descriptor) {
87         System.out.println("The OzoneClassDescriptor:");
88         System.out.println("Name: " + descriptor.getName());
89         System.out.println("Desc: " + descriptor.getDescription());
90         System.out.println("Package: " + descriptor.getPackage());
91         System.out.println("Superclass: " + descriptor.getSuperclass());
92         System.out.println("Interfaces: ");
93         String JavaDoc[] _i = descriptor.getInterface();
94         if (_i != null) {
95             for (int i = 0, l = _i.length; i < l; ++i) {
96                 System.out.println(" " + _i[i]);
97             }
98         }
99         System.out.println("Constructors: ");
100         Constructors ctors = descriptor.getConstructors();
101         PublicConstructor[] ctor = ctors.getPublicConstructor();
102         for (int i = 0, l = ctor.length; i < l; ++i) {
103             System.out.println(" - parameters: " + ctor[i].getParameter());
104             if (ctor[i].getDescription() != null) {
105                 System.out.println(" desc: " + ctor[i].getDescription());
106             }
107         }
108         System.out.println("Methods: ");
109         Methods mths = descriptor.getMethods();
110         PublicMethod[] m = mths.getPublicMethod();
111         for (int i = 0, l = m.length; i < l; ++i) {
112             System.out.println(" - name: " + m[i].getName());
113             System.out.println(" parameters: " + m[i].getParameter());
114             System.out.println(" locklevel : " + m[i].getLocklevel());
115             if (m[i].getDescription() != null) {
116                 System.out.println(" desc: " + m[i].getDescription());
117             }
118         }
119     }
120 }
Popular Tags