KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JRExpressionCollector


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Set JavaDoc;
38 import java.util.TreeMap JavaDoc;
39
40 import net.sf.jasperreports.charts.JRAreaPlot;
41 import net.sf.jasperreports.charts.JRBar3DPlot;
42 import net.sf.jasperreports.charts.JRBarPlot;
43 import net.sf.jasperreports.charts.JRBubblePlot;
44 import net.sf.jasperreports.charts.JRCandlestickPlot;
45 import net.sf.jasperreports.charts.JRCategoryDataset;
46 import net.sf.jasperreports.charts.JRCategorySeries;
47 import net.sf.jasperreports.charts.JRDataRange;
48 import net.sf.jasperreports.charts.JRHighLowDataset;
49 import net.sf.jasperreports.charts.JRHighLowPlot;
50 import net.sf.jasperreports.charts.JRLinePlot;
51 import net.sf.jasperreports.charts.JRMeterPlot;
52 import net.sf.jasperreports.charts.JRPieDataset;
53 import net.sf.jasperreports.charts.JRScatterPlot;
54 import net.sf.jasperreports.charts.JRThermometerPlot;
55 import net.sf.jasperreports.charts.JRTimePeriodDataset;
56 import net.sf.jasperreports.charts.JRTimePeriodSeries;
57 import net.sf.jasperreports.charts.JRTimeSeries;
58 import net.sf.jasperreports.charts.JRTimeSeriesDataset;
59 import net.sf.jasperreports.charts.JRTimeSeriesPlot;
60 import net.sf.jasperreports.charts.JRValueDataset;
61 import net.sf.jasperreports.charts.JRXyDataset;
62 import net.sf.jasperreports.charts.JRXySeries;
63 import net.sf.jasperreports.charts.JRXyzDataset;
64 import net.sf.jasperreports.charts.JRXyzSeries;
65 import net.sf.jasperreports.charts.util.JRMeterInterval;
66 import net.sf.jasperreports.crosstabs.JRCellContents;
67 import net.sf.jasperreports.crosstabs.JRCrosstab;
68 import net.sf.jasperreports.crosstabs.JRCrosstabBucket;
69 import net.sf.jasperreports.crosstabs.JRCrosstabCell;
70 import net.sf.jasperreports.crosstabs.JRCrosstabColumnGroup;
71 import net.sf.jasperreports.crosstabs.JRCrosstabDataset;
72 import net.sf.jasperreports.crosstabs.JRCrosstabMeasure;
73 import net.sf.jasperreports.crosstabs.JRCrosstabParameter;
74 import net.sf.jasperreports.crosstabs.JRCrosstabRowGroup;
75 import net.sf.jasperreports.crosstabs.design.JRDesignCrosstab;
76
77
78 /**
79  * @author Teodor Danciu (teodord@users.sourceforge.net)
80  * @version $Id: JRExpressionCollector.java 1502 2006-11-21 18:14:56 +0200 (Tue, 21 Nov 2006) teodord $
81  */

