KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRBaseFiller


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
29 /*
30  * Contributors:
31  * John Bindel - jbindel@users.sourceforge.net
32  */

33
34 package net.sf.jasperreports.engine.fill;
35
36 import java.net.URLStreamHandlerFactory JavaDoc;
37 import java.sql.Connection JavaDoc;
38 import java.text.Format JavaDoc;
39 import java.util.ArrayList JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.HashSet JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44 import java.util.ListIterator JavaDoc;
45 import java.util.Locale JavaDoc;
46 import java.util.Map JavaDoc;
47 import java.util.Set JavaDoc;
48 import java.util.TimeZone JavaDoc;
49
50 import net.sf.jasperreports.engine.JRAbstractScriptlet;
51 import net.sf.jasperreports.engine.JRBand;
52 import net.sf.jasperreports.engine.JRConstants;
53 import net.sf.jasperreports.engine.JRDataSource;
54 import net.sf.jasperreports.engine.JRDataset;
55 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
56 import net.sf.jasperreports.engine.JRException;
57 import net.sf.jasperreports.engine.JRExpression;
58 import net.sf.jasperreports.engine.JRGroup;
59 import net.sf.jasperreports.engine.JRParameter;
60 import net.sf.jasperreports.engine.JRPrintElement;
61 import net.sf.jasperreports.engine.JRPrintPage;
62 import net.sf.jasperreports.engine.JRReport;
63 import net.sf.jasperreports.engine.JRReportFont;
64 import net.sf.jasperreports.engine.JRRuntimeException;
65 import net.sf.jasperreports.engine.JRStyle;
66 import net.sf.jasperreports.engine.JRVirtualizer;
67 import net.sf.jasperreports.engine.JasperPrint;
68 import net.sf.jasperreports.engine.JasperReport;
69 import net.sf.jasperreports.engine.base.JRBasePrintPage;
70 import net.sf.jasperreports.engine.base.JRVirtualPrintPage;
71 import net.sf.jasperreports.engine.util.DefaultFormatFactory;
72 import net.sf.jasperreports.engine.util.FormatFactory;
73 import net.sf.jasperreports.engine.util.JRDataUtils;
74 import net.sf.jasperreports.engine.util.JRGraphEnvInitializer;
75 import net.sf.jasperreports.engine.util.JRResourcesUtil;
76 import net.sf.jasperreports.engine.util.JRStyledTextParser;
77
78
79 /**
80  * @author Teodor Danciu (teodord@users.sourceforge.net)
81  * @version $Id: JRBaseFiller.java 1500 2006-11-21 18:10:31 +0200 (Tue, 21 Nov 2006) teodord $
82  */

83 public abstract class JRBaseFiller implements JRDefaultStyleProvider, JRVirtualPrintPage.IdentityDataProvider//, JRDefaultFontProvider
84
{
85
86     /**
87      * Map class to be used for bound elements.
88      * <p/>
89      * Keeps print elements to fill elements maps.
90      * If per page element maps are used, such maps are kept per page.
91      *
92      * @author John Bindel
93      */

94     public class BoundElementMap
95     {
96         private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
97
98         private final Map JavaDoc map;
99
100         BoundElementMap()
101         {
102             map = new HashMap JavaDoc();
103         }
104
105         /**
106          * Keep track of the objects per page for our virtualizer.
107          */

108         public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value, JRPrintPage keyPage)
109         {
110             Map JavaDoc pageMap = (Map JavaDoc) map.get(keyPage);
111             if (pageMap == null)
112             {
113                 pageMap = new HashMap JavaDoc();
114                 map.put(keyPage, pageMap);
115             }
116
117             return pageMap.put(key, value);
118         }
119
120         /**
121          * If per page map is required, the entry will also be added for the
122          * current print page.
123          */

124         public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value)
125         {
126             if (isPerPageBoundElements)
127             {
128                 return put(key, value, fillContext.getPrintPage());
129             }
130
131             return map.put(key, value);
132         }
133
134         public void clear()
135         {
136             map.clear();
137         }
138
139         public Map JavaDoc getMap()
140         {
141             return map;
142         }
143
144         public Map JavaDoc getMap(JRPrintPage page)
145         {
146             return (Map JavaDoc) map.get(page);
147         }
148
149         public Map JavaDoc putMap(JRPrintPage page, Map JavaDoc valueMap)
150         {
151             return (Map JavaDoc) map.put(page, valueMap);
152         }
153     }
154
155     /**
156      *
157      */

