KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > compiler > Javac


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Javac.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.compiler;
25
26 import java.io.PrintWriter JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 import org.enhydra.xml.io.ErrorReporter;
30 import org.enhydra.xml.xmlc.XMLCException;
31 import org.enhydra.xml.xmlc.codegen.JavaCompile;
32 import org.enhydra.xml.xmlc.metadata.DocumentClass;
33 import org.enhydra.xml.xmlc.metadata.GenerateType;
34 import org.enhydra.xml.xmlc.metadata.JavaCompilerSection;
35 import org.enhydra.xml.xmlc.metadata.MetaData;
36
37 /**
38  * Compile generated classes.
39  */

40 public class Javac {
41     /** Should errors be passed back in an exception? */
42     private boolean fThrowErrorMsgs;
43
44
45     /**
46      * Enable collecting errors and throwing them in an exception.
47      */

48     public void setThrowErrorMsgs(boolean enable) {
49         fThrowErrorMsgs = enable;
50     }
51
52     /**
53      * Run a javac process. Stdout/stderr are written to the standard
54      * descriptors.
55      *
56      * @param metaData Document metadata.
57      * @param errorReporter Write errors to this object.
58      * @param verboseOut Write verbose message to this file if not null.
59      */

60     public void compile(MetaData metaData,
61                         ErrorReporter errorReporter,
62                         PrintWriter JavaDoc verboseOut)
63             throws XMLCException {
64
65         DocumentClass documentClass = metaData.getDocumentClass();
66         GenerateType generate = documentClass.getGenerate();
67         JavaCompilerSection compilerSection = metaData.getJavaCompilerSection();
68
69         String JavaDoc classOutputRoot = metaData.getCompileOptions().getClassOutputRoot();
70         ArrayList JavaDoc cmd = new ArrayList JavaDoc();
71
72         JavaCompile compile = new JavaCompile(errorReporter,
73                                               compilerSection.getJavac());
74
75         if (fThrowErrorMsgs) {
76             compile.setOptions(JavaCompile.COLLECT_STDOUT
77                    |JavaCompile.COLLECT_STDERR
78                                |JavaCompile.DUMP_STDERR_ON_FAIL);
79         }
80         if (classOutputRoot != null) {
81             compile.setClassOutputRoot(classOutputRoot);
82         }
83         compile.addArgs(compilerSection.getJavacArgs());
84     
85         compile.addArg("-encoding", "ISO-8859-1");
86         if (generate.generateClass()) {
87             compile.addSrc(documentClass.getJavaClassSource().getPath());
88         }
89         if (generate.generateInterface()) {
90             compile.addSrc(documentClass.getJavaInterfaceSource().getPath());
91         }
92         compile.compile(verboseOut);
93     }
94 }
95
Popular Tags