Class JRAbstractCompiler
- java.lang.Object
-
- net.sf.jasperreports.engine.design.JRAbstractCompiler
-
- All Implemented Interfaces:
JRCompiler
- Direct Known Subclasses:
JavaScriptCompilerBase,JRAbstractJavaCompiler
public abstract class JRAbstractCompiler extends java.lang.Object implements JRCompiler
Base class for report compilers.- Author:
- Lucian Chirita (lucianc@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXCEPTION_MESSAGE_KEY_CROSSTAB_ID_NOT_FOUNDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_DESIGN_COMPILE_ERRORstatic java.lang.StringEXCEPTION_MESSAGE_KEY_LANGUAGE_NOT_SUPPORTEDstatic java.lang.StringEXCEPTION_MESSAGE_KEY_REPORT_EXPRESSIONS_COMPILE_ERRORstatic java.lang.StringEXCEPTION_MESSAGE_KEY_TEMP_DIR_NOT_FOUNDprotected JasperReportsContextjasperReportsContextprotected ReportClassFilterreportClassFilter-
Fields inherited from interface net.sf.jasperreports.engine.design.JRCompiler
COMPILER_CLASS, COMPILER_CLASSPATH, COMPILER_KEEP_JAVA_FILE, COMPILER_PREFIX, COMPILER_TEMP_DIR
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJRAbstractCompiler(JasperReportsContext jasperReportsContext, boolean needsSourceFiles)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcheckLanguage(java.lang.String language)Checks that the report language is supported by the compiler.JasperReportcompileReport(JasperDesign jasperDesign)Compiles a report design.protected abstract java.lang.StringcompileUnits(JRCompilationUnit[] units, java.lang.String classpath, java.io.File tempDirFile)Compiles several expression evaluator units.protected ReportExpressionEvaluationDatacreateCompileData(JRCompilationUnit unit)protected JREvaluatorcreateEvaluator(java.io.Serializable compileData, java.lang.String unitName)protected DirectExpressionValueFilterdirectValueFilter()protected DirectExpressionValueFiltereffectiveDirectValueFilter()protected abstract JRCompilationSourceCodegenerateSourceCode(JRSourceCompileTask sourceTask)Generates expression evaluator code.protected java.lang.StringgetCompilerClass()protected java.io.FilegetSourceFile(java.io.File saveSourceDir, java.lang.String unitName, JRCompilationSourceCode sourceCode)protected abstract java.lang.StringgetSourceFileName(java.lang.String unitName)Returns the name of the source file where generated source code for an unit is saved.static java.lang.StringgetUnitName(JasperReport report, JRCrosstab crosstab)Returns the name of the expression evaluator unit for a crosstab of a report.static java.lang.StringgetUnitName(JasperReport report, JRDataset dataset)Returns the name of the expression evaluator unit for a dataset of a report.protected static java.lang.StringgetUnitName(JRReport report, int crosstabId, java.lang.String nameSuffix)protected static java.lang.StringgetUnitName(JRReport report, JRCrosstab crosstab, JRExpressionCollector expressionCollector, java.lang.String nameSuffix)protected static java.lang.StringgetUnitName(JRReport report, JRDataset dataset, java.lang.String nameSuffix)protected abstract JREvaluatorloadEvaluator(java.io.Serializable compileData, java.lang.String unitName)Creates an expression evaluator instance from data saved when the report was compiled.JREvaluatorloadEvaluator(JasperReport jasperReport)Loads the evaluator for a report's main dataset.JREvaluatorloadEvaluator(JasperReport jasperReport, JRCrosstab crosstab)Loads a expression evaluator class for a crosstab of a report.JREvaluatorloadEvaluator(JasperReport jasperReport, JRDataset dataset)Loads a expression evaluator class for a dataset of a report.
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_CROSSTAB_ID_NOT_FOUND
public static final java.lang.String EXCEPTION_MESSAGE_KEY_CROSSTAB_ID_NOT_FOUND
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_DESIGN_COMPILE_ERROR
public static final java.lang.String EXCEPTION_MESSAGE_KEY_DESIGN_COMPILE_ERROR
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_LANGUAGE_NOT_SUPPORTED
public static final java.lang.String EXCEPTION_MESSAGE_KEY_LANGUAGE_NOT_SUPPORTED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_REPORT_EXPRESSIONS_COMPILE_ERROR
public static final java.lang.String EXCEPTION_MESSAGE_KEY_REPORT_EXPRESSIONS_COMPILE_ERROR
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_TEMP_DIR_NOT_FOUND
public static final java.lang.String EXCEPTION_MESSAGE_KEY_TEMP_DIR_NOT_FOUND
- See Also:
- Constant Field Values
-
jasperReportsContext
protected final JasperReportsContext jasperReportsContext
-
reportClassFilter
protected ReportClassFilter reportClassFilter
-
-
Constructor Detail
-
JRAbstractCompiler
protected JRAbstractCompiler(JasperReportsContext jasperReportsContext, boolean needsSourceFiles)
Constructor.- Parameters:
needsSourceFiles- whether the compiler needs source files or is able to do in memory compilationIf true, the generated code is saved in source files to be used by the compiler.
-
-
Method Detail
-
getUnitName
public static java.lang.String getUnitName(JasperReport report, JRDataset dataset)
Returns the name of the expression evaluator unit for a dataset of a report.- Parameters:
report- the reportdataset- the dataset- Returns:
- the generated expression evaluator unit name
-
getUnitName
protected static java.lang.String getUnitName(JRReport report, JRDataset dataset, java.lang.String nameSuffix)
-
getUnitName
public static java.lang.String getUnitName(JasperReport report, JRCrosstab crosstab)
Returns the name of the expression evaluator unit for a crosstab of a report.- Parameters:
report- the reportcrosstab- the crosstab- Returns:
- the generated expression evaluator unit name
-
getUnitName
protected static java.lang.String getUnitName(JRReport report, JRCrosstab crosstab, JRExpressionCollector expressionCollector, java.lang.String nameSuffix)
-
getUnitName
protected static java.lang.String getUnitName(JRReport report, int crosstabId, java.lang.String nameSuffix)
-
compileReport
public final JasperReport compileReport(JasperDesign jasperDesign) throws JRException
Description copied from interface:JRCompilerCompiles 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.- Specified by:
compileReportin interfaceJRCompiler- Parameters:
jasperDesign- the report design- Returns:
- the compiled report
- Throws:
JRException
-
createCompileData
protected ReportExpressionEvaluationData createCompileData(JRCompilationUnit unit)
-
getCompilerClass
protected java.lang.String getCompilerClass()
-
getSourceFile
protected java.io.File getSourceFile(java.io.File saveSourceDir, java.lang.String unitName, JRCompilationSourceCode sourceCode)
-
loadEvaluator
public JREvaluator loadEvaluator(JasperReport jasperReport) throws JRException
Description copied from interface:JRCompilerLoads the evaluator for a report's main dataset.- Specified by:
loadEvaluatorin interfaceJRCompiler- Parameters:
jasperReport- the report- Returns:
- the evaluator for the report's main dataset
- Throws:
JRException
-
loadEvaluator
public JREvaluator loadEvaluator(JasperReport jasperReport, JRDataset dataset) throws JRException
Description copied from interface:JRCompilerLoads a expression evaluator class for a dataset of a report.- Specified by:
loadEvaluatorin interfaceJRCompiler- Parameters:
jasperReport- the reportdataset- the dataset- Returns:
- an instance of the dataset evaluator class
- Throws:
JRException
-
loadEvaluator
public JREvaluator loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab) throws JRException
Description copied from interface:JRCompilerLoads a expression evaluator class for a crosstab of a report.- Specified by:
loadEvaluatorin interfaceJRCompiler- Parameters:
jasperReport- the reportcrosstab- the crosstab- Returns:
- an instance of the dataset evaluator class
- Throws:
JRException
-
createEvaluator
protected JREvaluator createEvaluator(java.io.Serializable compileData, java.lang.String unitName) throws JRException
- Throws:
JRException
-
effectiveDirectValueFilter
protected DirectExpressionValueFilter effectiveDirectValueFilter()
-
directValueFilter
protected DirectExpressionValueFilter directValueFilter()
-
loadEvaluator
protected abstract JREvaluator loadEvaluator(java.io.Serializable compileData, java.lang.String unitName) throws JRException
Creates an expression evaluator instance from data saved when the report was compiled.- Parameters:
compileData- the data saved when the report was compiledunitName- the evaluator unit name- Returns:
- an expression evaluator instance
- Throws:
JRException
-
checkLanguage
protected abstract void checkLanguage(java.lang.String language) throws JRExceptionChecks that the report language is supported by the compiler.- Parameters:
language- the report language- Throws:
JRException
-
generateSourceCode
protected abstract JRCompilationSourceCode generateSourceCode(JRSourceCompileTask sourceTask) throws JRException
Generates expression evaluator code.- Parameters:
sourceTask- the source code generation information- Returns:
- generated expression evaluator code
- Throws:
JRException
-
compileUnits
protected abstract java.lang.String compileUnits(JRCompilationUnit[] units, java.lang.String classpath, java.io.File tempDirFile) throws JRException
Compiles several expression evaluator units.The result of the compilation should be set by calling
setCompileDataon all compile units.- Parameters:
units- the compilation unitsclasspath- the compilation classpathtempDirFile- temporary directory- Returns:
- a string containing compilation errors, or null if the compilation was successfull
- Throws:
JRException
-
getSourceFileName
protected abstract java.lang.String getSourceFileName(java.lang.String unitName)
Returns the name of the source file where generated source code for an unit is saved.If the compiler needs source files for compilation or
COMPILER_KEEP_JAVA_FILEis set, the generated source will be saved in a file having the name returned by this method.- Parameters:
unitName- the unit name- Returns:
- the source file name
-
-