158     protected JRBaseFiller parentFiller = null;
159
160     private JRStyledTextParser styledTextParser = new JRStyledTextParser();
161
162     /**
163      *
164      */

165     private boolean isInterrupted = false;
166
167     /**
168      *
169      */

170     protected String JavaDoc name = null;
171
172     protected int columnCount = 1;
173
174     protected byte printOrder = JRReport.PRINT_ORDER_VERTICAL;
175
176     protected int pageWidth = 0;
177
178     protected int pageHeight = 0;
179
180     protected byte orientation = JRReport.ORIENTATION_PORTRAIT;
181
182     protected byte whenNoDataType = JRReport.WHEN_NO_DATA_TYPE_NO_PAGES;
183
184     protected int columnWidth = 0;
185
186     protected int columnSpacing = 0;
187
188     protected int leftMargin = 0;
189
190     protected int rightMargin = 0;
191
192     protected int topMargin = 0;
193
194     protected int bottomMargin = 0;
195
196     protected boolean isTitleNewPage = false;
197
198     protected boolean isSummaryNewPage = false;
199
200     protected boolean isFloatColumnFooter = false;
201
202     /**
203      * the resource missing handling type
204      */

205     protected byte whenResourceMissingType = JRReport.WHEN_RESOURCE_MISSING_TYPE_NULL;
206
207     protected JRReportFont defaultFont = null;
208
209     protected JRReportFont[] fonts = null;
210
211     protected JRStyle defaultStyle = null;
212
213     protected JRStyle[] styles = null;
214
215     /**
216      * Main report dataset.
217      */

218     protected JRFillDataset mainDataset;
219
220     protected JRFillGroup[] groups = null;
221
222     protected JRFillBand missingFillBand = null;
223
224     protected JRFillBand background = null;
225
226     protected JRFillBand title = null;
227
228     protected JRFillBand pageHeader = null;
229
230     protected JRFillBand columnHeader = null;
231
232     protected JRFillBand detail = null;
233
234     protected JRFillBand columnFooter = null;
235
236     protected JRFillBand pageFooter = null;
237
238     protected JRFillBand lastPageFooter = null;
239
240     protected JRFillBand summary = null;
241
242     protected JRVirtualizer virtualizer = null;
243
244     protected ClassLoader JavaDoc reportClassLoader = null;
245
246     protected FormatFactory formatFactory = null;
247     
248     protected URLStreamHandlerFactory JavaDoc urlHandlerFactory;
249
250     protected Map JavaDoc loadedSubreports = null;
251
252     protected JRFillContext fillContext;
253
254     /**
255      * Bound element maps indexed by {@link JREvaluationTime JREvaluationTime} objects.
256      */

257     protected Map JavaDoc boundElements;
258
259     /**
260      *
261      */

262     protected JasperPrint jasperPrint = null;
263
264     protected JRPrintPage printPage = null;
265
266     protected int printPageStretchHeight = 0;
267
268     /**
269      * List of {@link JRFillBand JRFillBand} objects containing all bands of the
270      * report.
271      */

272     protected List JavaDoc bands;
273
274     /**
275      * Collection of subfillers
276      */

277     protected Set JavaDoc subfillers;
278
279     private List JavaDoc identityPages;
280
281     private Thread JavaDoc fillingThread;
282
283     protected JRCalculator calculator;
284
285     protected JRAbstractScriptlet scriptlet;
286
287     /**
288      * Map of datasets ({@link JRFillDataset JRFillDataset} objects} indexed by name.
289      */

290     protected Map JavaDoc datasetMap;
291
292     /**
293      * The report.
294      */

295     protected JasperReport jasperReport;
296
297     private boolean bandOverFlowAllowed;
298
299     protected boolean isPerPageBoundElements;
300
301     /**
302      *
303      */

304     protected Map JavaDoc dateFormatCache = new HashMap JavaDoc();
305     protected Map JavaDoc numberFormatCache = new HashMap JavaDoc();
306     
307     private JRSubreportRunner subreportRunner;
308
309
310     /**
311      *
312      */

313     protected boolean isCreatingNewPage = false;
314     protected boolean isNewPage = false;
315     protected boolean isNewColumn = false;
316     protected boolean isNewGroup = true;
317
318     protected int columnIndex = 0;
319
320     protected int offsetX = 0;
321     protected int offsetY = 0;
322     protected int columnHeaderOffsetY = 0;
323     protected int columnFooterOffsetY = 0;
324     protected int lastPageColumnFooterOffsetY = 0;
325
326     protected boolean isLastPageFooter = false;
327
328     
329     /**
330      *
331      */