82 public class JRExpressionCollector
83 {
84     
85     public static JRExpressionCollector collector(JRReport report)
86     {
87         JRExpressionCollector collector = new JRExpressionCollector(null, report);
88         collector.collect();
89         return collector;
90     }
91     
92     public static List JavaDoc collectExpressions(JRReport report)
93     {
94         return collector(report).getExpressions();
95     }
96     
97     public static JRExpressionCollector collector(JRReport report, JRCrosstab crosstab)
98     {
99         JRExpressionCollector collector = new JRExpressionCollector(null, report);
100         collector.collect(crosstab);
101         return collector;
102     }
103     
104     public static List JavaDoc collectExpressions(JRReport report, JRCrosstab crosstab)
105     {
106         return collector(report, crosstab).getExpressions(crosstab);
107     }
108
109     private final JRReport report;
110     private final JRExpressionCollector parent;
111     
112     private Map JavaDoc expressionIds;
113
114     protected static class GeneratedIds
115     {
116         private final TreeMap JavaDoc ids = new TreeMap JavaDoc();
117         private int nextId = 0;
118         private List JavaDoc expressions;
119         
120         public JRExpression put(Integer JavaDoc id, JRExpression expression)
121         {
122             expressions = null;
123             
124             return (JRExpression) ids.put(id, expression);
125         }
126         
127         public Integer JavaDoc nextId()
128         {
129             Integer JavaDoc id = new Integer JavaDoc(nextId);
130             while(ids.containsKey(id))
131             {
132                 id = new Integer JavaDoc(++nextId);
133             }
134             return id;
135         }
136         
137         public List JavaDoc expressions()
138         {
139             if (expressions == null)
140             {
141                 expressions = new ArrayList JavaDoc(ids.values());
142             }
143             return expressions;
144         }
145     }
146     private GeneratedIds generatedIds = new GeneratedIds();
147     
148     private Map JavaDoc crosstabIds = new HashMap JavaDoc();
149     
150     /**
151      * Collectors for sub datasets indexed by dataset name.
152      */

153     private Map JavaDoc datasetCollectors;
154
155     /**
156      * Collectors for crosstabs.
157      */

158     private Map JavaDoc crosstabCollectors;
159     
160     private final Set JavaDoc collectedStyles;
161     
162     
163     protected JRExpressionCollector(JRExpressionCollector parent, JRReport report)
164     {
165         this.parent = parent;
166         this.report = report;
167         
168         if (parent == null)
169         {
170             expressionIds = new HashMap JavaDoc();
171             datasetCollectors = new HashMap JavaDoc();
172             crosstabCollectors = new HashMap JavaDoc();
173         }
174         
175         collectedStyles = new HashSet JavaDoc();
176     }
177
178     /**
179      *
180      */

181     private void addExpression(JRExpression expression)
182     {
183         if (expression != null)
184         {
185             Integer JavaDoc id = getGlobalGeneratedId(expression);
186             if (id == null)
187             {
188                 id = generatedIds.nextId();
189                 setGlobalGeneratedId(expression, id);
190                 generatedIds.put(id, expression);
191             }
192             else
193             {
194                 JRExpression existingExpression = generatedIds.put(id, expression);
195                 if (existingExpression != null && !existingExpression.equals(expression))
196                 {
197                     Integer JavaDoc newId = generatedIds.nextId();
198                     updateGlobalGeneratedId(existingExpression, id, newId);
199                     generatedIds.put(newId, existingExpression);
200                 }
201             }
202         }
203     }
204     
205     private Integer JavaDoc getGlobalGeneratedId(JRExpression expression)
206     {
207         Integer JavaDoc generatedId;
208         if (parent == null)
209         {
210             generatedId = (Integer JavaDoc) expressionIds.get(expression);
211         }
212         else
213         {
214             generatedId = parent.getGlobalGeneratedId(expression);
215         }
216         return generatedId;
217     }
218
219     private void setGlobalGeneratedId(JRExpression expression, Integer JavaDoc id)
220     {
221         if (parent == null)
222         {
223             Object JavaDoc existingId = expressionIds.put(expression, id);
224             if (existingId != null && !existingId.equals(id))
225             {
226                 throw new JRRuntimeException("Expression \"" + expression.getText() + "\" has two generated IDs");
227             }
228         }
229         else
230         {
231             parent.setGlobalGeneratedId(expression, id);
232         }
233     }
234
235     private void updateGlobalGeneratedId(JRExpression expression, Integer JavaDoc currentId, Integer JavaDoc newId)
236     {
237         if (parent == null)
238         {
239             Object JavaDoc existingId = expressionIds.put(expression, newId);
240             if (existingId == null || !existingId.equals(currentId))
241             {
242                 throw new JRRuntimeException("Expression \"" + expression.getText() + "\" not found with id " + currentId);
243             }
244         }
245         else
246         {
247             parent.updateGlobalGeneratedId(expression, currentId, newId);
248         }
249     }
250
251     
252     private JRExpressionCollector getCollector(JRElementDataset elementDataset)
253     {
254         JRExpressionCollector collector;
255         
256         JRDatasetRun datasetRun = elementDataset.getDatasetRun();
257         if (datasetRun == null)
258         {
259             collector = this;
260         }
261         else
262         {
263             collector = getDatasetCollector(datasetRun.getDatasetName());
264         }
265         
266         return collector;
267     }
268
269     
270     private JRExpressionCollector getDatasetCollector(String JavaDoc datasetName)
271     {
272         JRExpressionCollector collector = (JRExpressionCollector) datasetCollectors.get(datasetName);
273         if (collector == null)
274         {
275             collector = new JRExpressionCollector(this, report);
276             datasetCollectors.put(datasetName, collector);
277         }
278         return collector;
279     }
280
281     private JRExpressionCollector getCollector(JRDataset dataset)
282     {
283         JRExpressionCollector collector;
284         
285         if (dataset.isMainDataset() || datasetCollectors == null)
286         {
287             collector = this;
288         }
289         else
290         {
291             collector = getDatasetCollector(dataset.getName());
292         }
293         
294         return collector;
295     }
296
297     
298     private JRExpressionCollector getCollector(JRCrosstab crosstab)
299     {
300         JRExpressionCollector collector = (JRExpressionCollector) crosstabCollectors.get(crosstab);
301         if (collector == null)
302         {
303             collector = new JRExpressionCollector(this, report);
304             crosstabCollectors.put(crosstab, collector);
305         }
306         return collector;
307     }
308     
309     
310     /**
311      * Returns the collected expressions.
312      *
313      * @return the collected expressions
314      */

315     public List JavaDoc getExpressions()
316     {
317         return new ArrayList JavaDoc(generatedIds.expressions());
318     }
319
320     
321     /**
322      * Returns the expressions collected for a dataset.
323      *
324      * @param dataset the dataset
325      * @return the expressions
326      */

327     public List JavaDoc getExpressions(JRDataset dataset)
328     {
329         return getCollector(dataset).getExpressions();
330     }
331
332     
333     /**
334      * Returns the expressions collected for a crosstab.
335      *
336      * @param crosstab the crosstab
337      * @return the expressions
338      */

339     public List JavaDoc getExpressions(JRCrosstab crosstab)
340     {
341         return getCollector(crosstab).getExpressions();
342     }
343
344
345     public Integer JavaDoc getExpressionId(JRExpression expression)
346     {
347         return (Integer JavaDoc) expressionIds.get(expression);
348     }
349
350
351     public Integer JavaDoc getCrosstabId(JRCrosstab crosstab)
352     {
353         return (Integer JavaDoc) crosstabIds.get(crosstab);
354     }
355
356     
357     /**
358      *
359      */

360     public Collection JavaDoc collect()
361     {
362         collect(report.getDefaultStyle());
363
364         collect(report.getMainDataset());
365
366         JRDataset[] datasets = report.getDatasets();
367         if (datasets != null && datasets.length > 0)
368         {
369             for (int i = 0; i < datasets.length; i++)
370             {
371                 JRExpressionCollector collector = getCollector(datasets[i]);
372                 collector.collect(datasets[i]);
373             }
374         }
375
376         collect(report.getBackground());
377         collect(report.getTitle());
378         collect(report.getPageHeader());
379         collect(report.getColumnHeader());
380         collect(report.getDetail());
381         collect(report.getColumnFooter());
382         collect(report.getPageFooter());
383         collect(report.getLastPageFooter());
384         collect(report.getSummary());
385         
386         return getExpressions();
387     }
388
389
390     /**
391      *
392      */

393     private void collect(JRStyle style)
394     {
395         if (style != null && collectedStyles.add(style))
396         {
397             JRConditionalStyle[] conditionalStyles = style.getConditionalStyles();
398
399             if (conditionalStyles != null && conditionalStyles.length > 0)
400             {
401                 for (int i = 0; i < conditionalStyles.length; i++)
402                 {
403                     addExpression(conditionalStyles[i].getConditionExpression());
404                 }
405             }
406             
407             collect(style.getStyle());
408         }
409     }
410
411
412     /**
413      *
414      */

415     private void collect(JRParameter[] parameters)
416     {
417         if (parameters != null && parameters.length > 0)
418         {
419             for(int i = 0; i < parameters.length; i++)
420             {
421                 addExpression(parameters[i].getDefaultValueExpression());
422             }
423         }
424     }
425
426     /**
427      *
428      */

429     private void collect(JRVariable[] variables)
430     {
431         if (variables != null && variables.length > 0)
432         {
433             for(int i = 0; i < variables.length; i++)
434             {
435                 JRVariable variable = variables[i];
436                 addExpression(variable.getExpression());
437                 addExpression(variable.getInitialValueExpression());
438             }
439         }
440     }
441
442     /**
443      *
444      */

445     private void collect(JRGroup[] groups)
446     {
447         if (groups != null && groups.length > 0)
448         {
449             for(int i = 0; i < groups.length; i++)
450             {
451                 JRGroup group = groups[i];
452                 addExpression(group.getExpression());
453
454                 collect(group.getGroupHeader());
455                 collect(group.getGroupFooter());
456             }
457         }
458     }
459
460     /**
461      *
462      */

463     private void collect(JRBand band)
464     {
465         if (band != null)
466         {
467             addExpression(band.getPrintWhenExpression());
468     
469             JRElement[] elements = band.getElements();
470             if (elements != null && elements.length > 0)
471             {
472                 for(int i = 0; i < elements.length; i++)
473                 {
474                     elements[i].collectExpressions(this);
475                 }
476             }
477         }
478     }
479
480     /**
481      *
482      */

483     private void collectElement(JRElement element)
484     {
485         collect(element.getStyle());
486         addExpression(element.getPrintWhenExpression());
487     }
488
489     /**
490      *
491      */

492     private void collectAnchor(JRAnchor anchor)
493     {
494         addExpression(anchor.getAnchorNameExpression());
495     }
496
497     
498     private void collectHyperlink(JRHyperlink hyperlink)
499     {
500         if (hyperlink != null)
501         {
502             addExpression(hyperlink.getHyperlinkReferenceExpression());
503             addExpression(hyperlink.getHyperlinkAnchorExpression());
504             addExpression(hyperlink.getHyperlinkPageExpression());
505             addExpression(hyperlink.getHyperlinkTooltipExpression());
506
507             JRHyperlinkParameter[] hyperlinkParameters = hyperlink.getHyperlinkParameters();
508             if (hyperlinkParameters != null)
509             {
510                 for (int i = 0; i < hyperlinkParameters.length; i++)
511                 {
512                     JRHyperlinkParameter parameter = hyperlinkParameters[i];
513                     collectHyperlinkParameter(parameter);
514                 }
515             }
516         }
517     }
518
519     protected void collectHyperlinkParameter(JRHyperlinkParameter parameter)
520     {
521         if (parameter != null)
522         {
523             addExpression(parameter.getValueExpression());
524         }
525     }
526
527     /**
528      *
529      */

530     public void collect(JRBreak breakElement)
531     {
532         collectElement(breakElement);
533     }
534
535     /**
536      *
537      */

538     public void collect(JRLine line)
539     {
540         collectElement(line);
541     }
542
543     /**
544      *
545      */

546     public void collect(JRRectangle rectangle)
547     {
548         collectElement(rectangle);
549     }
550
551     /**
552      *
553      */

554     public void collect(JREllipse ellipse)
555     {
556         collectElement(ellipse);
557     }
558
559     /**
560      *
561      */

562     public void collect(JRImage image)
563     {
564         collectElement(image);
565         addExpression(image.getExpression());
566         collectAnchor(image);
567         collectHyperlink(image);
568     }
569
570     /**
571      *
572      */

573     public void collect(JRStaticText staticText)
574     {
575         collectElement(staticText);
576     }
577
578     /**
579      *
580      */

581     public void collect(JRTextField textField)
582     {
583         collectElement(textField);
584         addExpression(textField.getExpression());
585         collectAnchor(textField);
586         collectHyperlink(textField);
587     }
588
589     /**
590      *
591      */

592     public void collect(JRSubreport subreport)
593     {
594         collectElement(subreport);
595         addExpression(subreport.getParametersMapExpression());
596
597         JRSubreportParameter[] parameters = subreport.getParameters();
598         if (parameters != null && parameters.length > 0)
599         {
600             for(int j = 0; j < parameters.length; j++)
601             {
602                 addExpression(parameters[j].getExpression());
603             }
604         }
605
606         addExpression(subreport.getConnectionExpression());
607         addExpression(subreport.getDataSourceExpression());
608         addExpression(subreport.getExpression());
609     }
610
611     /**
612      *
613      */

614     public void collect(JRChart chart)
615     {
616         collectElement(chart);
617         collectAnchor(chart);
618         collectHyperlink(chart);
619         
620         addExpression(chart.getTitleExpression());
621         addExpression(chart.getSubtitleExpression());
622
623         chart.getDataset().collectExpressions(this);
624         chart.getPlot().collectExpressions(this);
625     }
626
627     /**
628      *
629      */

630     public void collect(JRPieDataset pieDataset)
631     {
632         collect((JRElementDataset) pieDataset);
633         
634         JRExpressionCollector collector = getCollector(pieDataset);
635         collector.addExpression(pieDataset.getKeyExpression());
636         collector.addExpression(pieDataset.getValueExpression());
637         collector.addExpression(pieDataset.getLabelExpression());
638         
639         collector.collectHyperlink(pieDataset.getSectionHyperlink());
640     }
641
642     /**
643      *
644      */

645     public void collect(JRCategoryDataset categoryDataset)
646     {
647         collect((JRElementDataset) categoryDataset);
648         
649         JRCategorySeries[] categorySeries = categoryDataset.getSeries();
650         if (categorySeries != null && categorySeries.length > 0)
651         {
652             JRExpressionCollector collector = getCollector(categoryDataset);
653             for(int j = 0; j < categorySeries.length; j++)
654             {
655                 collector.collect(categorySeries[j]);
656             }
657         }
658     }
659
660     /**
661      *
662      */

663     public void collect(JRXyDataset xyDataset)
664     {
665         collect((JRElementDataset) xyDataset);
666         
667         JRXySeries[] xySeries = xyDataset.getSeries();
668         if (xySeries != null && xySeries.length > 0)
669         {
670             JRExpressionCollector collector = getCollector(xyDataset);
671             for(int j = 0; j < xySeries.length; j++)
672             {
673                 collector.collect(xySeries[j]);
674             }
675         }
676     }
677
678     /**
679      *
680      */

681     public void collect( JRTimeSeriesDataset timeSeriesDataset ){
682         collect((JRElementDataset) timeSeriesDataset);
683         
684         JRTimeSeries[] timeSeries = timeSeriesDataset.getSeries();
685         if( timeSeries != null && timeSeries.length > 0 ){
686             JRExpressionCollector collector = getCollector(timeSeriesDataset);
687             for( int i = 0; i < timeSeries.length; i++ ){
688                 collector.collect(timeSeries[i]);
689             }
690         }
691     }
692     
693     /**
694      *
695      */

696     public void collect( JRTimePeriodDataset timePeriodDataset ){
697         collect((JRElementDataset) timePeriodDataset);
698         
699         JRTimePeriodSeries[] timePeriodSeries = timePeriodDataset.getSeries();
700         if( timePeriodSeries != null && timePeriodSeries.length > 0 ){
701             JRExpressionCollector collector = getCollector(timePeriodDataset);
702             for( int i = 0; i < timePeriodSeries.length; i++ ){
703                 collector.collect(timePeriodSeries[i]);
704             }
705         }
706     }
707     
708     /**
709      *
710      */

711     public void collect( JRValueDataset valueDataset ){
712         collect((JRElementDataset) valueDataset);
713
714         addExpression(valueDataset.getValueExpression());
715     }
716         
717     /**
718      *
719      */

720     private void collect(JRXySeries xySeries)
721     {
722         addExpression(xySeries.getSeriesExpression());
723         addExpression(xySeries.getXValueExpression());
724         addExpression(xySeries.getYValueExpression());
725         addExpression(xySeries.getLabelExpression());
726         
727         collectHyperlink(xySeries.getItemHyperlink());
728     }
729
730     /**
731      *
732      */

733     private void collect(JRCategorySeries categorySeries)
734     {
735         addExpression(categorySeries.getSeriesExpression());
736         addExpression(categorySeries.getCategoryExpression());
737         addExpression(categorySeries.getValueExpression());
738         addExpression(categorySeries.getLabelExpression());
739         
740         collectHyperlink(categorySeries.getItemHyperlink());
741     }
742
743     /**
744      *
745      */

746     public void collect(JRBarPlot barPlot)
747     {
748         addExpression(barPlot.getCategoryAxisLabelExpression());
749         addExpression(barPlot.getValueAxisLabelExpression());
750     }
751     
752     /**
753      *
754      */

755     public void collect(JRBar3DPlot barPlot)
756     {
757         addExpression(barPlot.getCategoryAxisLabelExpression());
758         addExpression(barPlot.getValueAxisLabelExpression());
759     }
760     
761     /**
762      *
763      */

764     public void collect( JRLinePlot linePlot ){
765         addExpression( linePlot.getCategoryAxisLabelExpression() );
766         addExpression( linePlot.getValueAxisLabelExpression() );
767     }
768     
769     /**
770      *
771      */

772     public void collect( JRTimeSeriesPlot timeSeriesPlot ){
773         addExpression( timeSeriesPlot.getTimeAxisLabelExpression() );
774         addExpression( timeSeriesPlot.getValueAxisLabelExpression() );
775     }
776     
777     /**
778      *
779      */

780     public void collect( JRScatterPlot scatterPlot ){
781         addExpression( scatterPlot.getXAxisLabelExpression() );
782         addExpression( scatterPlot.getYAxisLabelExpression() );
783     }
784     
785     /**
786      *
787      */

788     public void collect( JRAreaPlot areaPlot ){
789         addExpression( areaPlot.getCategoryAxisLabelExpression() );
790         addExpression( areaPlot.getValueAxisLabelExpression() );
791     }
792
793     /**
794      *
795      */

796     private void collect(JRTimeSeries timeSeries)
797     {
798         addExpression(timeSeries.getSeriesExpression());
799         addExpression(timeSeries.getTimePeriodExpression());
800         addExpression(timeSeries.getValueExpression());
801         addExpression(timeSeries.getLabelExpression());
802         
803         collectHyperlink(timeSeries.getItemHyperlink());
804     }
805     
806     /**
807      *
808      */

809     private void collect(JRTimePeriodSeries timePeriodSeries ){
810         addExpression(timePeriodSeries.getSeriesExpression());
811         addExpression(timePeriodSeries.getStartDateExpression());
812         addExpression(timePeriodSeries.getEndDateExpression());
813         addExpression(timePeriodSeries.getValueExpression());
814         addExpression(timePeriodSeries.getLabelExpression());
815         collectHyperlink(timePeriodSeries.getItemHyperlink());
816     }
817
818     /**
819      *
820      */

821     public void collect(JRXyzDataset xyzDataset) {
822         collect((JRElementDataset) xyzDataset);
823         
824         JRXyzSeries[] xyzSeries = xyzDataset.getSeries();
825         if (xyzSeries != null && xyzSeries.length > 0)
826         {
827             JRExpressionCollector collector = getCollector(xyzDataset);
828             for(int j = 0; j < xyzSeries.length; j++)
829             {
830                 collector.collect(xyzSeries[j]);
831             }
832         }
833         
834     }
835
836     /**
837      *
838      */

839     private void collect(JRXyzSeries xyzSeries) {
840         addExpression(xyzSeries.getSeriesExpression());
841         addExpression(xyzSeries.getXValueExpression());
842         addExpression(xyzSeries.getYValueExpression());
843         addExpression(xyzSeries.getZValueExpression());
844         collectHyperlink(xyzSeries.getItemHyperlink());
845     }
846
847     /**
848      *
849      */

850     public void collect(JRBubblePlot bubblePlot) {
851         addExpression(bubblePlot.getXAxisLabelExpression());
852         addExpression(bubblePlot.getYAxisLabelExpression());
853         
854     }
855
856     /**
857      *
858      */

859     public void collect(JRHighLowPlot highLowPlot)
860     {
861         addExpression(highLowPlot.getTimeAxisLabelExpression());
862         addExpression(highLowPlot.getValueAxisLabelExpression());
863     }
864
865     /**
866      *
867      */

868     public void collect(JRDataRange dataRange)
869     {
870         if (dataRange != null)
871         {
872             addExpression(dataRange.getLowExpression());
873             addExpression(dataRange.getHighExpression());
874         }
875     }
876     
877     /**
878      *
879      */

880     public void collect(JRMeterPlot meterPlot)
881     {
882         List JavaDoc intervals = meterPlot.getIntervals();
883         if (intervals != null)
884         {
885             Iterator JavaDoc iter = intervals.iterator();
886             while (iter.hasNext())
887             {
888                 JRMeterInterval interval = (JRMeterInterval)iter.next();
889                 collect(interval.getDataRange());
890             }
891         }
892         collect(meterPlot.getDataRange());
893     }
894
895     /**
896      *
897      */

898     public void collect(JRThermometerPlot thermometerPlot)
899     {
900         collect(thermometerPlot.getDataRange());
901         collect(thermometerPlot.getLowRange());
902         collect(thermometerPlot.getMediumRange());
903         collect(thermometerPlot.getHighRange());
904     }
905
906
907     /**
908      *
909      */

910     public void collect(JRHighLowDataset highLowDataset)
911     {
912         collect((JRElementDataset) highLowDataset);
913         
914         JRExpressionCollector collector = getCollector(highLowDataset);
915         collector.addExpression(highLowDataset.getSeriesExpression());
916         collector.addExpression(highLowDataset.getDateExpression());
917         collector.addExpression(highLowDataset.getHighExpression());
918         collector.addExpression(highLowDataset.getLowExpression());
919         collector.addExpression(highLowDataset.getOpenExpression());
920         collector.addExpression(highLowDataset.getCloseExpression());
921         collector.addExpression(highLowDataset.getVolumeExpression());
922         
923         collector.collectHyperlink(highLowDataset.getItemHyperlink());
924     }
925
926     /**
927      *
928      */

929     public void collect(JRCandlestickPlot candlestickPlot)
930     {
931         addExpression(candlestickPlot.getTimeAxisLabelExpression());
932         addExpression(candlestickPlot.getValueAxisLabelExpression());
933     }
934
935     
936     /**
937      * Collects expressions from a crosstab.
938      *
939      * @param crosstab the crosstab
940      */

941     public void collect(JRCrosstab crosstab)
942     {
943         collectElement(crosstab);
944         
945         createCrosstabId(crosstab);
946         
947         JRCrosstabDataset dataset = crosstab.getDataset();
948         collect(dataset);
949         
950         JRExpressionCollector datasetCollector = getCollector(dataset);
951         JRExpressionCollector crosstabCollector = getCollector(crosstab);
952         
953         crosstabCollector.collect(report.getDefaultStyle());
954         
955         addExpression(crosstab.getParametersMapExpression());
956         
957         JRCrosstabParameter[] parameters = crosstab.getParameters();
958         if (parameters != null)
959         {
960             for (int i = 0; i < parameters.length; i++)
961             {
962                 addExpression(parameters[i].getExpression());
963             }
964         }
965         
966         crosstabCollector.collect(crosstab.getHeaderCell());
967
968         JRCrosstabRowGroup[] rowGroups = crosstab.getRowGroups();
969         if (rowGroups != null)
970         {
971             for (int i = 0; i < rowGroups.length; i++)
972             {
973                 JRCrosstabRowGroup rowGroup = rowGroups[i];
974                 JRCrosstabBucket bucket = rowGroup.getBucket();
975                 datasetCollector.addExpression(bucket.getExpression());
976                 addExpression(bucket.getComparatorExpression());
977                 crosstabCollector.collect(rowGroup.getHeader());
978                 crosstabCollector.collect(rowGroup.getTotalHeader());
979             }
980         }
981         
982         JRCrosstabColumnGroup[] colGroups = crosstab.getColumnGroups();
983         if (colGroups != null)
984         {
985             for (int i = 0; i < colGroups.length; i++)
986             {
987                 JRCrosstabColumnGroup columnGroup = colGroups[i];
988                 datasetCollector.addExpression(columnGroup.getBucket().getExpression());
989                 addExpression(columnGroup.getBucket().getComparatorExpression());
990                 crosstabCollector.collect(columnGroup.getHeader());
991                 crosstabCollector.collect(columnGroup.getTotalHeader());
992             }
993         }
994         
995         JRCrosstabMeasure[] measures = crosstab.getMeasures();
996         if (measures != null)
997         {
998             for (int i = 0; i < measures.length; i++)
999             {
1000                datasetCollector.addExpression(measures[i].getValueExpression());
1001            }
1002        }
1003        
1004        crosstabCollector.collect(crosstab.getWhenNoDataCell());
1005        
1006        collectCrosstabCells(crosstab, crosstabCollector);
1007    }
1008
1009
1010    private void createCrosstabId(JRCrosstab crosstab)
1011    {
1012        crosstabIds.put(crosstab, new Integer JavaDoc(crosstabIds.size()));
1013    }
1014
1015
1016    private void collectCrosstabCells(JRCrosstab crosstab, JRExpressionCollector crosstabCollector)
1017    {
1018        if (crosstab instanceof JRDesignCrosstab)
1019        {
1020            List JavaDoc cellsList = ((JRDesignCrosstab) crosstab).getCellsList();
1021            
1022            if (cellsList != null)
1023            {
1024                for (Iterator JavaDoc iter = cellsList.iterator(); iter.hasNext();)
1025                {
1026                    JRCrosstabCell cell = (JRCrosstabCell) iter.next();
1027                    crosstabCollector.collect(cell.getContents());
1028                }
1029            }
1030        }
1031        else
1032        {
1033            JRCrosstabCell[][] cells = crosstab.getCells();
1034            if (cells != null)
1035            {
1036                for (int i = 0; i < cells.length; ++i)
1037                {
1038                    for (int j = 0; j < cells[i].length; j++)
1039                    {
1040                        if (cells[i][j] != null)
1041                        {
1042                            crosstabCollector.collect(cells[i][j].getContents());
1043                        }
1044                    }
1045                }
1046            }
1047        }
1048    }
1049
1050    
1051    /**
1052     * Collects expressions from a dataset.
1053     *
1054     * @param dataset the dataset
1055     * @return collected expressions
1056     */

1057    public Collection JavaDoc collect(JRDataset dataset)
1058    {
1059        JRExpressionCollector collector = getCollector(dataset);
1060        collector.collect(dataset.getParameters());
1061        collector.collect(dataset.getVariables());
1062        collector.collect(dataset.getGroups());
1063        
1064        collector.addExpression(dataset.getFilterExpression());
1065        
1066        return getExpressions(dataset);
1067    }
1068
1069    
1070    /**
1071     * Collects expressions from an element dataset.
1072     *
1073     * @param dataset the element dataset
1074     */

1075    protected void collect(JRElementDataset dataset)
1076    {
1077        collect(dataset.getDatasetRun());
1078        
1079        JRExpression incrementWhenExpression = dataset.getIncrementWhenExpression();
1080        if (incrementWhenExpression != null)
1081        {
1082            JRExpressionCollector datasetCollector = getCollector(dataset);
1083            datasetCollector.addExpression(incrementWhenExpression);
1084        }
1085    }
1086
1087
1088    private void collect(JRDatasetRun datasetRun)
1089    {
1090        if (datasetRun != null)
1091        {
1092            addExpression(datasetRun.getParametersMapExpression());
1093            addExpression(datasetRun.getConnectionExpression());
1094            addExpression(datasetRun.getDataSourceExpression());
1095            
1096            JRDatasetParameter[] parameters = datasetRun.getParameters();
1097            if (parameters != null && parameters.length > 0)
1098            {
1099                for (int i = 0; i < parameters.length; i++)
1100                {
1101                    addExpression(parameters[i].getExpression());
1102                }
1103            }
1104        }
1105    }
1106    
1107    
1108    protected void collect(JRCellContents cell)
1109    {
1110        if (cell != null)
1111        {
1112            collect(cell.getStyle());
1113            JRElement[] elements = cell.getElements();
1114            if (elements != null && elements.length > 0)
1115            {
1116                for(int i = 0; i < elements.length; i++)
1117                {
1118                    elements[i].collectExpressions(this);
1119                }
1120            }
1121        }
1122    }
1123    
1124    
1125    public void collect(JRFrame frame)
1126    {
1127        collectElement(frame);
1128        JRElement[] elements = frame.getElements();
1129        if (elements != null)
1130        {
1131            for (int i = 0; i < elements.length; i++)
1132            {
1133                elements[i].collectExpressions(this);
1134            }
1135        }
1136    }
1137}
1138
Popular Tags