Interface JRCompiler
- All Known Implementing Classes:
JavaScriptClassCompiler
,JavaScriptCompiler
,JavaScriptCompilerBase
,JRAbstractClassCompiler
,JRAbstractCompiler
,JRAbstractJavaCompiler
,JRAbstractMultiClassCompiler
,JRAbstractSingleClassCompiler
,JRGroovyCompiler
,JRJavacCompiler
,JRJdk13Compiler
,JRJdtCompiler
Source report templates, created either by using the API or by parsing JRXML files, are subject to the report compilation process before they are filled with data. This is necessary to make various consistency validations and to incorporate into these report templates data used to evaluate all report expressions at runtime.
The compilation process transforms
JasperDesign
objects into
JasperReport
objects. Both classes are
implementations of the same basic JRReport
interface. However, JasperReport
objects
cannot be modified once they are produced,
while JasperDesign
objects can.
This is because some modifications made on the
report template would probably require re-validation, or if a report expression is
modified, the compiler-associated data stored inside the report template would have to be
updated.
JasperDesign
objects are produced when parsing JRXML files using the
JRXmlLoader
or created directly by the parent
application if dynamic report templates are required. The GUI tools for editing
JasperReports templates also work with this class to make in-memory modifications to
the report templates before storing them on disk.
A JasperDesign
object must be
subject to the report compilation process to produce a
JasperReport
object.
Central to this process is this JRCompiler
interface, which defines few methods, one being the following:
public JasperReport compileReport(JasperDesign design) throws JRException;
There are several implementations for this compiler interface depending on the language used for the report expressions or the mechanism used for their runtime evaluation.
Expressions Scripting Language
The default language for the report expressions is Java, but report expressions can be written in Groovy, JavaScript or any other scripting language as long as a report compiler implementation that can evaluate them at runtime is available.JasperReports currently ships report compiler implementations for the Groovy scripting language (http://groovy.codehaus.org) and JavaScript (http://www.mozilla.org/rhino).
The related compiler implementation classes are:
Since the most common scenario is to use the Java language for writing report
expressions, default implementations of the report compiler interface are shipped with
the library and are ready to use. They generate a Java class from the report expressions
and store bytecode in the generated JasperReport
object for use at report-filling time.
Java Compilers
The Java report compilers come in different flavors depending on the Java compiler used to compile the class that is generated on the fly:- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Deprecated.static final String
The classpath used by the report compiler.static final String
Whether to keep the java file generated when the report is compiled.static final String
Prefix for properties that map report compilers to expression languages.static final String
The temporary directory used by the report compiler. -
Method Summary
Modifier and TypeMethodDescriptioncompileReport
(JasperDesign jasperDesign) Compiles a report design.loadEvaluator
(JasperReport jasperReport) Loads the evaluator for a report's main dataset.loadEvaluator
(JasperReport jasperReport, JRCrosstab crosstab) Loads a expression evaluator class for a crosstab of a report.loadEvaluator
(JasperReport jasperReport, JRDataset dataset) Loads a expression evaluator class for a dataset of a report.
-
Field Details
-
COMPILER_CLASS
Deprecated.Replaced byCOMPILER_PREFIX
.The name of the class to be used for report compilation.No default value.
- See Also:
-
COMPILER_PREFIX
Prefix for properties that map report compilers to expression languages. Properties having this prefix are used to indicate the JRCompiler implementation to be used when compiling report designs that rely on the expression language specified as property suffix.- See Also:
-
COMPILER_KEEP_JAVA_FILE
Whether to keep the java file generated when the report is compiled.Defaults to
false
.- See Also:
-
COMPILER_TEMP_DIR
The temporary directory used by the report compiler.Defaults to
System.getProperty("java.io.tmpdir")
.- See Also:
-
COMPILER_CLASSPATH
The classpath used by the report compiler.Defaults to
System.getProperty("java.class.path")
.- See Also:
-
-
Method Details
-
compileReport
Compiles a report design.The compilation consists of verification of the design, generation of expression evaluators and construction of a serializable read-only version of the report.
A report compiler should usually extend
JRAbstractCompiler
.- Parameters:
jasperDesign
- the report design- Returns:
- the compiled report
- Throws:
JRException
-
loadEvaluator
Loads the evaluator for a report's main dataset.- Parameters:
jasperReport
- the report- Returns:
- the evaluator for the report's main dataset
- Throws:
JRException
-
loadEvaluator
Loads a expression evaluator class for a dataset of a report.- Parameters:
jasperReport
- the reportdataset
- the dataset- Returns:
- an instance of the dataset evaluator class
- Throws:
JRException
-
loadEvaluator
Loads a expression evaluator class for a crosstab of a report.- Parameters:
jasperReport
- the reportcrosstab
- the crosstab- Returns:
- an instance of the dataset evaluator class
- Throws:
JRException
-
COMPILER_PREFIX
.