332     protected JRBaseFiller(JasperReport jasperReport, JREvaluator initEvaluator, JRBaseFiller parentFiller) throws JRException
333     {
334         JRGraphEnvInitializer.initializeGraphEnv();
335
336         this.jasperReport = jasperReport;
337
338         /* */
339         this.parentFiller = parentFiller;
340
341         if (parentFiller == null)
342         {
343             fillContext = new JRFillContext();
344         }
345         else
346         {
347             fillContext = parentFiller.fillContext;
348         }
349
350         /* */
351         name = jasperReport.getName();
352         columnCount = jasperReport.getColumnCount();
353         printOrder = jasperReport.getPrintOrder();
354         pageWidth = jasperReport.getPageWidth();
355         pageHeight = jasperReport.getPageHeight();
356         orientation = jasperReport.getOrientation();
357         whenNoDataType = jasperReport.getWhenNoDataType();
358         columnWidth = jasperReport.getColumnWidth();
359         columnSpacing = jasperReport.getColumnSpacing();
360         leftMargin = jasperReport.getLeftMargin();
361         rightMargin = jasperReport.getRightMargin();
362         topMargin = jasperReport.getTopMargin();
363         bottomMargin = jasperReport.getBottomMargin();
364         isTitleNewPage = jasperReport.isTitleNewPage();
365         isSummaryNewPage = jasperReport.isSummaryNewPage();
366         isFloatColumnFooter = jasperReport.isFloatColumnFooter();
367         whenResourceMissingType = jasperReport.getWhenResourceMissingType();
368
369         jasperPrint = new JasperPrint();
370
371         if (initEvaluator == null)
372         {
373             calculator = JRFillDataset.createCalculator(jasperReport, jasperReport.getMainDataset());
374         }
375         else
376         {
377             calculator = new JRCalculator(initEvaluator);
378         }
379
380         /* */
381         JRFillObjectFactory factory = new JRFillObjectFactory(this);
382
383         /* */
384         defaultFont = factory.getReportFont(jasperReport.getDefaultFont());
385
386         /* */
387         JRReportFont[] jrFonts = jasperReport.getFonts();
388         if (jrFonts != null && jrFonts.length > 0)
389         {
390             fonts = new JRReportFont[jrFonts.length];
391             for (int i = 0; i < fonts.length; i++)
392             {
393                 fonts[i] = factory.getReportFont(jrFonts[i]);
394             }
395         }
396
397         createDatasets(factory);
398         mainDataset = factory.getDataset(jasperReport.getMainDataset());
399         groups = mainDataset.groups;
400
401         /* */
402         defaultStyle = factory.getStyle(jasperReport.getDefaultStyle());
403
404         /* */
405         JRStyle[] jrStyles = jasperReport.getStyles();
406         if (jrStyles != null && jrStyles.length > 0)
407         {
408             styles = new JRStyle[jrStyles.length];
409             for (int i = 0; i < styles.length; i++)
410             {
411                 styles[i] = factory.getStyle(jrStyles[i]);
412             }
413         }
414
415         /* */
416         missingFillBand = factory.getBand(null);
417         background = factory.getBand(jasperReport.getBackground());
418         title = factory.getBand(jasperReport.getTitle());
419         pageHeader = factory.getBand(jasperReport.getPageHeader());
420         columnHeader = factory.getBand(jasperReport.getColumnHeader());
421         detail = factory.getBand(jasperReport.getDetail());
422         columnFooter = factory.getBand(jasperReport.getColumnFooter());
423         pageFooter = factory.getBand(jasperReport.getPageFooter());
424         lastPageFooter = factory.getBand(jasperReport.getLastPageFooter());
425         if (isEmpty(jasperReport.getSummary()))
426         {
427             summary = missingFillBand;
428         }
429         else
430         {
431             summary = factory.getBand(jasperReport.getSummary());
432         }
433
434         mainDataset.initElementDatasets(factory);
435         initDatasets(factory);
436
437         mainDataset.checkVariableCalculationReqs(factory);
438
439         /* */
440         mainDataset.setCalculator(calculator);
441         mainDataset.initCalculator();
442
443         initBands();
444     }
445
446
447     /**
448      * Returns the report parameters indexed by name.
449      *
450      * @return the report parameters map
451      */

