0001: /*
0002: * ============================================================================
0003: * GNU Lesser General Public License
0004: * ============================================================================
0005: *
0006: * JasperReports - Free Java report-generating library.
0007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
0008: *
0009: * This library is free software; you can redistribute it and/or
0010: * modify it under the terms of the GNU Lesser General Public
0011: * License as published by the Free Software Foundation; either
0012: * version 2.1 of the License, or (at your option) any later version.
0013: *
0014: * This library is distributed in the hope that it will be useful,
0015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0017: * Lesser General Public License for more details.
0018: *
0019: * You should have received a copy of the GNU Lesser General Public
0020: * License along with this library; if not, write to the Free Software
0021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
0022: *
0023: * JasperSoft Corporation
0024: * 303 Second Street, Suite 450 North
0025: * San Francisco, CA 94107
0026: * http://www.jaspersoft.com
0027: */
0028: package net.sf.jasperreports.engine;
0029:
0030: import java.util.ArrayList;
0031: import java.util.Collection;
0032: import java.util.HashMap;
0033: import java.util.HashSet;
0034: import java.util.Iterator;
0035: import java.util.List;
0036: import java.util.Map;
0037: import java.util.Set;
0038: import java.util.TreeMap;
0039:
0040: import net.sf.jasperreports.charts.JRAreaPlot;
0041: import net.sf.jasperreports.charts.JRBar3DPlot;
0042: import net.sf.jasperreports.charts.JRBarPlot;
0043: import net.sf.jasperreports.charts.JRBubblePlot;
0044: import net.sf.jasperreports.charts.JRCandlestickPlot;
0045: import net.sf.jasperreports.charts.JRCategoryDataset;
0046: import net.sf.jasperreports.charts.JRCategorySeries;
0047: import net.sf.jasperreports.charts.JRDataRange;
0048: import net.sf.jasperreports.charts.JRHighLowDataset;
0049: import net.sf.jasperreports.charts.JRHighLowPlot;
0050: import net.sf.jasperreports.charts.JRLinePlot;
0051: import net.sf.jasperreports.charts.JRMeterPlot;
0052: import net.sf.jasperreports.charts.JRPieDataset;
0053: import net.sf.jasperreports.charts.JRScatterPlot;
0054: import net.sf.jasperreports.charts.JRThermometerPlot;
0055: import net.sf.jasperreports.charts.JRTimePeriodDataset;
0056: import net.sf.jasperreports.charts.JRTimePeriodSeries;
0057: import net.sf.jasperreports.charts.JRTimeSeries;
0058: import net.sf.jasperreports.charts.JRTimeSeriesDataset;
0059: import net.sf.jasperreports.charts.JRTimeSeriesPlot;
0060: import net.sf.jasperreports.charts.JRValueDataset;
0061: import net.sf.jasperreports.charts.JRXyDataset;
0062: import net.sf.jasperreports.charts.JRXySeries;
0063: import net.sf.jasperreports.charts.JRXyzDataset;
0064: import net.sf.jasperreports.charts.JRXyzSeries;
0065: import net.sf.jasperreports.charts.util.JRMeterInterval;
0066: import net.sf.jasperreports.crosstabs.JRCellContents;
0067: import net.sf.jasperreports.crosstabs.JRCrosstab;
0068: import net.sf.jasperreports.crosstabs.JRCrosstabBucket;
0069: import net.sf.jasperreports.crosstabs.JRCrosstabCell;
0070: import net.sf.jasperreports.crosstabs.JRCrosstabColumnGroup;
0071: import net.sf.jasperreports.crosstabs.JRCrosstabDataset;
0072: import net.sf.jasperreports.crosstabs.JRCrosstabMeasure;
0073: import net.sf.jasperreports.crosstabs.JRCrosstabParameter;
0074: import net.sf.jasperreports.crosstabs.JRCrosstabRowGroup;
0075: import net.sf.jasperreports.crosstabs.design.JRDesignCrosstab;
0076:
0077: /**
0078: * @author Teodor Danciu (teodord@users.sourceforge.net)
0079: * @version $Id: JRExpressionCollector.java 1795 2007-07-30 09:18:47Z teodord $
0080: */
0081: public class JRExpressionCollector {
0082:
0083: public static JRExpressionCollector collector(JRReport report) {
0084: JRExpressionCollector collector = new JRExpressionCollector(
0085: null, report);
0086: collector.collect();
0087: return collector;
0088: }
0089:
0090: public static List collectExpressions(JRReport report) {
0091: return collector(report).getExpressions();
0092: }
0093:
0094: public static JRExpressionCollector collector(JRReport report,
0095: JRCrosstab crosstab) {
0096: JRExpressionCollector collector = new JRExpressionCollector(
0097: null, report);
0098: collector.collect(crosstab);
0099: return collector;
0100: }
0101:
0102: public static List collectExpressions(JRReport report,
0103: JRCrosstab crosstab) {
0104: return collector(report, crosstab).getExpressions(crosstab);
0105: }
0106:
0107: private final JRReport report;
0108: private final JRExpressionCollector parent;
0109:
0110: private Map expressionIds;
0111:
0112: protected static class GeneratedIds {
0113: private final TreeMap ids = new TreeMap();
0114: private int nextId = 0;
0115: private List expressions;
0116:
0117: public JRExpression put(Integer id, JRExpression expression) {
0118: expressions = null;
0119:
0120: return (JRExpression) ids.put(id, expression);
0121: }
0122:
0123: public Integer nextId() {
0124: Integer id = new Integer(nextId);
0125: while (ids.containsKey(id)) {
0126: id = new Integer(++nextId);
0127: }
0128: return id;
0129: }
0130:
0131: public List expressions() {
0132: if (expressions == null) {
0133: expressions = new ArrayList(ids.values());
0134: }
0135: return expressions;
0136: }
0137:
0138: public JRExpression expression(int id) {
0139: return (JRExpression) ids.get(new Integer(id));
0140: }
0141: }
0142:
0143: private GeneratedIds generatedIds = new GeneratedIds();
0144:
0145: private Map crosstabIds = new HashMap();
0146:
0147: /**
0148: * Collectors for sub datasets indexed by dataset name.
0149: */
0150: private Map datasetCollectors;
0151:
0152: /**
0153: * Collectors for crosstabs.
0154: */
0155: private Map crosstabCollectors;
0156:
0157: private final Set collectedStyles;
0158:
0159: protected JRExpressionCollector(JRExpressionCollector parent,
0160: JRReport report) {
0161: this .parent = parent;
0162: this .report = report;
0163:
0164: if (parent == null) {
0165: expressionIds = new HashMap();
0166: datasetCollectors = new HashMap();
0167: crosstabCollectors = new HashMap();
0168: } else {
0169: expressionIds = this .parent.expressionIds;
0170: }
0171:
0172: collectedStyles = new HashSet();
0173: }
0174:
0175: /**
0176: *
0177: */
0178: private void addExpression(JRExpression expression) {
0179: if (expression != null) {
0180: Integer id = getExpressionId(expression);
0181: if (id == null) {
0182: id = generatedIds.nextId();
0183: setGeneratedId(expression, id);
0184: generatedIds.put(id, expression);
0185: } else {
0186: JRExpression existingExpression = generatedIds.put(id,
0187: expression);
0188: if (existingExpression != null
0189: && !existingExpression.equals(expression)) {
0190: Integer newId = generatedIds.nextId();
0191: updateGeneratedId(existingExpression, id, newId);
0192: generatedIds.put(newId, existingExpression);
0193: }
0194: }
0195: }
0196: }
0197:
0198: private void setGeneratedId(JRExpression expression, Integer id) {
0199: Object existingId = expressionIds.put(expression, id);
0200: if (existingId != null && !existingId.equals(id)) {
0201: throw new JRRuntimeException("Expression \""
0202: + expression.getText() + "\" has two generated IDs");
0203: }
0204: }
0205:
0206: private void updateGeneratedId(JRExpression expression,
0207: Integer currentId, Integer newId) {
0208: Object existingId = expressionIds.put(expression, newId);
0209: if (existingId == null || !existingId.equals(currentId)) {
0210: throw new JRRuntimeException("Expression \""
0211: + expression.getText() + "\" not found with id "
0212: + currentId);
0213: }
0214: }
0215:
0216: private JRExpressionCollector getCollector(
0217: JRElementDataset elementDataset) {
0218: JRExpressionCollector collector;
0219:
0220: JRDatasetRun datasetRun = elementDataset.getDatasetRun();
0221: if (datasetRun == null) {
0222: collector = this ;
0223: } else {
0224: collector = getDatasetCollector(datasetRun.getDatasetName());
0225: }
0226:
0227: return collector;
0228: }
0229:
0230: private JRExpressionCollector getDatasetCollector(String datasetName) {
0231: JRExpressionCollector collector = (JRExpressionCollector) datasetCollectors
0232: .get(datasetName);
0233: if (collector == null) {
0234: collector = new JRExpressionCollector(this , report);
0235: datasetCollectors.put(datasetName, collector);
0236: }
0237: return collector;
0238: }
0239:
0240: /**
0241: * Returns the expression collector for a dataset.
0242: *
0243: * @param dataset the dataset
0244: * @return the dataset expression collector
0245: */
0246: public JRExpressionCollector getCollector(JRDataset dataset) {
0247: JRExpressionCollector collector;
0248:
0249: if (dataset.isMainDataset() || datasetCollectors == null) {
0250: collector = this ;
0251: } else {
0252: collector = getDatasetCollector(dataset.getName());
0253: }
0254:
0255: return collector;
0256: }
0257:
0258: /**
0259: * Returns the expression collector for a crosstab.
0260: *
0261: * @param crosstab the crosstab
0262: * @return the crosstab expression collector
0263: */
0264: public JRExpressionCollector getCollector(JRCrosstab crosstab) {
0265: JRExpressionCollector collector = (JRExpressionCollector) crosstabCollectors
0266: .get(crosstab);
0267: if (collector == null) {
0268: collector = new JRExpressionCollector(this , report);
0269: crosstabCollectors.put(crosstab, collector);
0270: }
0271: return collector;
0272: }
0273:
0274: /**
0275: * Returns the collected expressions.
0276: *
0277: * @return the collected expressions
0278: */
0279: public List getExpressions() {
0280: return new ArrayList(generatedIds.expressions());
0281: }
0282:
0283: /**
0284: * Returns the expressions collected for a dataset.
0285: *
0286: * @param dataset the dataset
0287: * @return the expressions
0288: */
0289: public List getExpressions(JRDataset dataset) {
0290: return getCollector(dataset).getExpressions();
0291: }
0292:
0293: /**
0294: * Returns the expressions collected for a crosstab.
0295: *
0296: * @param crosstab the crosstab
0297: * @return the expressions
0298: */
0299: public List getExpressions(JRCrosstab crosstab) {
0300: return getCollector(crosstab).getExpressions();
0301: }
0302:
0303: public Integer getExpressionId(JRExpression expression) {
0304: return (Integer) expressionIds.get(expression);
0305: }
0306:
0307: public JRExpression getExpression(int expressionId) {
0308: return generatedIds.expression(expressionId);
0309: }
0310:
0311: public Integer getCrosstabId(JRCrosstab crosstab) {
0312: return (Integer) crosstabIds.get(crosstab);
0313: }
0314:
0315: /**
0316: *
0317: */
0318: public Collection collect() {
0319: collectTemplates();
0320:
0321: collect(report.getDefaultStyle());
0322:
0323: collect(report.getMainDataset());
0324:
0325: JRDataset[] datasets = report.getDatasets();
0326: if (datasets != null && datasets.length > 0) {
0327: for (int i = 0; i < datasets.length; i++) {
0328: JRExpressionCollector collector = getCollector(datasets[i]);
0329: collector.collect(datasets[i]);
0330: }
0331: }
0332:
0333: collect(report.getBackground());
0334: collect(report.getTitle());
0335: collect(report.getPageHeader());
0336: collect(report.getColumnHeader());
0337: collect(report.getDetail());
0338: collect(report.getColumnFooter());
0339: collect(report.getPageFooter());
0340: collect(report.getLastPageFooter());
0341: collect(report.getSummary());
0342: collect(report.getNoData());
0343:
0344: return getExpressions();
0345: }
0346:
0347: protected void collectTemplates() {
0348: JRReportTemplate[] templates = report.getTemplates();
0349: if (templates != null) {
0350: for (int i = 0; i < templates.length; i++) {
0351: JRReportTemplate template = templates[i];
0352: collect(template);
0353: }
0354: }
0355: }
0356:
0357: protected void collect(JRReportTemplate template) {
0358: addExpression(template.getSourceExpression());
0359: }
0360:
0361: /**
0362: *
0363: */
0364: private void collect(JRStyle style) {
0365: if (style != null && collectedStyles.add(style)) {
0366: JRConditionalStyle[] conditionalStyles = style
0367: .getConditionalStyles();
0368:
0369: if (conditionalStyles != null
0370: && conditionalStyles.length > 0) {
0371: for (int i = 0; i < conditionalStyles.length; i++) {
0372: addExpression(conditionalStyles[i]
0373: .getConditionExpression());
0374: }
0375: }
0376:
0377: collect(style.getStyle());
0378: }
0379: }
0380:
0381: /**
0382: *
0383: */
0384: private void collect(JRParameter[] parameters) {
0385: if (parameters != null && parameters.length > 0) {
0386: for (int i = 0; i < parameters.length; i++) {
0387: addExpression(parameters[i].getDefaultValueExpression());
0388: }
0389: }
0390: }
0391:
0392: /**
0393: *
0394: */
0395: private void collect(JRVariable[] variables) {
0396: if (variables != null && variables.length > 0) {
0397: for (int i = 0; i < variables.length; i++) {
0398: JRVariable variable = variables[i];
0399: addExpression(variable.getExpression());
0400: addExpression(variable.getInitialValueExpression());
0401: }
0402: }
0403: }
0404:
0405: /**
0406: *
0407: */
0408: private void collect(JRGroup[] groups) {
0409: if (groups != null && groups.length > 0) {
0410: for (int i = 0; i < groups.length; i++) {
0411: JRGroup group = groups[i];
0412: addExpression(group.getExpression());
0413:
0414: collect(group.getGroupHeader());
0415: collect(group.getGroupFooter());
0416: }
0417: }
0418: }
0419:
0420: /**
0421: *
0422: */
0423: private void collect(JRBand band) {
0424: if (band != null) {
0425: addExpression(band.getPrintWhenExpression());
0426:
0427: JRElement[] elements = band.getElements();
0428: if (elements != null && elements.length > 0) {
0429: for (int i = 0; i < elements.length; i++) {
0430: elements[i].collectExpressions(this );
0431: }
0432: }
0433: }
0434: }
0435:
0436: /**
0437: *
0438: */
0439: private void collectElement(JRElement element) {
0440: collect(element.getStyle());
0441: addExpression(element.getPrintWhenExpression());
0442: }
0443:
0444: /**
0445: *
0446: */
0447: private void collectAnchor(JRAnchor anchor) {
0448: addExpression(anchor.getAnchorNameExpression());
0449: }
0450:
0451: private void collectHyperlink(JRHyperlink hyperlink) {
0452: if (hyperlink != null) {
0453: addExpression(hyperlink.getHyperlinkReferenceExpression());
0454: addExpression(hyperlink.getHyperlinkAnchorExpression());
0455: addExpression(hyperlink.getHyperlinkPageExpression());
0456: addExpression(hyperlink.getHyperlinkTooltipExpression());
0457:
0458: JRHyperlinkParameter[] hyperlinkParameters = hyperlink
0459: .getHyperlinkParameters();
0460: if (hyperlinkParameters != null) {
0461: for (int i = 0; i < hyperlinkParameters.length; i++) {
0462: JRHyperlinkParameter parameter = hyperlinkParameters[i];
0463: collectHyperlinkParameter(parameter);
0464: }
0465: }
0466: }
0467: }
0468:
0469: protected void collectHyperlinkParameter(
0470: JRHyperlinkParameter parameter) {
0471: if (parameter != null) {
0472: addExpression(parameter.getValueExpression());
0473: }
0474: }
0475:
0476: /**
0477: *
0478: */
0479: public void collect(JRBreak breakElement) {
0480: collectElement(breakElement);
0481: }
0482:
0483: /**
0484: *
0485: */
0486: public void collect(JRLine line) {
0487: collectElement(line);
0488: }
0489:
0490: /**
0491: *
0492: */
0493: public void collect(JRRectangle rectangle) {
0494: collectElement(rectangle);
0495: }
0496:
0497: /**
0498: *
0499: */
0500: public void collect(JREllipse ellipse) {
0501: collectElement(ellipse);
0502: }
0503:
0504: /**
0505: *
0506: */
0507: public void collect(JRImage image) {
0508: collectElement(image);
0509: addExpression(image.getExpression());
0510: collectAnchor(image);
0511: collectHyperlink(image);
0512: }
0513:
0514: /**
0515: *
0516: */
0517: public void collect(JRStaticText staticText) {
0518: collectElement(staticText);
0519: }
0520:
0521: /**
0522: *
0523: */
0524: public void collect(JRTextField textField) {
0525: collectElement(textField);
0526: addExpression(textField.getExpression());
0527: collectAnchor(textField);
0528: collectHyperlink(textField);
0529: }
0530:
0531: /**
0532: *
0533: */
0534: public void collect(JRSubreport subreport) {
0535: collectElement(subreport);
0536: addExpression(subreport.getParametersMapExpression());
0537:
0538: JRSubreportParameter[] parameters = subreport.getParameters();
0539: if (parameters != null && parameters.length > 0) {
0540: for (int j = 0; j < parameters.length; j++) {
0541: addExpression(parameters[j].getExpression());
0542: }
0543: }
0544:
0545: addExpression(subreport.getConnectionExpression());
0546: addExpression(subreport.getDataSourceExpression());
0547: addExpression(subreport.getExpression());
0548: }
0549:
0550: /**
0551: *
0552: */
0553: public void collect(JRChart chart) {
0554: collectElement(chart);
0555: collectAnchor(chart);
0556: collectHyperlink(chart);
0557:
0558: addExpression(chart.getTitleExpression());
0559: addExpression(chart.getSubtitleExpression());
0560:
0561: chart.getDataset().collectExpressions(this );
0562: chart.getPlot().collectExpressions(this );
0563: }
0564:
0565: /**
0566: *
0567: */
0568: public void collect(JRPieDataset pieDataset) {
0569: collect((JRElementDataset) pieDataset);
0570:
0571: JRExpressionCollector collector = getCollector(pieDataset);
0572: collector.addExpression(pieDataset.getKeyExpression());
0573: collector.addExpression(pieDataset.getValueExpression());
0574: collector.addExpression(pieDataset.getLabelExpression());
0575:
0576: collector.collectHyperlink(pieDataset.getSectionHyperlink());
0577: }
0578:
0579: /**
0580: *
0581: */
0582: public void collect(JRCategoryDataset categoryDataset) {
0583: collect((JRElementDataset) categoryDataset);
0584:
0585: JRCategorySeries[] categorySeries = categoryDataset.getSeries();
0586: if (categorySeries != null && categorySeries.length > 0) {
0587: JRExpressionCollector collector = getCollector(categoryDataset);
0588: for (int j = 0; j < categorySeries.length; j++) {
0589: collector.collect(categorySeries[j]);
0590: }
0591: }
0592: }
0593:
0594: /**
0595: *
0596: */
0597: public void collect(JRXyDataset xyDataset) {
0598: collect((JRElementDataset) xyDataset);
0599:
0600: JRXySeries[] xySeries = xyDataset.getSeries();
0601: if (xySeries != null && xySeries.length > 0) {
0602: JRExpressionCollector collector = getCollector(xyDataset);
0603: for (int j = 0; j < xySeries.length; j++) {
0604: collector.collect(xySeries[j]);
0605: }
0606: }
0607: }
0608:
0609: /**
0610: *
0611: */
0612: public void collect(JRTimeSeriesDataset timeSeriesDataset) {
0613: collect((JRElementDataset) timeSeriesDataset);
0614:
0615: JRTimeSeries[] timeSeries = timeSeriesDataset.getSeries();
0616: if (timeSeries != null && timeSeries.length > 0) {
0617: JRExpressionCollector collector = getCollector(timeSeriesDataset);
0618: for (int i = 0; i < timeSeries.length; i++) {
0619: collector.collect(timeSeries[i]);
0620: }
0621: }
0622: }
0623:
0624: /**
0625: *
0626: */
0627: public void collect(JRTimePeriodDataset timePeriodDataset) {
0628: collect((JRElementDataset) timePeriodDataset);
0629:
0630: JRTimePeriodSeries[] timePeriodSeries = timePeriodDataset
0631: .getSeries();
0632: if (timePeriodSeries != null && timePeriodSeries.length > 0) {
0633: JRExpressionCollector collector = getCollector(timePeriodDataset);
0634: for (int i = 0; i < timePeriodSeries.length; i++) {
0635: collector.collect(timePeriodSeries[i]);
0636: }
0637: }
0638: }
0639:
0640: /**
0641: *
0642: */
0643: public void collect(JRValueDataset valueDataset) {
0644: collect((JRElementDataset) valueDataset);
0645:
0646: JRExpressionCollector collector = getCollector(valueDataset);
0647: collector.addExpression(valueDataset.getValueExpression());
0648: }
0649:
0650: /**
0651: *
0652: */
0653: private void collect(JRXySeries xySeries) {
0654: addExpression(xySeries.getSeriesExpression());
0655: addExpression(xySeries.getXValueExpression());
0656: addExpression(xySeries.getYValueExpression());
0657: addExpression(xySeries.getLabelExpression());
0658:
0659: collectHyperlink(xySeries.getItemHyperlink());
0660: }
0661:
0662: /**
0663: *
0664: */
0665: private void collect(JRCategorySeries categorySeries) {
0666: addExpression(categorySeries.getSeriesExpression());
0667: addExpression(categorySeries.getCategoryExpression());
0668: addExpression(categorySeries.getValueExpression());
0669: addExpression(categorySeries.getLabelExpression());
0670:
0671: collectHyperlink(categorySeries.getItemHyperlink());
0672: }
0673:
0674: /**
0675: *
0676: */
0677: public void collect(JRBarPlot barPlot) {
0678: addExpression(barPlot.getCategoryAxisLabelExpression());
0679: addExpression(barPlot.getValueAxisLabelExpression());
0680: }
0681:
0682: /**
0683: *
0684: */
0685: public void collect(JRBar3DPlot barPlot) {
0686: addExpression(barPlot.getCategoryAxisLabelExpression());
0687: addExpression(barPlot.getValueAxisLabelExpression());
0688: }
0689:
0690: /**
0691: *
0692: */
0693: public void collect(JRLinePlot linePlot) {
0694: addExpression(linePlot.getCategoryAxisLabelExpression());
0695: addExpression(linePlot.getValueAxisLabelExpression());
0696: }
0697:
0698: /**
0699: *
0700: */
0701: public void collect(JRTimeSeriesPlot timeSeriesPlot) {
0702: addExpression(timeSeriesPlot.getTimeAxisLabelExpression());
0703: addExpression(timeSeriesPlot.getValueAxisLabelExpression());
0704: }
0705:
0706: /**
0707: *
0708: */
0709: public void collect(JRScatterPlot scatterPlot) {
0710: addExpression(scatterPlot.getXAxisLabelExpression());
0711: addExpression(scatterPlot.getYAxisLabelExpression());
0712: }
0713:
0714: /**
0715: *
0716: */
0717: public void collect(JRAreaPlot areaPlot) {
0718: addExpression(areaPlot.getCategoryAxisLabelExpression());
0719: addExpression(areaPlot.getValueAxisLabelExpression());
0720: }
0721:
0722: /**
0723: *
0724: */
0725: private void collect(JRTimeSeries timeSeries) {
0726: addExpression(timeSeries.getSeriesExpression());
0727: addExpression(timeSeries.getTimePeriodExpression());
0728: addExpression(timeSeries.getValueExpression());
0729: addExpression(timeSeries.getLabelExpression());
0730:
0731: collectHyperlink(timeSeries.getItemHyperlink());
0732: }
0733:
0734: /**
0735: *
0736: */
0737: private void collect(JRTimePeriodSeries timePeriodSeries) {
0738: addExpression(timePeriodSeries.getSeriesExpression());
0739: addExpression(timePeriodSeries.getStartDateExpression());
0740: addExpression(timePeriodSeries.getEndDateExpression());
0741: addExpression(timePeriodSeries.getValueExpression());
0742: addExpression(timePeriodSeries.getLabelExpression());
0743: collectHyperlink(timePeriodSeries.getItemHyperlink());
0744: }
0745:
0746: /**
0747: *
0748: */
0749: public void collect(JRXyzDataset xyzDataset) {
0750: collect((JRElementDataset) xyzDataset);
0751:
0752: JRXyzSeries[] xyzSeries = xyzDataset.getSeries();
0753: if (xyzSeries != null && xyzSeries.length > 0) {
0754: JRExpressionCollector collector = getCollector(xyzDataset);
0755: for (int j = 0; j < xyzSeries.length; j++) {
0756: collector.collect(xyzSeries[j]);
0757: }
0758: }
0759:
0760: }
0761:
0762: /**
0763: *
0764: */
0765: private void collect(JRXyzSeries xyzSeries) {
0766: addExpression(xyzSeries.getSeriesExpression());
0767: addExpression(xyzSeries.getXValueExpression());
0768: addExpression(xyzSeries.getYValueExpression());
0769: addExpression(xyzSeries.getZValueExpression());
0770: collectHyperlink(xyzSeries.getItemHyperlink());
0771: }
0772:
0773: /**
0774: *
0775: */
0776: public void collect(JRBubblePlot bubblePlot) {
0777: addExpression(bubblePlot.getXAxisLabelExpression());
0778: addExpression(bubblePlot.getYAxisLabelExpression());
0779:
0780: }
0781:
0782: /**
0783: *
0784: */
0785: public void collect(JRHighLowPlot highLowPlot) {
0786: addExpression(highLowPlot.getTimeAxisLabelExpression());
0787: addExpression(highLowPlot.getValueAxisLabelExpression());
0788: }
0789:
0790: /**
0791: *
0792: */
0793: public void collect(JRDataRange dataRange) {
0794: if (dataRange != null) {
0795: addExpression(dataRange.getLowExpression());
0796: addExpression(dataRange.getHighExpression());
0797: }
0798: }
0799:
0800: /**
0801: *
0802: */
0803: public void collect(JRMeterPlot meterPlot) {
0804: List intervals = meterPlot.getIntervals();
0805: if (intervals != null) {
0806: Iterator iter = intervals.iterator();
0807: while (iter.hasNext()) {
0808: JRMeterInterval interval = (JRMeterInterval) iter
0809: .next();
0810: collect(interval.getDataRange());
0811: }
0812: }
0813: collect(meterPlot.getDataRange());
0814: }
0815:
0816: /**
0817: *
0818: */
0819: public void collect(JRThermometerPlot thermometerPlot) {
0820: collect(thermometerPlot.getDataRange());
0821: collect(thermometerPlot.getLowRange());
0822: collect(thermometerPlot.getMediumRange());
0823: collect(thermometerPlot.getHighRange());
0824: }
0825:
0826: /**
0827: *
0828: */
0829: public void collect(JRHighLowDataset highLowDataset) {
0830: collect((JRElementDataset) highLowDataset);
0831:
0832: JRExpressionCollector collector = getCollector(highLowDataset);
0833: collector.addExpression(highLowDataset.getSeriesExpression());
0834: collector.addExpression(highLowDataset.getDateExpression());
0835: collector.addExpression(highLowDataset.getHighExpression());
0836: collector.addExpression(highLowDataset.getLowExpression());
0837: collector.addExpression(highLowDataset.getOpenExpression());
0838: collector.addExpression(highLowDataset.getCloseExpression());
0839: collector.addExpression(highLowDataset.getVolumeExpression());
0840:
0841: collector.collectHyperlink(highLowDataset.getItemHyperlink());
0842: }
0843:
0844: /**
0845: *
0846: */
0847: public void collect(JRCandlestickPlot candlestickPlot) {
0848: addExpression(candlestickPlot.getTimeAxisLabelExpression());
0849: addExpression(candlestickPlot.getValueAxisLabelExpression());
0850: }
0851:
0852: /**
0853: * Collects expressions from a crosstab.
0854: *
0855: * @param crosstab the crosstab
0856: */
0857: public void collect(JRCrosstab crosstab) {
0858: collectElement(crosstab);
0859:
0860: createCrosstabId(crosstab);
0861:
0862: JRCrosstabDataset dataset = crosstab.getDataset();
0863: collect(dataset);
0864:
0865: JRExpressionCollector datasetCollector = getCollector(dataset);
0866: JRExpressionCollector crosstabCollector = getCollector(crosstab);
0867:
0868: crosstabCollector.collect(report.getDefaultStyle());
0869:
0870: addExpression(crosstab.getParametersMapExpression());
0871:
0872: JRCrosstabParameter[] parameters = crosstab.getParameters();
0873: if (parameters != null) {
0874: for (int i = 0; i < parameters.length; i++) {
0875: addExpression(parameters[i].getExpression());
0876: }
0877: }
0878:
0879: crosstabCollector.collect(crosstab.getHeaderCell());
0880:
0881: JRCrosstabRowGroup[] rowGroups = crosstab.getRowGroups();
0882: if (rowGroups != null) {
0883: for (int i = 0; i < rowGroups.length; i++) {
0884: JRCrosstabRowGroup rowGroup = rowGroups[i];
0885: JRCrosstabBucket bucket = rowGroup.getBucket();
0886: datasetCollector.addExpression(bucket.getExpression());
0887: addExpression(bucket.getComparatorExpression());
0888: crosstabCollector.collect(rowGroup.getHeader());
0889: crosstabCollector.collect(rowGroup.getTotalHeader());
0890: }
0891: }
0892:
0893: JRCrosstabColumnGroup[] colGroups = crosstab.getColumnGroups();
0894: if (colGroups != null) {
0895: for (int i = 0; i < colGroups.length; i++) {
0896: JRCrosstabColumnGroup columnGroup = colGroups[i];
0897: datasetCollector.addExpression(columnGroup.getBucket()
0898: .getExpression());
0899: addExpression(columnGroup.getBucket()
0900: .getComparatorExpression());
0901: crosstabCollector.collect(columnGroup.getHeader());
0902: crosstabCollector.collect(columnGroup.getTotalHeader());
0903: }
0904: }
0905:
0906: JRCrosstabMeasure[] measures = crosstab.getMeasures();
0907: if (measures != null) {
0908: for (int i = 0; i < measures.length; i++) {
0909: datasetCollector.addExpression(measures[i]
0910: .getValueExpression());
0911: }
0912: }
0913:
0914: crosstabCollector.collect(crosstab.getWhenNoDataCell());
0915:
0916: collectCrosstabCells(crosstab, crosstabCollector);
0917: }
0918:
0919: private void createCrosstabId(JRCrosstab crosstab) {
0920: crosstabIds.put(crosstab, new Integer(crosstabIds.size()));
0921: }
0922:
0923: private void collectCrosstabCells(JRCrosstab crosstab,
0924: JRExpressionCollector crosstabCollector) {
0925: if (crosstab instanceof JRDesignCrosstab) {
0926: List cellsList = ((JRDesignCrosstab) crosstab)
0927: .getCellsList();
0928:
0929: if (cellsList != null) {
0930: for (Iterator iter = cellsList.iterator(); iter
0931: .hasNext();) {
0932: JRCrosstabCell cell = (JRCrosstabCell) iter.next();
0933: crosstabCollector.collect(cell.getContents());
0934: }
0935: }
0936: } else {
0937: JRCrosstabCell[][] cells = crosstab.getCells();
0938: if (cells != null) {
0939: for (int i = 0; i < cells.length; ++i) {
0940: for (int j = 0; j < cells[i].length; j++) {
0941: if (cells[i][j] != null) {
0942: crosstabCollector.collect(cells[i][j]
0943: .getContents());
0944: }
0945: }
0946: }
0947: }
0948: }
0949: }
0950:
0951: /**
0952: * Collects expressions from a dataset.
0953: *
0954: * @param dataset the dataset
0955: * @return collected expressions
0956: */
0957: public Collection collect(JRDataset dataset) {
0958: JRExpressionCollector collector = getCollector(dataset);
0959: collector.collect(dataset.getParameters());
0960: collector.collect(dataset.getVariables());
0961: collector.collect(dataset.getGroups());
0962:
0963: collector.addExpression(dataset.getFilterExpression());
0964:
0965: return getExpressions(dataset);
0966: }
0967:
0968: /**
0969: * Collects expressions from an element dataset.
0970: *
0971: * @param dataset the element dataset
0972: */
0973: protected void collect(JRElementDataset dataset) {
0974: collect(dataset.getDatasetRun());
0975:
0976: JRExpression incrementWhenExpression = dataset
0977: .getIncrementWhenExpression();
0978: if (incrementWhenExpression != null) {
0979: JRExpressionCollector datasetCollector = getCollector(dataset);
0980: datasetCollector.addExpression(incrementWhenExpression);
0981: }
0982: }
0983:
0984: private void collect(JRDatasetRun datasetRun) {
0985: if (datasetRun != null) {
0986: addExpression(datasetRun.getParametersMapExpression());
0987: addExpression(datasetRun.getConnectionExpression());
0988: addExpression(datasetRun.getDataSourceExpression());
0989:
0990: JRDatasetParameter[] parameters = datasetRun
0991: .getParameters();
0992: if (parameters != null && parameters.length > 0) {
0993: for (int i = 0; i < parameters.length; i++) {
0994: addExpression(parameters[i].getExpression());
0995: }
0996: }
0997: }
0998: }
0999:
1000: protected void collect(JRCellContents cell) {
1001: if (cell != null) {
1002: collect(cell.getStyle());
1003: JRElement[] elements = cell.getElements();
1004: if (elements != null && elements.length > 0) {
1005: for (int i = 0; i < elements.length; i++) {
1006: elements[i].collectExpressions(this );
1007: }
1008: }
1009: }
1010: }
1011:
1012: public void collect(JRFrame frame) {
1013: collectElement(frame);
1014: JRElement[] elements = frame.getElements();
1015: if (elements != null) {
1016: for (int i = 0; i < elements.length; i++) {
1017: elements[i].collectExpressions(this);
1018: }
1019: }
1020: }
1021: }
|