KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseReport


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.base;
29
30 import java.io.Serializable JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Set JavaDoc;
34
35 import net.sf.jasperreports.engine.JRBand;
36 import net.sf.jasperreports.engine.JRConstants;
37 import net.sf.jasperreports.engine.JRDataset;
38 import net.sf.jasperreports.engine.JRExpressionCollector;
39 import net.sf.jasperreports.engine.JRField;
40 import net.sf.jasperreports.engine.JRGroup;
41 import net.sf.jasperreports.engine.JRParameter;
42 import net.sf.jasperreports.engine.JRPropertiesMap;
43 import net.sf.jasperreports.engine.JRQuery;
44 import net.sf.jasperreports.engine.JRReport;
45 import net.sf.jasperreports.engine.JRReportFont;
46 import net.sf.jasperreports.engine.JRSortField;
47 import net.sf.jasperreports.engine.JRStyle;
48 import net.sf.jasperreports.engine.JRVariable;
49
50
51 /**
52  * @author Teodor Danciu (teodord@users.sourceforge.net)
53  * @version $Id: JRBaseReport.java 1485 2006-11-14 20:23:17 +0200 (Tue, 14 Nov 2006) teodord $
54  */

55 public class JRBaseReport implements JRReport, Serializable JavaDoc
56 {
57
58     
59     /**
60      *
61      */

62     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
63
64     /**
65      *
66      */

67     protected String JavaDoc name = null;
68     protected String JavaDoc language = LANGUAGE_JAVA;
69     protected int columnCount = 1;
70     protected byte printOrder = PRINT_ORDER_VERTICAL;
71     protected int pageWidth = 595;
72     protected int pageHeight = 842;
73     protected byte orientation = ORIENTATION_PORTRAIT;
74     protected byte whenNoDataType = WHEN_NO_DATA_TYPE_NO_PAGES;
75     protected int columnWidth = 555;
76     protected int columnSpacing = 0;
77     protected int leftMargin = 20;
78     protected int rightMargin = 20;
79     protected int topMargin = 30;
80     protected int bottomMargin = 30;
81     protected boolean isTitleNewPage = false;
82     protected boolean isSummaryNewPage = false;
83     protected boolean isFloatColumnFooter = false;
84     protected boolean ignorePagination = false;
85
86     /**
87      *
88      */

89     protected String JavaDoc formatFactoryClass = null;
90
91     /**
92      *
93      */

94     protected Set JavaDoc importsSet = null;
95     protected JRReportFont defaultFont = null;
96     protected JRReportFont[] fonts = null;
97     protected JRStyle defaultStyle = null;
98     protected JRStyle[] styles = null;
99     
100     /**
101      * The main dataset of the report.
102      */

103     protected JRDataset mainDataset;
104     
105     /**
106      * Sub datasets of the report.
107      */

108     protected JRDataset[] datasets;
109     
110     protected JRBand background = null;
111     protected JRBand title = null;
112     protected JRBand pageHeader = null;
113     protected JRBand columnHeader = null;
114     protected JRBand detail = null;
115     protected JRBand columnFooter = null;
116     protected JRBand pageFooter = null;
117     protected JRBand lastPageFooter = null;
118     protected JRBand summary = null;
119
120     
121     /**
122      *
123      */

124     public JRBaseReport()
125     {
126     }
127     
128     /**
129      * Constructs a copy of a report.
130      *
131      * @param report the original report
132      * @param expressionCollector expression collector used to provide new expression IDs
133      */

134     public JRBaseReport(JRReport report, JRExpressionCollector expressionCollector)
135     {
136         /* */
137         name = report.getName();
138         language = report.getLanguage();
139         columnCount = report.getColumnCount();
140         printOrder = report.getPrintOrder();
141         pageWidth = report.getPageWidth();
142         pageHeight = report.getPageHeight();
143         orientation = report.getOrientation();
144         whenNoDataType = report.getWhenNoDataType();
145         columnWidth = report.getColumnWidth();
146         columnSpacing = report.getColumnSpacing();
147         leftMargin = report.getLeftMargin();
148         rightMargin = report.getRightMargin();
149         topMargin = report.getTopMargin();
150         bottomMargin = report.getBottomMargin();
151         isTitleNewPage = report.isTitleNewPage();
152         isSummaryNewPage = report.isSummaryNewPage();
153         isFloatColumnFooter = report.isFloatColumnFooter();
154         ignorePagination = report.isIgnorePagination();
155
156         formatFactoryClass = report.getFormatFactoryClass();
157         
158         /* */
159         String JavaDoc[] imports = report.getImports();
160         if (imports != null && imports.length > 0)
161         {
162             importsSet = new HashSet JavaDoc(imports.length);
163             importsSet.addAll(Arrays.asList(imports));
164         }
165
166         /* */
167         JRBaseObjectFactory factory = new JRBaseObjectFactory(this, expressionCollector);
168         
169         /* */
170         defaultFont = factory.getReportFont(report.getDefaultFont());
171
172         /* */
173         JRReportFont[] jrFonts = report.getFonts();
174         if (jrFonts != null && jrFonts.length > 0)
175         {
176             fonts = new JRReportFont[jrFonts.length];
177             for(int i = 0; i < fonts.length; i++)
178             {
179                 fonts[i] = factory.getReportFont(jrFonts[i]);
180             }
181         }
182
183         /* */
184         defaultStyle = factory.getStyle(report.getDefaultStyle());
185
186         /* */
187         JRStyle[] jrStyles = report.getStyles();
188         if (jrStyles != null && jrStyles.length > 0)
189         {
190             styles = new JRStyle[jrStyles.length];
191             for(int i = 0; i < styles.length; i++)
192             {
193                 styles[i] = factory.getStyle(jrStyles[i]);
194             }
195         }
196         
197         mainDataset = factory.getDataset(report.getMainDataset());
198         
199         JRDataset[] datasetArray = report.getDatasets();
200         if (datasetArray != null && datasetArray.length > 0)
201         {
202             datasets = new JRDataset[datasetArray.length];
203             for (int i = 0; i < datasets.length; i++)
204             {
205                 datasets[i] = factory.getDataset(datasetArray[i]);
206             }
207         }
208
209         background = factory.getBand(report.getBackground());
210         title = factory.getBand(report.getTitle());
211         pageHeader = factory.getBand(report.getPageHeader());
212         columnHeader = factory.getBand(report.getColumnHeader());
213         detail = factory.getBand(report.getDetail());
214         columnFooter = factory.getBand(report.getColumnFooter());
215         pageFooter = factory.getBand(report.getPageFooter());
216         lastPageFooter = factory.getBand(report.getLastPageFooter());
217         summary = factory.getBand(report.getSummary());
218     }
219
220     
221     public JRBaseReport(JRReport report)
222     {
223         this(report, null);
224     }
225
226     
227     /**
228      *
229      */

230     public String JavaDoc getName()
231     {
232         return name;
233     }
234
235     /**
236      *
237      */

238     public String JavaDoc getLanguage()
239     {
240         return language;
241     }
242         
243     /**
244      *
245      */

246     public int getColumnCount()
247     {
248         return columnCount;
249     }
250         
251     /**
252      *
253      */

254     public byte getPrintOrder()
255     {
256         return printOrder;
257     }
258         
259     /**
260      *
261      */

262     public int getPageWidth()
263     {
264         return pageWidth;
265     }
266         
267     /**
268      *
269      */

270     public int getPageHeight()
271     {
272         return pageHeight;
273     }
274         
275     /**
276      *
277      */

278     public byte getOrientation()
279     {
280         return orientation;
281     }
282         
283     /**
284      *
285      */

286     public byte getWhenNoDataType()
287     {
288         return whenNoDataType;
289     }
290         
291     /**
292      *
293      */

294     public void setWhenNoDataType(byte whenNoDataType)
295     {
296         this.whenNoDataType = whenNoDataType;
297     }
298
299     /**
300      *
301      */

302     public int getColumnWidth()
303     {
304         return columnWidth;
305     }
306         
307     /**
308      *
309      */

310     public int getColumnSpacing()
311     {
312         return columnSpacing;
313     }
314         
315     /**
316      *
317      */

318     public int getLeftMargin()
319     {
320         return leftMargin;
321     }
322         
323     /**
324      *
325      */

326     public int getRightMargin()
327     {
328         return rightMargin;
329     }
330         
331     /**
332      *
333      */

334     public int getTopMargin()
335     {
336         return topMargin;
337     }
338         
339     /**
340      *
341      */

342     public int getBottomMargin()
343     {
344         return bottomMargin;
345     }
346         
347     /**
348      *
349      */

350     public boolean isTitleNewPage()
351     {
352         return isTitleNewPage;
353     }
354         
355     /**
356      *
357      */

358     public boolean isSummaryNewPage()
359     {
360         return isSummaryNewPage;
361     }
362         
363     /**
364      *
365      */

366     public boolean isFloatColumnFooter()
367     {
368         return isFloatColumnFooter;
369     }
370         
371     /**
372      *
373      */

374     public String JavaDoc getScriptletClass()
375     {
376         return mainDataset.getScriptletClass();
377     }
378
379     /**
380      *
381      */

382     public String JavaDoc getFormatFactoryClass()
383     {
384         return formatFactoryClass;
385     }
386
387     /**
388      *
389      */

390     public String JavaDoc getResourceBundle()
391     {
392         return mainDataset.getResourceBundle();
393     }
394
395     /**
396      *
397      */

398     public String JavaDoc[] getPropertyNames()
399     {
400         return mainDataset.getPropertiesMap().getPropertyNames();
401     }
402
403     /**
404      *
405      */

406     public String JavaDoc getProperty(String JavaDoc propName)
407     {
408         return mainDataset.getPropertiesMap().getProperty(propName);
409     }
410
411     /**
412      *
413      */

414     public void setProperty(String JavaDoc propName, String JavaDoc value)
415     {
416         mainDataset.getPropertiesMap().setProperty(propName, value);
417     }
418
419     /**
420      *
421      */

422     public void removeProperty(String JavaDoc propName)
423     {
424         mainDataset.getPropertiesMap().removeProperty(propName);
425     }
426
427     /**
428      *
429      */

430     public String JavaDoc[] getImports()
431     {
432         if (importsSet != null)
433         {
434             return (String JavaDoc[])importsSet.toArray(new String JavaDoc[importsSet.size()]);
435         }
436         return null;
437     }
438
439     /**
440      * @deprecated
441      */

442     public JRReportFont getDefaultFont()
443     {
444         return defaultFont;
445     }
446
447     /**
448      * @deprecated
449      */

450     public JRReportFont[] getFonts()
451     {
452         return fonts;
453     }
454
455     /**
456      *
457      */

458     public JRStyle getDefaultStyle()
459     {
460         return defaultStyle;
461     }
462
463     /**
464      *
465      */

466     public JRStyle[] getStyles()
467     {
468         return styles;
469     }
470
471     /**
472      * Gets an array of report parameters (including built-in ones).
473      */

474     public JRParameter[] getParameters()
475     {
476         return mainDataset.getParameters();
477     }
478
479     /**
480      *
481      */

482     public JRQuery getQuery()
483     {
484         return mainDataset.getQuery();
485     }
486
487     /**
488      * Gets an array of report fields.
489      */

490     public JRField[] getFields()
491     {
492         return mainDataset.getFields();
493     }
494
495     /**
496      * Gets an array of sort report fields.
497      */

498     public JRSortField[] getSortFields()
499     {
500         return mainDataset.getSortFields();
501     }
502
503     /**
504      * Gets an array of report variables.
505      */

506     public JRVariable[] getVariables()
507     {
508         return mainDataset.getVariables();
509     }
510
511     /**
512      *
513      */

514     public JRGroup[] getGroups()
515     {
516         return mainDataset.getGroups();
517     }
518
519     /**
520      *
521      */

522     public JRBand getBackground()
523     {
524         return background;
525     }
526
527     /**
528      *
529      */

530     public JRBand getTitle()
531     {
532         return title;
533     }
534
535     /**
536      *
537      */

538     public JRBand getPageHeader()
539     {
540         return pageHeader;
541     }
542
543     /**
544      *
545      */

546     public JRBand getColumnHeader()
547     {
548         return columnHeader;
549     }
550
551     /**
552      *
553      */

554     public JRBand getDetail()
555     {
556         return detail;
557     }
558
559     /**
560      *
561      */

562     public JRBand getColumnFooter()
563     {
564         return columnFooter;
565     }
566
567     /**
568      *
569      */

570     public JRBand getPageFooter()
571     {
572         return pageFooter;
573     }
574
575     /**
576      *
577      */

578     public JRBand getLastPageFooter()
579     {
580         return lastPageFooter;
581     }
582
583     /**
584      *
585      */

586     public JRBand getSummary()
587     {
588         return summary;
589     }
590
591     
592     /**
593      *
594      */

595     public byte getWhenResourceMissingType()
596     {
597         return mainDataset.getWhenResourceMissingType();
598     }
599         
600     /**
601      *
602      */

603     public void setWhenResourceMissingType(byte whenResourceMissingType)
604     {
605         mainDataset.setWhenResourceMissingType(whenResourceMissingType);
606     }
607
608     
609     public JRDataset getMainDataset()
610     {
611         return mainDataset;
612     }
613
614     
615     public JRDataset[] getDatasets()
616     {
617         return datasets;
618     }
619
620     
621     public boolean isIgnorePagination()
622     {
623         return ignorePagination;
624     }
625
626     public JRPropertiesMap getPropertiesMap()
627     {
628         return mainDataset.getPropertiesMap();
629     }
630 }
631
Popular Tags