452     protected Map JavaDoc getParametersMap()
453     {
454         return mainDataset.parametersMap;
455     }
456
457
458     /**
459      * Returns the report fields indexed by name.
460      *
461      * @return the report fields map
462      */

463     protected Map JavaDoc getFieldsMap()
464     {
465         return mainDataset.fieldsMap;
466     }
467
468
469     /**
470      * Returns the report variables indexed by name.
471      *
472      * @return the report variables map
473      */

474     protected Map JavaDoc getVariablesMap()
475     {
476         return mainDataset.variablesMap;
477     }
478
479
480     /**
481      * Returns a report variable.
482      *
483      * @param variableName the variable name
484      * @return the variable
485      */

486     protected JRFillVariable getVariable(String JavaDoc variableName)
487     {
488         return (JRFillVariable) mainDataset.variablesMap.get(variableName);
489     }
490
491
492     /**
493      * Returns a report field.
494      *
495      * @param fieldName the field name
496      * @return the field
497      */

498     protected JRFillField getField(String JavaDoc fieldName)
499     {
500         return (JRFillField) mainDataset.fieldsMap.get(fieldName);
501     }
502
503     private void initBands()
504     {
505         bands = new ArrayList JavaDoc(8 + (groups == null ? 0 : (2 * groups.length)));
506         bands.add(title);
507         bands.add(summary);
508         bands.add(pageHeader);
509         bands.add(pageFooter);
510         bands.add(lastPageFooter);
511         bands.add(columnHeader);
512         bands.add(columnFooter);
513         bands.add(detail);
514
515         if (groups != null && groups.length > 0)
516         {
517             for (int i = 0; i < groups.length; i++)
518             {
519                 JRFillGroup group = groups[i];
520                 bands.add(group.getGroupHeader());
521                 bands.add(group.getGroupFooter());
522             }
523         }
524
525         initBandsNowEvaluationTimes();
526     }
527
528
529     private void initBandsNowEvaluationTimes()
530     {
531         JREvaluationTime[] groupEvaluationTimes;
532         if (groups == null)
533         {
534             groupEvaluationTimes = new JREvaluationTime[0];
535         }
536         else
537         {
538             groupEvaluationTimes = new JREvaluationTime[groups.length];
539             for (int i = 0; i < groups.length; i++)
540             {
541                 groupEvaluationTimes[i] = JREvaluationTime.getGroupEvaluationTime(groups[i].getName());
542             }
543
544             for (int i = 0; i < groups.length; i++)
545             {
546                 JRGroup group = groups[i];
547                 JRFillBand footer = (JRFillBand) group.getGroupFooter();
548
549                 for (int j = i; j < groupEvaluationTimes.length; ++j)
550                 {
551                     footer.addNowEvaluationTime(groupEvaluationTimes[j]);
552                 }
553             }
554         }
555
556         columnFooter.addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_COLUMN);
557
558         pageFooter.addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_COLUMN);
559         pageFooter.addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_PAGE);
560
561         summary.addNowEvaluationTimes(groupEvaluationTimes);
562     }
563
564
565     /**
566      *
567      */

568     public JRStyledTextParser getStyledTextParser()
569     {
570         return styledTextParser;
571     }
572
573     /**
574      *
575      */

576     public JasperPrint getJasperPrint()
577     {
578         return jasperPrint;
579     }
580
581     /**
582      *
583      */

584     public JRReportFont getDefaultFont()
585     {
586         return defaultFont;
587     }
588
589     /**
590      *
591      */

592     public JRStyle getDefaultStyle()
593     {
594         return defaultStyle;
595     }
596
597     /**
598      *
599      */

600     protected boolean isSubreport()
601     {
602         return (parentFiller != null);
603     }
604
605     /**
606      *
607      */

608     protected boolean isInterrupted()
609     {
610         return (isInterrupted || (parentFiller != null && parentFiller.isInterrupted()));
611     }
612
613     /**
614      *
615      */

616     protected void setInterrupted(boolean isInterrupted)
617     {
618         this.isInterrupted = isInterrupted;
619     }
620
621     /**
622      *
623      */

624     protected JRPrintPage getCurrentPage()
625     {
626         return printPage;
627     }
628
629     /**
630      *
631      */

632     protected JRReportFont[] getFonts()
633     {
634         return fonts;
635     }
636
637     /**
638      *
639      */

640     protected int getCurrentPageStretchHeight()
641     {
642         return printPageStretchHeight;
643     }
644
645     /**
646      *
647      */

