return query;
}
public static DynamicJasperDesign downCast(JasperDesign jd, DynamicReport dr) throws CoreException {
DynamicJasperDesign djd = new DynamicJasperDesign();
log.info("downcasting JasperDesign");
try {
BeanUtils.copyProperties(djd, jd);
//BeanUtils.copyProperties does not perform deep copy,
//adding original parameter definitions manually
if (dr.isTemplateImportParameters()){
for (Iterator iter = jd.getParametersList().iterator(); iter.hasNext();) {
JRParameter element = (JRParameter) iter.next();
try {
djd.addParameter(element);
} catch (JRException e) {
if (log.isDebugEnabled()){
log.warn(e.getMessage());
}
}
}
}
//BeanUtils.copyProperties does not perform deep copy,
//adding original fields definitions manually
if (dr.isTemplateImportFields()){
for (Iterator iter = jd.getFieldsList().iterator(); iter.hasNext();) {
JRField element = (JRField) iter.next();
try {
djd.addField(element);
} catch (JRException e) {
if (log.isDebugEnabled()){
log.warn(e.getMessage());
}
}
}
}
//BeanUtils.copyProperties does not perform deep copy,
//adding original variables definitions manually
if (dr.isTemplateImportVariables()){
for (Iterator iter = jd.getVariablesList().iterator(); iter.hasNext();) {
JRVariable element = (JRVariable) iter.next();
try {
if (element instanceof JRDesignVariable){
djd.addVariable((JRDesignVariable) element);
}
} catch (JRException e) {
if (log.isDebugEnabled()){
log.warn(e.getMessage());
}
}
}
}
//BeanUtils.copyProperties does not perform deep copy,
//adding original dataset definitions manually
if (dr.isTemplateImportDatasets()) {
// also copy query
JRQuery query = jd.getQuery();
if (query instanceof JRDesignQuery) {
djd.setQuery((JRDesignQuery) query);
dr.setQuery(new DJQuery(query.getText(), query
.getLanguage()));
}
for (Iterator iter = jd.getDatasetsList().iterator(); iter.hasNext();) {
JRDesignDataset dataset = (JRDesignDataset) iter.next();
try {
djd.addDataset(dataset);
} catch (JRException e) {
if (log.isDebugEnabled()) {
log.warn(e.getMessage());
}
}
}
}
//BeanUtils.copyProperties does not perform deep copy,
//adding original properties definitions manually
String[] properties = jd.getPropertyNames();
for (int i = 0; i < properties.length; i++) {
String propName = properties[i];
String propValue = jd.getProperty(propName);
djd.setProperty(propName, propValue);
}
//Add all existing styles in the design to the new one
for (Iterator iterator = jd.getStylesList().iterator(); iterator.hasNext();) {
JRStyle style = (JRStyle) iterator.next();
try {
djd.addStyle(style);
} catch (JRException e) {
if (log.isDebugEnabled()){
log.warn("Duplicated style (style name \""+ style.getName()+"\") when loading design: " + e.getMessage(), e);
}
}