Interface JRCompiler
-
- All Known Implementing Classes:
JavaScriptClassCompiler
,JavaScriptCompiler
,JavaScriptCompilerBase
,JRAbstractClassCompiler
,JRAbstractCompiler
,JRAbstractJavaCompiler
,JRAbstractMultiClassCompiler
,JRAbstractSingleClassCompiler
,JRGroovyCompiler
,JRJavacCompiler
,JRJdk13Compiler
,JRJdtCompiler
public interface JRCompiler
This interface exposes methods to load expressions evaluators and compile report templates.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 intoJasperReport
objects. Both classes are implementations of the same basicJRReport
interface. However,JasperReport
objects cannot be modified once they are produced, whileJasperDesign
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 theJRXmlLoader
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 aJasperReport
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:
JasperReport
,JasperDesign
,JRXmlLoader
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPILER_CLASS
Deprecated.Replaced byCOMPILER_PREFIX
.static String
COMPILER_CLASSPATH
The classpath used by the report compiler.static String
COMPILER_KEEP_JAVA_FILE
Whether to keep the java file generated when the report is compiled.static String
COMPILER_PREFIX
Prefix for properties that map report compilers to expression languages.static String
COMPILER_TEMP_DIR
The temporary directory used by the report compiler.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JasperReport
compileReport(JasperDesign jasperDesign)
Compiles a report design.JREvaluator
loadEvaluator(JasperReport jasperReport)
Loads the evaluator for a report's main dataset.JREvaluator
loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab)
Loads a expression evaluator class for a crosstab of a report.JREvaluator
loadEvaluator(JasperReport jasperReport, JRDataset dataset)
Loads a expression evaluator class for a dataset of a report.
-
-
-
Field Detail
-
COMPILER_CLASS
static final String COMPILER_CLASS
Deprecated.Replaced byCOMPILER_PREFIX
.The name of the class to be used for report compilation.No default value.
- See Also:
- Constant Field Values
-
COMPILER_PREFIX
static final String 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:
- Constant Field Values
-
COMPILER_KEEP_JAVA_FILE
static final String COMPILER_KEEP_JAVA_FILE
Whether to keep the java file generated when the report is compiled.Defaults to
false
.- See Also:
- Constant Field Values
-
COMPILER_TEMP_DIR
static final String COMPILER_TEMP_DIR
The temporary directory used by the report compiler.Defaults to
System.getProperty("user.dir")
.- See Also:
- Constant Field Values
-
COMPILER_CLASSPATH
static final String COMPILER_CLASSPATH
The classpath used by the report compiler.Defaults to
System.getProperty("java.class.path")
.- See Also:
- Constant Field Values
-
-
Method Detail
-
compileReport
JasperReport compileReport(JasperDesign jasperDesign) throws JRException
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
JREvaluator loadEvaluator(JasperReport jasperReport) throws JRException
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
JREvaluator loadEvaluator(JasperReport jasperReport, JRDataset dataset) throws JRException
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
JREvaluator loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab) throws JRException
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
-
-