648     protected abstract void setPageHeight(int pageHeight);
649
650
651     public JasperPrint fill(Map JavaDoc parameterValues, Connection JavaDoc conn) throws JRException
652     {
653         if (parameterValues == null)
654         {
655             parameterValues = new HashMap JavaDoc();
656         }
657
658         setConnectionParameterValue(parameterValues, conn);
659
660         return fill(parameterValues);
661     }
662
663
664     protected void setConnectionParameterValue(Map JavaDoc parameterValues, Connection JavaDoc conn)
665     {
666         mainDataset.setConnectionParameterValue(parameterValues, conn);
667     }
668
669
670     public JasperPrint fill(Map JavaDoc parameterValues, JRDataSource ds) throws JRException
671     {
672         if (parameterValues == null)
673         {
674             parameterValues = new HashMap JavaDoc();
675         }
676
677         setDatasourceParameterValue(parameterValues, ds);
678
679         return fill(parameterValues);
680     }
681
682
683     protected void setDatasourceParameterValue(Map JavaDoc parameterValues, JRDataSource ds)
684     {
685         mainDataset.setDatasourceParameterValue(parameterValues, ds);
686     }
687
688
689     public JasperPrint fill(Map JavaDoc parameterValues) throws JRException
690     {
691         if (parameterValues == null)
692         {
693             parameterValues = new HashMap JavaDoc();
694         }
695
696         fillingThread = Thread.currentThread();
697         boolean urlHandlerFactorySet = false;
698         boolean classLoaderSet = false;
699         try
700         {
701             /* */
702             setParameters(parameterValues);
703
704             classLoaderSet = setClassLoader(parameterValues);
705             urlHandlerFactorySet = setUrlHandlerFactory(parameterValues);
706
707             if (parentFiller != null)
708             {
709                 parentFiller.registerSubfiller(this);
710             }
711
712             jasperPrint.setName(name);
713             jasperPrint.setPageWidth(pageWidth);
714             jasperPrint.setPageHeight(pageHeight);
715             jasperPrint.setOrientation(orientation);
716
717             jasperPrint.setDefaultFont(defaultFont);
718             
719             jasperPrint.setFormatFactoryClass(jasperReport.getFormatFactoryClass());
720             jasperPrint.setLocaleCode(JRDataUtils.getLocaleCode(getLocale()));
721             jasperPrint.setTimeZoneId(JRDataUtils.getTimeZoneId(getTimeZone()));
722
723             /* */
724             if (fonts != null && fonts.length > 0)
725             {
726                 for (int i = 0; i < fonts.length; i++)
727                 {
728                     jasperPrint.addFont(fonts[i], true);
729                 }
730             }
731
732             jasperPrint.setDefaultStyle(defaultStyle);
733
734             /* */
735             if (styles != null && styles.length > 0)
736             {
737                 for (int i = 0; i < styles.length; i++)
738                 {
739                     jasperPrint.addStyle(styles[i], true);
740                 }
741             }
742
743             loadedSubreports = new HashMap JavaDoc();
744
745             createBoundElemementMaps();
746
747             /* */
748             mainDataset.start();
749
750             /* */
751             fillReport();
752
753             // add consolidates styles as normal styles in the print object
754
// for (Iterator it = consolidatedStyles.values().iterator(); it.hasNext();)
755
// {
756
// jasperPrint.addStyle((JRStyle) it.next());
757
// }
758

759             return jasperPrint;
760         }
761         finally
762         {
763             mainDataset.closeDatasource();
764
765             if (parentFiller != null)
766             {
767                 parentFiller.unregisterSubfiller(this);
768             }
769
770             fillingThread = null;
771
772             //kill the subreport filler threads
773
killSubfillerThreads();
774             
775             if (classLoaderSet)
776             {
777                 JRResourcesUtil.resetClassLoader();
778             }
779
780             if (urlHandlerFactorySet)
781             {
782                 JRResourcesUtil.resetThreadURLHandlerFactory();
783             }
784         }
785     }
786
787
788     private void createBoundElemementMaps()
789     {
790         boundElements = new HashMap JavaDoc();
791
792         createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_REPORT);
793         createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_PAGE);
794         createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_COLUMN);
795
796         if (groups != null)
797         {
798             for (int i = 0; i < groups.length; i++)
799             {
800                 createBoundElementMaps(JREvaluationTime.getGroupEvaluationTime(groups[i].getName()));
801             }
802         }
803
804         for (Iterator JavaDoc i = bands.iterator(); i.hasNext();)
805         {
806             JRFillBand band = (JRFillBand) i.next();
807             createBoundElementMaps(JREvaluationTime.getBandEvaluationTime(band));
808         }
809     }
810
811
812     private void createBoundElementMaps(JREvaluationTime evaluationTime)
813     {
814         BoundElementMap boundElementsMap = new BoundElementMap();
815         boundElements.put(evaluationTime, boundElementsMap);
816     }
817
818
819     private void killSubfillerThreads()
820     {
821         if (subfillers != null && !subfillers.isEmpty())
822         {
823             for (Iterator JavaDoc it = subfillers.iterator(); it.hasNext();)
824             {
825                 JRBaseFiller subfiller = (JRBaseFiller) it.next();
826                 if (subfiller.fillingThread != null)
827                 {
828                     subfiller.fillingThread.interrupt();
829                 }
830             }
831         }
832     }
833
834
835     /**
836      *
837      */

