KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > enhance > SunReferenceEnhancer


1 /*
2  * $Id: SunReferenceEnhancer.java,v 1.6 2003/10/20 05:59:26 jackknifebarber Exp $
3  */

4
5 package com.triactive.jdo.enhance;
6
7 import java.io.File JavaDoc;
8 import java.util.Arrays JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.List JavaDoc;
12
13 /**
14  * This is an implementation of the Enhancer that wraps Sun's JDO Reference
15  * Implementation class endhancer.
16  *
17  * @version $Revision: 1.6 $
18  */

19 public class SunReferenceEnhancer
20   extends Enhancer
21 {
22     private final Collection JavaDoc jdoFiles;
23     private final String JavaDoc destDir;
24     private final boolean verbose;
25
26
27     private SunReferenceEnhancer(String JavaDoc destDir, boolean verbose, Collection JavaDoc jdoFiles)
28     {
29         super();
30
31         this.destDir = destDir;
32         this.verbose = verbose;
33         this.jdoFiles = jdoFiles;
34     }
35
36
37     /**
38      * This method accepts a list of jdo files that should be enhanced by
39      * the Sun Reference Implementation enhancer.
40      *
41      * @param classNames The list of class names to be enhanced
42      */

43     protected int callExternalEnhancer(String JavaDoc[] classNames) throws Exception JavaDoc
44     {
45         int returnCode = 0;
46
47         if (classNames.length > 0)
48         {
49             ArrayList JavaDoc args = new ArrayList JavaDoc();
50
51             args.add("-f"); // Force writing of .class files.
52
args.add("-d");
53             args.add(destDir);
54
55             if (verbose)
56                 args.add("-v");
57
58             args.addAll(jdoFiles);
59
60             for (int i = 0; i < classNames.length; ++i)
61             {
62                 String JavaDoc name = classNames[i];
63                 System.out.println("Enhancing class " + name);
64
65                 args.add(new File JavaDoc(destDir, name.replace('.', '/') + ".class").toString());
66             }
67
68             com.sun.jdori.enhancer.Main main = new com.sun.jdori.enhancer.Main();
69             returnCode = main.process((String JavaDoc[])args.toArray(new String JavaDoc[args.size()]));
70         }
71
72         return returnCode;
73     }
74
75
76     /**
77      * Called when the class is invoked from the command line.
78      *
79      * @param args
80      * A list of JDO metadata files (*.jdo files). The list may optionally
81      * be prefixed by a -l flag followed by the name of a file to which
82      * the list of enhanced classes will be written to. The -d argument
83      * is also accepted to specify the destination directory to write the
84      * class files to. The -v flag makes the enhancer run with verbose
85      * output.
86      */

87     public static void main(String JavaDoc[] args) throws Exception JavaDoc
88     {
89         String JavaDoc classListFile = null;
90         String JavaDoc destDir = ".";
91         boolean verbose = false;
92         ArrayList JavaDoc jdoFiles = new ArrayList JavaDoc();
93
94         for (int i=0; i<args.length; i++)
95         {
96             if (args[i].equals("-l"))
97             {
98                 classListFile = args[++i];
99             }
100             else if (args[i].equals("-d"))
101             {
102                 destDir = args[++i];
103             }
104             else if (args[i].equals("-v"))
105             {
106                 verbose = true;
107             }
108             else
109             {
110                 jdoFiles.add(args[i]);
111             }
112         }
113
114         List JavaDoc classNames = getOrderedClassNames((String JavaDoc[])jdoFiles.toArray(new String JavaDoc[jdoFiles.size()]));
115
116         if (classListFile != null)
117             writeClassListFile(classListFile, classNames);
118
119         System.exit(new SunReferenceEnhancer(destDir, verbose, jdoFiles).enhance(classNames));
120     }
121 }
122
Popular Tags