01: /*
02: * ============================================================================
03: * GNU Lesser General Public License
04: * ============================================================================
05: *
06: * JasperReports - Free Java report-generating library.
07: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22: *
23: * JasperSoft Corporation
24: * 303 Second Street, Suite 450 North
25: * San Francisco, CA 94107
26: * http://www.jaspersoft.com
27: */
28: package net.sf.jasperreports.engine.design;
29:
30: import java.io.File;
31:
32: import net.sf.jasperreports.engine.JRException;
33: import net.sf.jasperreports.engine.JRReport;
34: import net.sf.jasperreports.engine.util.JRLoader;
35:
36: /**
37: * @author Teodor Danciu (teodord@users.sourceforge.net)
38: * @version $Id: JRAbstractClassCompiler.java 1625 2007-03-09 17:21:31Z lucianc $
39: */
40: public abstract class JRAbstractClassCompiler extends
41: JRAbstractJavaCompiler implements JRMultiClassCompiler {
42:
43: protected JRAbstractClassCompiler() {
44: super (true);
45: }
46:
47: protected String compileUnits(JRCompilationUnit[] units,
48: String classpath, File tempDirFile) throws JRException {
49: File[] sources = new File[units.length];
50: for (int i = 0; i < sources.length; i++) {
51: sources[i] = units[i].getSourceFile();
52: }
53:
54: File[] classFiles = new File[units.length];
55: for (int i = 0; i < classFiles.length; i++) {
56: classFiles[i] = new File(tempDirFile, units[i].getName()
57: + ".class");
58: }
59:
60: try {
61: String errors = compileClasses(sources, classpath);
62:
63: if (errors == null) {
64: for (int i = 0; i < units.length; i++) {
65: byte[] classBytes = JRLoader
66: .loadBytes(classFiles[i]);
67: units[i].setCompileData(classBytes);
68: }
69: }
70:
71: return errors;
72: } finally {
73: for (int i = 0; i < classFiles.length; i++) {
74: if (classFiles[i].exists()) {
75: classFiles[i].delete();
76: }
77: }
78: }
79: }
80:
81: protected void checkLanguage(String language) throws JRException {
82: if (!JRReport.LANGUAGE_JAVA.equals(language)) {
83: throw new JRException("Language \"" + language
84: + "\" not supported by this report compiler.\n"
85: + "Expecting \"java\" instead.");
86: }
87: }
88:
89: protected JRCompilationSourceCode generateSourceCode(
90: JRSourceCompileTask sourceTask) throws JRException {
91: return JRClassGenerator.generateClass(sourceTask);
92: }
93:
94: protected String getSourceFileName(String unitName) {
95: return unitName + ".java";
96: }
97: }
|