838     protected abstract void fillReport() throws JRException;
839
840     /**
841      *
842      */

843     protected void setParameters(Map JavaDoc parameterValues) throws JRException
844     {
845         if (!isSubreport())
846         {
847             /* Virtualizer */
848             virtualizer = (JRVirtualizer) parameterValues.get(JRParameter.REPORT_VIRTUALIZER);
849
850             if (virtualizer != null)
851             {
852                 fillContext.setUsingVirtualizer(true);
853                 fillContext.setPerPageBoundElements(true);
854                 JRVirtualizationContext.register(fillContext.getVirtualizationContext(), jasperPrint);
855             }
856         }
857
858         isPerPageBoundElements = fillContext.isPerPageBoundElements();
859
860         setFormatFactory(parameterValues);
861         
862         setIgnorePagination(parameterValues);
863
864         mainDataset.setParameterValues(parameterValues);
865         
866         this.scriptlet = mainDataset.scriptlet;
867         
868         if (!isSubreport())
869         {
870             fillContext.setMasterFormatFactory(getFormatFactory());
871             fillContext.setMasterLocale(getLocale());
872             fillContext.setMasterTimeZone(getTimeZone());
873         }
874     }
875
876
877     private void setFormatFactory(Map JavaDoc parameterValues)
878     {
879         formatFactory = (FormatFactory)parameterValues.get(JRParameter.REPORT_FORMAT_FACTORY);
880         if (formatFactory == null)
881         {
882             formatFactory = DefaultFormatFactory.createFormatFactory(jasperReport.getFormatFactoryClass());
883             parameterValues.put(JRParameter.REPORT_FORMAT_FACTORY, formatFactory);
884         }
885     }
886
887
888     private boolean setClassLoader(Map JavaDoc parameterValues)
889     {
890         reportClassLoader = (ClassLoader JavaDoc) parameterValues.get(JRParameter.REPORT_CLASS_LOADER);
891         boolean setClassLoader = reportClassLoader != null;
892         if (setClassLoader)
893         {
894             JRResourcesUtil.setThreadClassLoader(reportClassLoader);
895         }
896         return setClassLoader;
897     }
898
899
900     private boolean setUrlHandlerFactory(Map JavaDoc parameterValues)
901     {
902         urlHandlerFactory = (URLStreamHandlerFactory JavaDoc) parameterValues.get(JRParameter.REPORT_URL_HANDLER_FACTORY);
903         boolean setUrlHandlerFactory = urlHandlerFactory != null;
904         if (setUrlHandlerFactory)
905         {
906             JRResourcesUtil.setThreadURLHandlerFactory(urlHandlerFactory);
907         }
908         return setUrlHandlerFactory;
909     }
910
911
912     private void setIgnorePagination(Map JavaDoc parameterValues)
913     {
914         if (parentFiller == null)//pagination is driven by the master
915
{
916             Boolean JavaDoc isIgnorePaginationParam = (Boolean JavaDoc) parameterValues.get(JRParameter.IS_IGNORE_PAGINATION);
917             if (isIgnorePaginationParam != null)
918             {
919                 fillContext.setIgnorePagination(isIgnorePaginationParam.booleanValue());
920             }
921             else
922             {
923                 boolean ignorePagination = jasperReport.isIgnorePagination();
924                 fillContext.setIgnorePagination(ignorePagination);
925                 parameterValues.put(JRParameter.IS_IGNORE_PAGINATION, ignorePagination ? Boolean.TRUE : Boolean.FALSE);
926             }
927         }
928         else
929         {