{
// check if the language is supported by the compiler
checkLanguage(jasperDesign.getLanguage());
// collect all report expressions
JRExpressionCollector expressionCollector = JRExpressionCollector.collector(jasperDesign);
// verify the report design
verifyDesign(jasperDesign, expressionCollector);
String nameSuffix = createNameSuffix();
// check if saving source files is required
boolean isKeepJavaFile = JRProperties.getBooleanProperty(JRProperties.COMPILER_KEEP_JAVA_FILE);
File tempDirFile = null;
if (isKeepJavaFile || needsSourceFiles)
{
String tempDirStr = JRProperties.getProperty(JRProperties.COMPILER_TEMP_DIR);
tempDirFile = new File(tempDirStr);
if (!tempDirFile.exists() || !tempDirFile.isDirectory())
{
throw new JRException("Temporary directory not found : " + tempDirStr);
}
}
List datasets = jasperDesign.getDatasetsList();
List crosstabs = jasperDesign.getCrosstabs();
JRCompilationUnit[] units = new JRCompilationUnit[datasets.size() + crosstabs.size() + 1];
// generating source code for the main report dataset
units[0] = createCompileUnit(jasperDesign, jasperDesign.getMainDesignDataset(), expressionCollector, tempDirFile, nameSuffix);
int sourcesCount = 1;
for (Iterator it = datasets.iterator(); it.hasNext(); ++sourcesCount)
{
JRDesignDataset dataset = (JRDesignDataset) it.next();
// generating source code for a sub dataset
units[sourcesCount] = createCompileUnit(jasperDesign, dataset, expressionCollector, tempDirFile, nameSuffix);
}
for (Iterator it = crosstabs.iterator(); it.hasNext(); ++sourcesCount)
{
JRDesignCrosstab crosstab = (JRDesignCrosstab) it.next();
// generating source code for a sub dataset
units[sourcesCount] = createCompileUnit(jasperDesign, crosstab, expressionCollector, tempDirFile, nameSuffix);
}
//TODO component - component compilation units?
String classpath = JRProperties.getProperty(JRProperties.COMPILER_CLASSPATH);
try
{
// compiling generated sources
String compileErrors = compileUnits(units, classpath, tempDirFile);
if (compileErrors != null)
{
throw new JRException("Errors were encountered when compiling report expressions class file:\n" + compileErrors);
}
// creating the report compile data
JRReportCompileData reportCompileData = new JRReportCompileData();
reportCompileData.setMainDatasetCompileData(units[0].getCompileData());
for (ListIterator it = datasets.listIterator(); it.hasNext();)
{
JRDesignDataset dataset = (JRDesignDataset) it.next();
reportCompileData.setDatasetCompileData(dataset, units[it.nextIndex()].getCompileData());
}
for (ListIterator it = crosstabs.listIterator(); it.hasNext();)
{
JRDesignCrosstab crosstab = (JRDesignCrosstab) it.next();
Integer crosstabId = expressionCollector.getCrosstabId(crosstab);
reportCompileData.setCrosstabCompileData(crosstabId.intValue(), units[datasets.size() + it.nextIndex()].getCompileData());
}
// creating the report
JasperReport jasperReport =