Source Code Cross Referenced for JRBaseFiller.java in  » Report » jasperreports-2.0.1 » net » sf » jasperreports » engine » fill » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jasperreports 2.0.1 » net.sf.jasperreports.engine.fill 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
0029:        /*
0030:         * Contributors:
0031:         * John Bindel - jbindel@users.sourceforge.net
0032:         */
0033:
0034:        package net.sf.jasperreports.engine.fill;
0035:
0036:        import java.net.URLStreamHandlerFactory;
0037:        import java.sql.Connection;
0038:        import java.text.Format;
0039:        import java.util.ArrayList;
0040:        import java.util.Collection;
0041:        import java.util.HashMap;
0042:        import java.util.HashSet;
0043:        import java.util.Iterator;
0044:        import java.util.List;
0045:        import java.util.ListIterator;
0046:        import java.util.Locale;
0047:        import java.util.Map;
0048:        import java.util.Set;
0049:        import java.util.TimeZone;
0050:
0051:        import net.sf.jasperreports.engine.JRAbstractScriptlet;
0052:        import net.sf.jasperreports.engine.JRConstants;
0053:        import net.sf.jasperreports.engine.JRDataSource;
0054:        import net.sf.jasperreports.engine.JRDataset;
0055:        import net.sf.jasperreports.engine.JRDefaultStyleProvider;
0056:        import net.sf.jasperreports.engine.JRException;
0057:        import net.sf.jasperreports.engine.JRExpression;
0058:        import net.sf.jasperreports.engine.JRGroup;
0059:        import net.sf.jasperreports.engine.JRParameter;
0060:        import net.sf.jasperreports.engine.JRPrintElement;
0061:        import net.sf.jasperreports.engine.JRPrintPage;
0062:        import net.sf.jasperreports.engine.JRReport;
0063:        import net.sf.jasperreports.engine.JRReportFont;
0064:        import net.sf.jasperreports.engine.JRReportTemplate;
0065:        import net.sf.jasperreports.engine.JRRuntimeException;
0066:        import net.sf.jasperreports.engine.JRStyle;
0067:        import net.sf.jasperreports.engine.JRStyleSetter;
0068:        import net.sf.jasperreports.engine.JRTemplate;
0069:        import net.sf.jasperreports.engine.JRTemplateReference;
0070:        import net.sf.jasperreports.engine.JRVirtualizer;
0071:        import net.sf.jasperreports.engine.JasperPrint;
0072:        import net.sf.jasperreports.engine.JasperReport;
0073:        import net.sf.jasperreports.engine.base.JRBasePrintPage;
0074:        import net.sf.jasperreports.engine.base.JRVirtualPrintPage;
0075:        import net.sf.jasperreports.engine.util.DefaultFormatFactory;
0076:        import net.sf.jasperreports.engine.util.FormatFactory;
0077:        import net.sf.jasperreports.engine.util.JRDataUtils;
0078:        import net.sf.jasperreports.engine.util.JRGraphEnvInitializer;
0079:        import net.sf.jasperreports.engine.util.JRProperties;
0080:        import net.sf.jasperreports.engine.util.JRResourcesUtil;
0081:        import net.sf.jasperreports.engine.util.JRStyledTextParser;
0082:
0083:        import org.apache.commons.logging.Log;
0084:        import org.apache.commons.logging.LogFactory;
0085:
0086:        /**
0087:         * @author Teodor Danciu (teodord@users.sourceforge.net)
0088:         * @version $Id: JRBaseFiller.java 1828 2007-08-24 13:58:43Z teodord $
0089:         */
0090:        public abstract class JRBaseFiller implements  JRDefaultStyleProvider,
0091:                JRVirtualPrintPage.IdentityDataProvider//, JRDefaultFontProvider
0092:        {
0093:
0094:            private static final Log log = LogFactory
0095:                    .getLog(JRBaseFiller.class);
0096:
0097:            private static final String PROPERTIES_PRINT_TRANSFER_PREFIX = "net.sf.jasperreports.print.transfer.";
0098:
0099:            /**
0100:             * Map class to be used for bound elements.
0101:             * <p/>
0102:             * Keeps print elements to fill elements maps.
0103:             * If per page element maps are used, such maps are kept per page.
0104:             *
0105:             * @author John Bindel
0106:             */
0107:            public class BoundElementMap {
0108:                private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
0109:
0110:                private final Map map;
0111:
0112:                BoundElementMap() {
0113:                    map = new HashMap();
0114:                }
0115:
0116:                /**
0117:                 * Keep track of the objects per page for our virtualizer.
0118:                 */
0119:                public Object put(Object key, Object value, JRPrintPage keyPage) {
0120:                    Map pageMap = (Map) map.get(keyPage);
0121:                    if (pageMap == null) {
0122:                        pageMap = new HashMap();
0123:                        map.put(keyPage, pageMap);
0124:                    }
0125:
0126:                    return pageMap.put(key, value);
0127:                }
0128:
0129:                /**
0130:                 * If per page map is required, the entry will also be added for the
0131:                 * current print page.
0132:                 */
0133:                public Object put(Object key, Object value) {
0134:                    if (isPerPageBoundElements) {
0135:                        return put(key, value, fillContext.getPrintPage());
0136:                    }
0137:
0138:                    return map.put(key, value);
0139:                }
0140:
0141:                public void clear() {
0142:                    map.clear();
0143:                }
0144:
0145:                public Map getMap() {
0146:                    return map;
0147:                }
0148:
0149:                public Map getMap(JRPrintPage page) {
0150:                    return (Map) map.get(page);
0151:                }
0152:
0153:                public Map putMap(JRPrintPage page, Map valueMap) {
0154:                    return (Map) map.put(page, valueMap);
0155:                }
0156:            }
0157:
0158:            protected final String fillerId;
0159:
0160:            /**
0161:             *
0162:             */
0163:            protected JRBaseFiller parentFiller = null;
0164:
0165:            private final JRFillObjectFactory factory;
0166:
0167:            private JRStyledTextParser styledTextParser = new JRStyledTextParser();
0168:
0169:            /**
0170:             *
0171:             */
0172:            private boolean isInterrupted = false;
0173:
0174:            /**
0175:             *
0176:             */
0177:            protected String name = null;
0178:
0179:            protected int columnCount = 1;
0180:
0181:            protected byte printOrder = JRReport.PRINT_ORDER_VERTICAL;
0182:
0183:            protected int pageWidth = 0;
0184:
0185:            protected int pageHeight = 0;
0186:
0187:            protected byte orientation = JRReport.ORIENTATION_PORTRAIT;
0188:
0189:            protected byte whenNoDataType = JRReport.WHEN_NO_DATA_TYPE_NO_PAGES;
0190:
0191:            protected int columnWidth = 0;
0192:
0193:            protected int columnSpacing = 0;
0194:
0195:            protected int leftMargin = 0;
0196:
0197:            protected int rightMargin = 0;
0198:
0199:            protected int topMargin = 0;
0200:
0201:            protected int bottomMargin = 0;
0202:
0203:            protected boolean isTitleNewPage = false;
0204:
0205:            protected boolean isSummaryNewPage = false;
0206:
0207:            protected boolean isFloatColumnFooter = false;
0208:
0209:            /**
0210:             * the resource missing handling type
0211:             */
0212:            protected byte whenResourceMissingType = JRReport.WHEN_RESOURCE_MISSING_TYPE_NULL;
0213:
0214:            protected JRFillReportTemplate[] reportTemplates;
0215:
0216:            protected JRReportFont defaultFont = null;
0217:
0218:            protected JRReportFont[] fonts = null;
0219:
0220:            protected JRStyle defaultStyle = null;
0221:
0222:            protected JRStyle[] styles = null;
0223:
0224:            /**
0225:             * Main report dataset.
0226:             */
0227:            protected JRFillDataset mainDataset;
0228:
0229:            protected JRFillGroup[] groups = null;
0230:
0231:            protected JRFillBand missingFillBand = null;
0232:
0233:            protected JRFillBand background = null;
0234:
0235:            protected JRFillBand title = null;
0236:
0237:            protected JRFillBand pageHeader = null;
0238:
0239:            protected JRFillBand columnHeader = null;
0240:
0241:            protected JRFillBand detail = null;
0242:
0243:            protected JRFillBand columnFooter = null;
0244:
0245:            protected JRFillBand pageFooter = null;
0246:
0247:            protected JRFillBand lastPageFooter = null;
0248:
0249:            protected JRFillBand summary = null;
0250:
0251:            protected JRFillBand noData = null;
0252:
0253:            protected JRVirtualizer virtualizer = null;
0254:
0255:            protected ClassLoader reportClassLoader = null;
0256:
0257:            protected FormatFactory formatFactory = null;
0258:
0259:            protected URLStreamHandlerFactory urlHandlerFactory;
0260:
0261:            protected JRFillContext fillContext;
0262:
0263:            /**
0264:             * Bound element maps indexed by {@link JREvaluationTime JREvaluationTime} objects.
0265:             */
0266:            protected Map boundElements;
0267:
0268:            /**
0269:             *
0270:             */
0271:            protected JasperPrint jasperPrint = null;
0272:
0273:            protected JRPrintPage printPage = null;
0274:
0275:            protected int printPageStretchHeight = 0;
0276:
0277:            /**
0278:             * List of {@link JRFillBand JRFillBand} objects containing all bands of the
0279:             * report.
0280:             */
0281:            protected List bands;
0282:
0283:            /**
0284:             * Collection of subfillers
0285:             */
0286:            protected Set subfillers;
0287:
0288:            private List identityPages;
0289:
0290:            private Thread fillingThread;
0291:
0292:            protected JRCalculator calculator;
0293:
0294:            protected JRAbstractScriptlet scriptlet;
0295:
0296:            /**
0297:             * Map of datasets ({@link JRFillDataset JRFillDataset} objects} indexed by name.
0298:             */
0299:            protected Map datasetMap;
0300:
0301:            /**
0302:             * The report.
0303:             */
0304:            protected JasperReport jasperReport;
0305:
0306:            private boolean bandOverFlowAllowed;
0307:
0308:            protected boolean isPerPageBoundElements;
0309:
0310:            /**
0311:             *
0312:             */
0313:            protected Map dateFormatCache = new HashMap();
0314:            protected Map numberFormatCache = new HashMap();
0315:
0316:            private JRSubreportRunner subreportRunner;
0317:
0318:            /**
0319:             *
0320:             */
0321:            protected boolean isCreatingNewPage = false;
0322:            protected boolean isNewPage = false;
0323:            protected boolean isNewColumn = false;
0324:            protected boolean isNewGroup = true;
0325:            protected boolean isFirstPageBand = false;
0326:            protected boolean isFirstColumnBand = false;
0327:
0328:            protected int columnIndex = 0;
0329:
0330:            protected int offsetX = 0;
0331:            protected int offsetY = 0;
0332:            protected int columnHeaderOffsetY = 0;
0333:            protected int columnFooterOffsetY = 0;
0334:            protected int lastPageColumnFooterOffsetY = 0;
0335:
0336:            protected boolean isLastPageFooter = false;
0337:
0338:            /**
0339:             *
0340:             */
0341:            protected JRBaseFiller(JasperReport jasperReport,
0342:                    JREvaluator initEvaluator, JRBaseFiller parentFiller)
0343:                    throws JRException {
0344:                this .fillerId = Integer.toString(System.identityHashCode(this ));
0345:
0346:                if (log.isDebugEnabled()) {
0347:                    log.debug("Fill " + fillerId + ": created for "
0348:                            + jasperReport.getName());
0349:                }
0350:
0351:                JRGraphEnvInitializer.initializeGraphEnv();
0352:
0353:                this .jasperReport = jasperReport;
0354:
0355:                /*   */
0356:                this .parentFiller = parentFiller;
0357:
0358:                if (parentFiller == null) {
0359:                    fillContext = new JRFillContext();
0360:                } else {
0361:                    fillContext = parentFiller.fillContext;
0362:                }
0363:
0364:                /*   */
0365:                name = jasperReport.getName();
0366:                columnCount = jasperReport.getColumnCount();
0367:                printOrder = jasperReport.getPrintOrder();
0368:                pageWidth = jasperReport.getPageWidth();
0369:                pageHeight = jasperReport.getPageHeight();
0370:                orientation = jasperReport.getOrientation();
0371:                whenNoDataType = jasperReport.getWhenNoDataType();
0372:                columnWidth = jasperReport.getColumnWidth();
0373:                columnSpacing = jasperReport.getColumnSpacing();
0374:                leftMargin = jasperReport.getLeftMargin();
0375:                rightMargin = jasperReport.getRightMargin();
0376:                topMargin = jasperReport.getTopMargin();
0377:                bottomMargin = jasperReport.getBottomMargin();
0378:                isTitleNewPage = jasperReport.isTitleNewPage();
0379:                isSummaryNewPage = jasperReport.isSummaryNewPage();
0380:                isFloatColumnFooter = jasperReport.isFloatColumnFooter();
0381:                whenResourceMissingType = jasperReport
0382:                        .getWhenResourceMissingType();
0383:
0384:                jasperPrint = new JasperPrint();
0385:
0386:                List transferPrefixProps = JRProperties
0387:                        .getProperties(PROPERTIES_PRINT_TRANSFER_PREFIX);
0388:                for (Iterator prefixIt = transferPrefixProps.iterator(); prefixIt
0389:                        .hasNext();) {
0390:                    JRProperties.PropertySuffix transferPrefixProp = (JRProperties.PropertySuffix) prefixIt
0391:                            .next();
0392:                    String transferPrefix = transferPrefixProp.getValue();
0393:                    if (transferPrefix != null && transferPrefix.length() > 0) {
0394:                        List transferProps = JRProperties
0395:                                .getProperties(jasperReport.getPropertiesMap(),
0396:                                        transferPrefix);
0397:                        for (Iterator propIt = transferProps.iterator(); propIt
0398:                                .hasNext();) {
0399:                            JRProperties.PropertySuffix property = (JRProperties.PropertySuffix) propIt
0400:                                    .next();
0401:                            String value = property.getValue();
0402:                            if (value != null && value.length() > 0) {
0403:                                jasperPrint.setProperty(property.getKey(),
0404:                                        value);
0405:                            }
0406:                        }
0407:                    }
0408:                }
0409:
0410:                if (initEvaluator == null) {
0411:                    calculator = JRFillDataset.createCalculator(jasperReport,
0412:                            jasperReport.getMainDataset());
0413:                } else {
0414:                    calculator = new JRCalculator(initEvaluator);
0415:                }
0416:
0417:                /*   */
0418:                factory = new JRFillObjectFactory(this );
0419:
0420:                /*   */
0421:                defaultFont = factory.getReportFont(jasperReport
0422:                        .getDefaultFont());
0423:
0424:                /*   */
0425:                JRReportFont[] jrFonts = jasperReport.getFonts();
0426:                if (jrFonts != null && jrFonts.length > 0) {
0427:                    fonts = new JRReportFont[jrFonts.length];
0428:                    for (int i = 0; i < fonts.length; i++) {
0429:                        fonts[i] = factory.getReportFont(jrFonts[i]);
0430:                    }
0431:                }
0432:
0433:                createDatasets();
0434:                mainDataset = factory.getDataset(jasperReport.getMainDataset());
0435:                groups = mainDataset.groups;
0436:
0437:                createReportTemplates(factory);
0438:
0439:                /*   */
0440:                missingFillBand = factory.getBand(null);
0441:                background = factory.getBand(jasperReport.getBackground());
0442:                title = factory.getBand(jasperReport.getTitle());
0443:                pageHeader = factory.getBand(jasperReport.getPageHeader());
0444:                columnHeader = factory.getBand(jasperReport.getColumnHeader());
0445:                detail = factory.getBand(jasperReport.getDetail());
0446:                columnFooter = factory.getBand(jasperReport.getColumnFooter());
0447:                pageFooter = factory.getBand(jasperReport.getPageFooter());
0448:                lastPageFooter = factory.getBand(jasperReport
0449:                        .getLastPageFooter());
0450:                summary = factory.getBand(jasperReport.getSummary());
0451:                if (summary != missingFillBand && summary.isEmpty()) {
0452:                    summary = missingFillBand;
0453:                }
0454:                noData = factory.getBand(jasperReport.getNoData());
0455:
0456:                mainDataset.initElementDatasets(factory);
0457:                initDatasets(factory);
0458:
0459:                mainDataset.checkVariableCalculationReqs(factory);
0460:
0461:                /*   */
0462:                mainDataset.setCalculator(calculator);
0463:                mainDataset.initCalculator();
0464:
0465:                initBands();
0466:            }
0467:
0468:            /**
0469:             * Returns the report parameters indexed by name.
0470:             *
0471:             * @return the report parameters map
0472:             */
0473:            protected Map getParametersMap() {
0474:                return mainDataset.parametersMap;
0475:            }
0476:
0477:            /**
0478:             * Returns the report fields indexed by name.
0479:             *
0480:             * @return the report fields map
0481:             */
0482:            protected Map getFieldsMap() {
0483:                return mainDataset.fieldsMap;
0484:            }
0485:
0486:            /**
0487:             * Returns the report variables indexed by name.
0488:             *
0489:             * @return the report variables map
0490:             */
0491:            protected Map getVariablesMap() {
0492:                return mainDataset.variablesMap;
0493:            }
0494:
0495:            /**
0496:             * Returns a report variable.
0497:             *
0498:             * @param variableName the variable name
0499:             * @return the variable
0500:             */
0501:            protected JRFillVariable getVariable(String variableName) {
0502:                return (JRFillVariable) mainDataset.variablesMap
0503:                        .get(variableName);
0504:            }
0505:
0506:            /**
0507:             * Returns a report field.
0508:             *
0509:             * @param fieldName the field name
0510:             * @return the field
0511:             */
0512:            protected JRFillField getField(String fieldName) {
0513:                return (JRFillField) mainDataset.fieldsMap.get(fieldName);
0514:            }
0515:
0516:            private void initBands() {
0517:                bands = new ArrayList(8 + (groups == null ? 0
0518:                        : (2 * groups.length)));
0519:                bands.add(title);
0520:                bands.add(summary);
0521:                bands.add(pageHeader);
0522:                bands.add(pageFooter);
0523:                bands.add(lastPageFooter);
0524:                bands.add(columnHeader);
0525:                bands.add(columnFooter);
0526:                bands.add(detail);
0527:                bands.add(noData);
0528:
0529:                if (groups != null && groups.length > 0) {
0530:                    for (int i = 0; i < groups.length; i++) {
0531:                        JRFillGroup group = groups[i];
0532:                        bands.add(group.getGroupHeader());
0533:                        bands.add(group.getGroupFooter());
0534:                    }
0535:                }
0536:
0537:                initBandsNowEvaluationTimes();
0538:            }
0539:
0540:            private void initBandsNowEvaluationTimes() {
0541:                JREvaluationTime[] groupEvaluationTimes;
0542:                if (groups == null) {
0543:                    groupEvaluationTimes = new JREvaluationTime[0];
0544:                } else {
0545:                    groupEvaluationTimes = new JREvaluationTime[groups.length];
0546:                    for (int i = 0; i < groups.length; i++) {
0547:                        groupEvaluationTimes[i] = JREvaluationTime
0548:                                .getGroupEvaluationTime(groups[i].getName());
0549:                    }
0550:
0551:                    for (int i = 0; i < groups.length; i++) {
0552:                        JRGroup group = groups[i];
0553:                        JRFillBand footer = (JRFillBand) group.getGroupFooter();
0554:
0555:                        for (int j = i; j < groupEvaluationTimes.length; ++j) {
0556:                            footer
0557:                                    .addNowEvaluationTime(groupEvaluationTimes[j]);
0558:                        }
0559:                    }
0560:                }
0561:
0562:                columnFooter
0563:                        .addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_COLUMN);
0564:
0565:                pageFooter
0566:                        .addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_COLUMN);
0567:                pageFooter
0568:                        .addNowEvaluationTime(JREvaluationTime.EVALUATION_TIME_PAGE);
0569:
0570:                summary.addNowEvaluationTimes(groupEvaluationTimes);
0571:                noData.addNowEvaluationTimes(groupEvaluationTimes);
0572:            }
0573:
0574:            /**
0575:             *
0576:             */
0577:            public JRStyledTextParser getStyledTextParser() {
0578:                return styledTextParser;
0579:            }
0580:
0581:            /**
0582:             *
0583:             */
0584:            public JasperPrint getJasperPrint() {
0585:                return jasperPrint;
0586:            }
0587:
0588:            /**
0589:             *
0590:             */
0591:            public JRReportFont getDefaultFont() {
0592:                return defaultFont;
0593:            }
0594:
0595:            /**
0596:             *
0597:             */
0598:            public JRStyle getDefaultStyle() {
0599:                return defaultStyle;
0600:            }
0601:
0602:            /**
0603:             *
0604:             */
0605:            protected boolean isSubreport() {
0606:                return (parentFiller != null);
0607:            }
0608:
0609:            /**
0610:             *
0611:             */
0612:            protected boolean isInterrupted() {
0613:                return (isInterrupted || (parentFiller != null && parentFiller
0614:                        .isInterrupted()));
0615:            }
0616:
0617:            /**
0618:             *
0619:             */
0620:            protected void setInterrupted(boolean isInterrupted) {
0621:                this .isInterrupted = isInterrupted;
0622:            }
0623:
0624:            /**
0625:             *
0626:             */
0627:            protected JRPrintPage getCurrentPage() {
0628:                return printPage;
0629:            }
0630:
0631:            /**
0632:             *
0633:             */
0634:            protected JRReportFont[] getFonts() {
0635:                return fonts;
0636:            }
0637:
0638:            /**
0639:             *
0640:             */
0641:            protected int getCurrentPageStretchHeight() {
0642:                return printPageStretchHeight;
0643:            }
0644:
0645:            /**
0646:             *
0647:             */
0648:            protected abstract void setPageHeight(int pageHeight);
0649:
0650:            public JasperPrint fill(Map parameterValues, Connection conn)
0651:                    throws JRException {
0652:                if (parameterValues == null) {
0653:                    parameterValues = new HashMap();
0654:                }
0655:
0656:                setConnectionParameterValue(parameterValues, conn);
0657:
0658:                return fill(parameterValues);
0659:            }
0660:
0661:            protected void setConnectionParameterValue(Map parameterValues,
0662:                    Connection conn) {
0663:                mainDataset.setConnectionParameterValue(parameterValues, conn);
0664:            }
0665:
0666:            public JasperPrint fill(Map parameterValues, JRDataSource ds)
0667:                    throws JRException {
0668:                if (parameterValues == null) {
0669:                    parameterValues = new HashMap();
0670:                }
0671:
0672:                setDatasourceParameterValue(parameterValues, ds);
0673:
0674:                return fill(parameterValues);
0675:            }
0676:
0677:            protected void setDatasourceParameterValue(Map parameterValues,
0678:                    JRDataSource ds) {
0679:                mainDataset.setDatasourceParameterValue(parameterValues, ds);
0680:            }
0681:
0682:            public JasperPrint fill(Map parameterValues) throws JRException {
0683:                if (parameterValues == null) {
0684:                    parameterValues = new HashMap();
0685:                }
0686:
0687:                if (log.isDebugEnabled()) {
0688:                    log.debug("Fill " + fillerId + ": filling report");
0689:                }
0690:
0691:                fillingThread = Thread.currentThread();
0692:                boolean urlHandlerFactorySet = false;
0693:                boolean classLoaderSet = false;
0694:                try {
0695:                    /*   */
0696:                    setParameters(parameterValues);
0697:
0698:                    classLoaderSet = setClassLoader(parameterValues);
0699:                    urlHandlerFactorySet = setUrlHandlerFactory(parameterValues);
0700:
0701:                    loadStyles();
0702:
0703:                    if (parentFiller != null) {
0704:                        parentFiller.registerSubfiller(this );
0705:                    }
0706:
0707:                    jasperPrint.setName(name);
0708:                    jasperPrint.setPageWidth(pageWidth);
0709:                    jasperPrint.setPageHeight(pageHeight);
0710:                    jasperPrint.setOrientation(orientation);
0711:
0712:                    jasperPrint.setDefaultFont(defaultFont);
0713:
0714:                    jasperPrint.setFormatFactoryClass(jasperReport
0715:                            .getFormatFactoryClass());
0716:                    jasperPrint.setLocaleCode(JRDataUtils
0717:                            .getLocaleCode(getLocale()));
0718:                    jasperPrint.setTimeZoneId(JRDataUtils
0719:                            .getTimeZoneId(getTimeZone()));
0720:
0721:                    /*   */
0722:                    if (fonts != null && fonts.length > 0) {
0723:                        for (int i = 0; i < fonts.length; i++) {
0724:                            jasperPrint.addFont(fonts[i], true);
0725:                        }
0726:                    }
0727:
0728:                    jasperPrint.setDefaultStyle(defaultStyle);
0729:
0730:                    /*   */
0731:                    if (styles != null && styles.length > 0) {
0732:                        for (int i = 0; i < styles.length; i++) {
0733:                            jasperPrint.addStyle(styles[i], true);
0734:                        }
0735:                    }
0736:
0737:                    createBoundElemementMaps();
0738:
0739:                    /*   */
0740:                    mainDataset.start();
0741:
0742:                    /*   */
0743:                    fillReport();
0744:
0745:                    // add consolidates styles as normal styles in the print object
0746:                    //			for (Iterator it = consolidatedStyles.values().iterator(); it.hasNext();)
0747:                    //			{
0748:                    //				jasperPrint.addStyle((JRStyle) it.next());
0749:                    //			}
0750:
0751:                    if (log.isDebugEnabled()) {
0752:                        log.debug("Fill " + fillerId + ": ended");
0753:                    }
0754:
0755:                    return jasperPrint;
0756:                } finally {
0757:                    mainDataset.closeDatasource();
0758:
0759:                    if (parentFiller != null) {
0760:                        parentFiller.unregisterSubfiller(this );
0761:                    }
0762:
0763:                    fillingThread = null;
0764:
0765:                    //kill the subreport filler threads
0766:                    killSubfillerThreads();
0767:
0768:                    if (classLoaderSet) {
0769:                        JRResourcesUtil.resetClassLoader();
0770:                    }
0771:
0772:                    if (urlHandlerFactorySet) {
0773:                        JRResourcesUtil.resetThreadURLHandlerFactory();
0774:                    }
0775:                }
0776:            }
0777:
0778:            protected static interface DefaultStyleListener {
0779:                void defaultStyleSet(JRStyle style);
0780:            }
0781:
0782:            private final List defaultStyleListeners = new ArrayList();
0783:
0784:            protected void addDefaultStyleListener(DefaultStyleListener listener) {
0785:                defaultStyleListeners.add(listener);
0786:            }
0787:
0788:            protected void setDefaultStyle(JRStyle style) {
0789:                defaultStyle = style;
0790:
0791:                for (Iterator it = defaultStyleListeners.iterator(); it
0792:                        .hasNext();) {
0793:                    DefaultStyleListener listener = (DefaultStyleListener) it
0794:                            .next();
0795:                    listener.defaultStyleSet(style);
0796:                }
0797:            }
0798:
0799:            protected void loadStyles() throws JRException {
0800:                List styleList = collectStyles();
0801:                JRStyle reportDefaultStyle = jasperReport.getDefaultStyle();
0802:                if (reportDefaultStyle == null) {
0803:                    lookupExternalDefaultStyle(styleList);
0804:                }
0805:
0806:                List includedStyles = factory.setStyles(styleList);
0807:
0808:                styles = (JRStyle[]) includedStyles
0809:                        .toArray(new JRStyle[includedStyles.size()]);
0810:
0811:                if (reportDefaultStyle != null) {
0812:                    setDefaultStyle(factory.getStyle(reportDefaultStyle));
0813:                }
0814:            }
0815:
0816:            private static final JRStyleSetter DUMMY_STYLE_SETTER = new JRStyleSetter() {
0817:                public void setStyle(JRStyle style) {
0818:                }
0819:
0820:                public void setStyleNameReference(String name) {
0821:                }
0822:            };
0823:
0824:            protected List collectStyles() throws JRException {
0825:                List styleList = collectTemplateStyles();
0826:
0827:                JRStyle[] reportStyles = jasperReport.getStyles();
0828:                if (reportStyles != null) {
0829:                    styles = new JRStyle[reportStyles.length];
0830:
0831:                    for (int i = 0; i < reportStyles.length; i++) {
0832:                        JRStyle style = reportStyles[i];
0833:                        styleList.add(style);
0834:
0835:                        //add dummy style requester so that report styles are always included
0836:                        //in the final list
0837:                        factory.registerDelayedStyleSetter(DUMMY_STYLE_SETTER,
0838:                                style.getName());
0839:                    }
0840:                }
0841:
0842:                return styleList;
0843:            }
0844:
0845:            protected List collectTemplateStyles() throws JRException {
0846:                List externalStyles = new ArrayList();
0847:                HashSet loadedLocations = new HashSet();
0848:
0849:                if (reportTemplates != null) {
0850:                    for (int i = 0; i < reportTemplates.length; i++) {
0851:                        JRFillReportTemplate reportTemplate = reportTemplates[i];
0852:                        JRTemplate template = reportTemplate.evaluate();
0853:                        collectStyles(template, externalStyles, loadedLocations);
0854:                    }
0855:                }
0856:
0857:                Collection paramTemplates = (Collection) mainDataset
0858:                        .getParameterValue(JRParameter.REPORT_TEMPLATES, true);
0859:                if (paramTemplates != null) {
0860:                    for (Iterator it = paramTemplates.iterator(); it.hasNext();) {
0861:                        JRTemplate template = (JRTemplate) it.next();
0862:                        collectStyles(template, externalStyles, loadedLocations);
0863:                    }
0864:                }
0865:
0866:                return externalStyles;
0867:            }
0868:
0869:            protected void collectStyles(JRTemplate template,
0870:                    List externalStyles, Set loadedLocations)
0871:                    throws JRException {
0872:                collectIncludedTemplates(template, externalStyles,
0873:                        loadedLocations);
0874:
0875:                JRStyle[] templateStyles = template.getStyles();
0876:                if (templateStyles != null) {
0877:                    for (int i = 0; i < templateStyles.length; i++) {
0878:                        JRStyle style = templateStyles[i];
0879:                        String styleName = style.getName();
0880:                        if (styleName == null) {
0881:                            throw new JRRuntimeException(
0882:                                    "External style name not set.");
0883:                        }
0884:
0885:                        externalStyles.add(style);
0886:                    }
0887:                }
0888:            }
0889:
0890:            protected void collectIncludedTemplates(JRTemplate template,
0891:                    List externalStyles, Set loadedLocations)
0892:                    throws JRException {
0893:                JRTemplateReference[] includedTemplates = template
0894:                        .getIncludedTemplates();
0895:                if (includedTemplates != null) {
0896:                    for (int i = 0; i < includedTemplates.length; i++) {
0897:                        JRTemplateReference reference = includedTemplates[i];
0898:                        String location = reference.getLocation();
0899:
0900:                        if (!loadedLocations.add(location)) {
0901:                            throw new JRRuntimeException(
0902:                                    "Circular dependency found for template at location "
0903:                                            + location);
0904:                        }
0905:
0906:                        JRTemplate includedTemplate = JRFillReportTemplate
0907:                                .loadTemplate(location, String.class,
0908:                                        fillContext);
0909:                        collectStyles(includedTemplate, externalStyles,
0910:                                loadedLocations);
0911:                    }
0912:                }
0913:            }
0914:
0915:            protected void lookupExternalDefaultStyle(Collection styleList) {
0916:                JRStyle defStyle = null;
0917:                for (Iterator it = styleList.iterator(); it.hasNext();) {
0918:                    JRStyle style = (JRStyle) it.next();
0919:                    if (style.isDefault()) {
0920:                        defStyle = style;
0921:                    }
0922:                }
0923:
0924:                if (defStyle != null) {
0925:                    factory.registerDelayedStyleSetter(new JRStyleSetter() {
0926:                        public void setStyle(JRStyle style) {
0927:                            if (style.isDefault()) {
0928:                                setDefaultStyle(style);
0929:                            }
0930:                        }
0931:
0932:                        public void setStyleNameReference(String name) {
0933:                        }
0934:                    }, defStyle.getName());
0935:                }
0936:            }
0937:
0938:            private void createBoundElemementMaps() {
0939:                boundElements = new HashMap();
0940:
0941:                createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_REPORT);
0942:                createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_PAGE);
0943:                createBoundElementMaps(JREvaluationTime.EVALUATION_TIME_COLUMN);
0944:
0945:                if (groups != null) {
0946:                    for (int i = 0; i < groups.length; i++) {
0947:                        createBoundElementMaps(JREvaluationTime
0948:                                .getGroupEvaluationTime(groups[i].getName()));
0949:                    }
0950:                }
0951:
0952:                for (Iterator i = bands.iterator(); i.hasNext();) {
0953:                    JRFillBand band = (JRFillBand) i.next();
0954:                    createBoundElementMaps(JREvaluationTime
0955:                            .getBandEvaluationTime(band));
0956:                }
0957:            }
0958:
0959:            private void createBoundElementMaps(JREvaluationTime evaluationTime) {
0960:                BoundElementMap boundElementsMap = new BoundElementMap();
0961:                boundElements.put(evaluationTime, boundElementsMap);
0962:            }
0963:
0964:            private void killSubfillerThreads() {
0965:                if (subfillers != null && !subfillers.isEmpty()) {
0966:                    for (Iterator it = subfillers.iterator(); it.hasNext();) {
0967:                        JRBaseFiller subfiller = (JRBaseFiller) it.next();
0968:                        if (subfiller.fillingThread != null) {
0969:                            if (log.isDebugEnabled()) {
0970:                                log.debug("Fill " + fillerId
0971:                                        + ": Interrupting subfiller thread "
0972:                                        + subfiller.fillingThread);
0973:                            }
0974:
0975:                            subfiller.fillingThread.interrupt();
0976:                        }
0977:                    }
0978:                }
0979:            }
0980:
0981:            /**
0982:             *
0983:             */
0984:            protected abstract void fillReport() throws JRException;
0985:
0986:            /**
0987:             *
0988:             */
0989:            protected void setParameters(Map parameterValues)
0990:                    throws JRException {
0991:                if (!isSubreport()) {
0992:                    /* Virtualizer */
0993:                    virtualizer = (JRVirtualizer) parameterValues
0994:                            .get(JRParameter.REPORT_VIRTUALIZER);
0995:
0996:                    if (virtualizer != null) {
0997:                        if (log.isDebugEnabled()) {
0998:                            log.debug("Fill " + fillerId
0999:                                    + ": using virtualizer " + virtualizer);
1000:                        }
1001:
1002:                        fillContext.setUsingVirtualizer(true);
1003:                        fillContext.setPerPageBoundElements(true);
1004:                        JRVirtualizationContext.register(fillContext
1005:                                .getVirtualizationContext(), jasperPrint);
1006:                    }
1007:                }
1008:
1009:                isPerPageBoundElements = fillContext.isPerPageBoundElements();
1010:
1011:                setFormatFactory(parameterValues);
1012:
1013:                setIgnorePagination(parameterValues);
1014:
1015:                mainDataset.setParameterValues(parameterValues);
1016:                mainDataset.initDatasource();
1017:
1018:                this .scriptlet = mainDataset.scriptlet;
1019:
1020:                if (!isSubreport()) {
1021:                    fillContext.setMasterFormatFactory(getFormatFactory());
1022:                    fillContext.setMasterLocale(getLocale());
1023:                    fillContext.setMasterTimeZone(getTimeZone());
1024:                }
1025:            }
1026:
1027:            private void setFormatFactory(Map parameterValues) {
1028:                formatFactory = (FormatFactory) parameterValues
1029:                        .get(JRParameter.REPORT_FORMAT_FACTORY);
1030:                if (formatFactory == null) {
1031:                    formatFactory = DefaultFormatFactory
1032:                            .createFormatFactory(jasperReport
1033:                                    .getFormatFactoryClass());
1034:                    parameterValues.put(JRParameter.REPORT_FORMAT_FACTORY,
1035:                            formatFactory);
1036:                }
1037:            }
1038:
1039:            private boolean setClassLoader(Map parameterValues) {
1040:                reportClassLoader = (ClassLoader) parameterValues
1041:                        .get(JRParameter.REPORT_CLASS_LOADER);
1042:                boolean setClassLoader = reportClassLoader != null;
1043:                if (setClassLoader) {
1044:                    JRResourcesUtil.setThreadClassLoader(reportClassLoader);
1045:                }
1046:                return setClassLoader;
1047:            }
1048:
1049:            private boolean setUrlHandlerFactory(Map parameterValues) {
1050:                urlHandlerFactory = (URLStreamHandlerFactory) parameterValues
1051:                        .get(JRParameter.REPORT_URL_HANDLER_FACTORY);
1052:                boolean setUrlHandlerFactory = urlHandlerFactory != null;
1053:                if (setUrlHandlerFactory) {
1054:                    JRResourcesUtil
1055:                            .setThreadURLHandlerFactory(urlHandlerFactory);
1056:                }
1057:                return setUrlHandlerFactory;
1058:            }
1059:
1060:            private void setIgnorePagination(Map parameterValues) {
1061:                if (parentFiller == null)//pagination is driven by the master
1062:                {
1063:                    Boolean isIgnorePaginationParam = (Boolean) parameterValues
1064:                            .get(JRParameter.IS_IGNORE_PAGINATION);
1065:                    if (isIgnorePaginationParam != null) {
1066:                        fillContext.setIgnorePagination(isIgnorePaginationParam
1067:                                .booleanValue());
1068:                    } else {
1069:                        boolean ignorePagination = jasperReport
1070:                                .isIgnorePagination();
1071:                        fillContext.setIgnorePagination(ignorePagination);
1072:                        parameterValues
1073:                                .put(JRParameter.IS_IGNORE_PAGINATION,
1074:                                        ignorePagination ? Boolean.TRUE
1075:                                                : Boolean.FALSE);
1076:                    }
1077:                } else {
1078:                    boolean ignorePagination = fillContext.isIgnorePagination();
1079:                    parameterValues.put(JRParameter.IS_IGNORE_PAGINATION,
1080:                            ignorePagination ? Boolean.TRUE : Boolean.FALSE);
1081:                }
1082:
1083:                if (fillContext.isIgnorePagination()) {
1084:                    isTitleNewPage = false;
1085:                    isSummaryNewPage = false;
1086:                    if (groups != null) {
1087:                        for (int i = 0; i < groups.length; i++) {
1088:                            groups[i].setStartNewPage(false);
1089:                            groups[i].setResetPageNumber(false);
1090:                            groups[i].setStartNewColumn(false);
1091:                        }
1092:                    }
1093:                    setPageHeight(Integer.MAX_VALUE);
1094:                }
1095:            }
1096:
1097:            /**
1098:             * Returns the report locale.
1099:             *
1100:             * @return the report locale
1101:             */
1102:            protected Locale getLocale() {
1103:                return mainDataset.locale;
1104:            }
1105:
1106:            /**
1107:             * Returns the report time zone.
1108:             *
1109:             * @return the report time zone
1110:             */
1111:            protected TimeZone getTimeZone() {
1112:                return mainDataset.timeZone;
1113:            }
1114:
1115:            /**
1116:             * Returns the report format factory.
1117:             *
1118:             * @return the report format factory
1119:             */
1120:            protected FormatFactory getFormatFactory() {
1121:                return formatFactory;
1122:            }
1123:
1124:            /**
1125:             *
1126:             */
1127:            protected Format getDateFormat(String pattern) {
1128:                Locale lc = getLocale();
1129:                TimeZone tz = getTimeZone();
1130:                String key = pattern + "|" + JRDataUtils.getLocaleCode(lc)
1131:                        + "|" + JRDataUtils.getTimeZoneId(tz);
1132:                Format format = (Format) dateFormatCache.get(key);
1133:                if (format == null) {
1134:                    format = getFormatFactory().createDateFormat(pattern, lc,
1135:                            tz);
1136:                    if (format != null) {
1137:                        dateFormatCache.put(key, format);
1138:                    }
1139:                }
1140:                return format;
1141:            }
1142:
1143:            /**
1144:             *
1145:             */
1146:            protected Format getNumberFormat(String pattern) {
1147:                Locale lc = getLocale();
1148:                String key = pattern + "|" + JRDataUtils.getLocaleCode(lc);
1149:                Format format = (Format) numberFormatCache.get(key);
1150:                if (format == null) {
1151:                    format = getFormatFactory().createNumberFormat(pattern, lc);
1152:                    if (format != null) {
1153:                        numberFormatCache.put(key, format);
1154:                    }
1155:                }
1156:                return format;
1157:            }
1158:
1159:            protected boolean hasMasterFormatFactory() {
1160:                return !isSubreport()
1161:                        || getFormatFactory().getClass().getName().equals(
1162:                                fillContext.getMasterFormatFactory().getClass()
1163:                                        .getName());
1164:            }
1165:
1166:            protected boolean hasMasterLocale() {
1167:                return !isSubreport()
1168:                        || getLocale().equals(fillContext.getMasterLocale());
1169:            }
1170:
1171:            protected boolean hasMasterTimeZone() {
1172:                return !isSubreport()
1173:                        || getTimeZone()
1174:                                .equals(fillContext.getMasterTimeZone());
1175:            }
1176:
1177:            /**
1178:             * Sets a parameter's value.
1179:             *
1180:             * @param parameterName the parameter name
1181:             * @param value the value
1182:             * @throws JRException
1183:             */
1184:            protected void setParameter(String parameterName, Object value)
1185:                    throws JRException {
1186:                mainDataset.setParameter(parameterName, value);
1187:            }
1188:
1189:            /**
1190:             * Sets a parameter's value.
1191:             *
1192:             * @param parameter the parameter
1193:             * @param value the value
1194:             * @throws JRException
1195:             */
1196:            protected void setParameter(JRFillParameter parameter, Object value)
1197:                    throws JRException {
1198:                mainDataset.setParameter(parameter, value);
1199:            }
1200:
1201:            /**
1202:             *
1203:             */
1204:            protected boolean next() throws JRException {
1205:                return mainDataset.next();
1206:            }
1207:
1208:            private void resolveBoundElements(Map boundElementsMap,
1209:                    byte evaluation, JREvaluationTime evaluationTime)
1210:                    throws JRException {
1211:                if (boundElementsMap != null) {
1212:                    for (Iterator it = boundElementsMap.entrySet().iterator(); it
1213:                            .hasNext();) {
1214:                        Map.Entry entry = (Map.Entry) it.next();
1215:                        JRPrintElement element = (JRPrintElement) entry
1216:                                .getKey();
1217:                        JRFillElement fillElement = (JRFillElement) entry
1218:                                .getValue();
1219:
1220:                        fillElement.resolveElement(element, evaluation,
1221:                                evaluationTime);
1222:                    }
1223:                }
1224:            }
1225:
1226:            protected void resolveBoundElements(
1227:                    JREvaluationTime evaluationTime, byte evaluation)
1228:                    throws JRException {
1229:                BoundElementMap boundElementsMap = (BoundElementMap) boundElements
1230:                        .get(evaluationTime);
1231:                if (isPerPageBoundElements) {
1232:                    Map perPageElementsMap = boundElementsMap.getMap();
1233:                    for (Iterator it = perPageElementsMap.entrySet().iterator(); it
1234:                            .hasNext();) {
1235:                        Map.Entry entry = (Map.Entry) it.next();
1236:                        // Calling getElements() will page in the data for the page.
1237:                        JRPrintPage page = (JRPrintPage) entry.getKey();
1238:                        page.getElements();
1239:                        Map elementsMap = (Map) entry.getValue();
1240:                        resolveBoundElements(elementsMap, evaluation,
1241:                                evaluationTime);
1242:                    }
1243:
1244:                    boundElementsMap.clear();
1245:                } else {
1246:                    resolveBoundElements(boundElementsMap.getMap(), evaluation,
1247:                            evaluationTime);
1248:                    boundElementsMap.clear();
1249:                }
1250:            }
1251:
1252:            /**
1253:             * Resolves elements which are to be evaluated at report level.
1254:             */
1255:            protected void resolveReportBoundElements() throws JRException {
1256:                resolveBoundElements(JREvaluationTime.EVALUATION_TIME_REPORT,
1257:                        JRExpression.EVALUATION_DEFAULT);
1258:            }
1259:
1260:            /**
1261:             * Resolves elements which are to be evaluated at page level.
1262:             *
1263:             * @param evaluation
1264:             *            the evaluation type
1265:             */
1266:            protected void resolvePageBoundElements(byte evaluation)
1267:                    throws JRException {
1268:                resolveBoundElements(JREvaluationTime.EVALUATION_TIME_PAGE,
1269:                        evaluation);
1270:            }
1271:
1272:            /**
1273:             * Resolves elements which are to be evaluated at column level.
1274:             *
1275:             * @param evaluation
1276:             *            the evaluation type
1277:             */
1278:            protected void resolveColumnBoundElements(byte evaluation)
1279:                    throws JRException {
1280:                resolveBoundElements(JREvaluationTime.EVALUATION_TIME_COLUMN,
1281:                        evaluation);
1282:            }
1283:
1284:            /**
1285:             * Resolves elements which are to be evaluated at group level.
1286:             *
1287:             * @param evaluation
1288:             *            the evaluation type
1289:             * @param isFinal
1290:             */
1291:            protected void resolveGroupBoundElements(byte evaluation,
1292:                    boolean isFinal) throws JRException {
1293:                if (groups != null && groups.length > 0) {
1294:                    for (int i = 0; i < groups.length; i++) {
1295:                        JRFillGroup group = groups[i];
1296:
1297:                        if ((group.hasChanged() && group.isFooterPrinted())
1298:                                || isFinal) {
1299:                            String groupName = group.getName();
1300:
1301:                            resolveBoundElements(JREvaluationTime
1302:                                    .getGroupEvaluationTime(groupName),
1303:                                    evaluation);
1304:                        }
1305:                    }
1306:                }
1307:            }
1308:
1309:            protected JRPrintPage newPage() {
1310:                JRPrintPage page;
1311:
1312:                if (virtualizer != null) {
1313:                    JRVirtualPrintPage virtualPage = new JRVirtualPrintPage(
1314:                            jasperPrint, virtualizer, fillContext
1315:                                    .getVirtualizationContext());
1316:
1317:                    addIdentityDataProviders(virtualPage, this );
1318:
1319:                    page = virtualPage;
1320:                } else {
1321:                    page = new JRBasePrintPage();
1322:                }
1323:
1324:                return page;
1325:            }
1326:
1327:            /**
1328:             * Returns the value of a variable.
1329:             *
1330:             * @param variableName
1331:             *            the variable name
1332:             *
1333:             * @return the variable value
1334:             *
1335:             * @throws JRRuntimeException when the variable does not exist
1336:             */
1337:            public Object getVariableValue(String variableName) {
1338:                return mainDataset.getVariableValue(variableName);
1339:            }
1340:
1341:            /**
1342:             * Resloves elements which are to be evaluated at band level.
1343:             *
1344:             * @param band
1345:             *            the band
1346:             * @param evaluation
1347:             *            the evaluation type
1348:             * @throws JRException
1349:             */
1350:            protected void resolveBandBoundElements(JRFillBand band,
1351:                    byte evaluation) throws JRException {
1352:                resolveBoundElements(JREvaluationTime
1353:                        .getBandEvaluationTime(band), evaluation);
1354:            }
1355:
1356:            /**
1357:             * Adds a variable calculation request.
1358:             *
1359:             * @param variableName
1360:             *            the variable name
1361:             * @param calculation
1362:             *            the calculation type
1363:             */
1364:            protected void addVariableCalculationReq(String variableName,
1365:                    byte calculation) {
1366:                mainDataset
1367:                        .addVariableCalculationReq(variableName, calculation);
1368:            }
1369:
1370:            /**
1371:             * Cancells the fill process.
1372:             *
1373:             * @throws JRException
1374:             */
1375:            public void cancelFill() throws JRException {
1376:                if (log.isDebugEnabled()) {
1377:                    log.debug("Fill " + fillerId + ": cancelling");
1378:                }
1379:
1380:                if (fillContext.cancelRunningQuery()) {
1381:                    if (log.isDebugEnabled()) {
1382:                        log.debug("Fill " + fillerId + ": query cancelled");
1383:                    }
1384:                } else {
1385:                    Thread t = fillingThread;
1386:                    if (t != null) {
1387:                        if (log.isDebugEnabled()) {
1388:                            log.debug("Fill " + fillerId
1389:                                    + ": Interrupting thread " + t);
1390:                        }
1391:
1392:                        t.interrupt();
1393:                    }
1394:                }
1395:            }
1396:
1397:            protected void registerSubfiller(JRBaseFiller subfiller) {
1398:                if (subfillers == null) {
1399:                    subfillers = new HashSet();
1400:                }
1401:
1402:                if (subfillers.add(subfiller)
1403:                        && fillContext.isUsingVirtualizer()) {
1404:                    subfiller.identityPages = new ArrayList();
1405:
1406:                    JRVirtualPrintPage masterPrintPage = (JRVirtualPrintPage) fillContext
1407:                            .getPrintPage();
1408:                    subfiller.identityPages.add(masterPrintPage);
1409:                    addIdentityDataProviders(masterPrintPage, subfiller);
1410:                }
1411:            }
1412:
1413:            protected void unregisterSubfiller(JRBaseFiller subfiller) {
1414:                if (subfillers != null && subfillers.remove(subfiller)
1415:                        && fillContext.isUsingVirtualizer()) {
1416:                    removeIdentityDataProviders(subfiller);
1417:                }
1418:            }
1419:
1420:            private static void addIdentityDataProviders(
1421:                    JRVirtualPrintPage page, JRBaseFiller filler) {
1422:                page.addIdentityDataProvider(filler);
1423:
1424:                if (filler.subfillers != null) {
1425:                    for (Iterator i = filler.subfillers.iterator(); i.hasNext();) {
1426:                        JRBaseFiller subfiller = (JRBaseFiller) i.next();
1427:
1428:                        subfiller.identityPages.add(page);
1429:                        addIdentityDataProviders(page, subfiller);
1430:                    }
1431:                }
1432:            }
1433:
1434:            private void removeIdentityDataProviders(JRBaseFiller filler) {
1435:                if (filler.identityPages != null) {
1436:                    for (Iterator it = filler.identityPages.iterator(); it
1437:                            .hasNext();) {
1438:                        JRVirtualPrintPage page = (JRVirtualPrintPage) it
1439:                                .next();
1440:
1441:                        page.removeIdentityDataProvider(filler);
1442:                    }
1443:
1444:                    filler.identityPages = null;
1445:                }
1446:            }
1447:
1448:            protected void addPage(JRPrintPage page) {
1449:                if (!isSubreport()) {
1450:                    if (log.isDebugEnabled()) {
1451:                        log.debug("Fill " + fillerId + ": adding page "
1452:                                + (jasperPrint.getPages().size() + 1));
1453:                    }
1454:
1455:                    jasperPrint.addPage(page);
1456:                    fillContext.setPrintPage(page);
1457:                }
1458:            }
1459:
1460:            protected static final class PageIdentityDataProvider implements 
1461:                    JRVirtualPrintPage.IdentityDataProvider {
1462:                private static final Map providers = new HashMap();
1463:
1464:                private final JRPrintPage printPage;
1465:
1466:                protected PageIdentityDataProvider(JRPrintPage printPage) {
1467:                    this .printPage = printPage;
1468:                }
1469:
1470:                public JRVirtualPrintPage.ObjectIDPair[] getIdentityData(
1471:                        JRVirtualPrintPage page) {
1472:                    return null;
1473:                }
1474:
1475:                public void setIdentityData(JRVirtualPrintPage page,
1476:                        JRVirtualPrintPage.ObjectIDPair[] identityData) {
1477:                    if (identityData != null && identityData.length > 0) {
1478:                        Map idMap = new HashMap();
1479:                        for (int i = 0; i < identityData.length; i++) {
1480:                            idMap.put(
1481:                                    new Integer(identityData[i].getIdentity()),
1482:                                    identityData[i].getObject());
1483:                        }
1484:
1485:                        for (ListIterator i = printPage.getElements()
1486:                                .listIterator(); i.hasNext();) {
1487:                            Object element = i.next();
1488:                            Integer id = new Integer(System
1489:                                    .identityHashCode(element));
1490:
1491:                            Object idObject = idMap.get(id);
1492:                            if (idObject != null) {
1493:                                i.set(idObject);
1494:                            }
1495:                        }
1496:                    }
1497:                }
1498:
1499:                public static JRVirtualPrintPage.IdentityDataProvider getIdentityDataProvider(
1500:                        JRPrintPage printPage) {
1501:                    JRVirtualPrintPage.IdentityDataProvider provider = (JRVirtualPrintPage.IdentityDataProvider) providers
1502:                            .get(printPage);
1503:                    if (provider == null) {
1504:                        provider = new PageIdentityDataProvider(printPage);
1505:                        providers.put(printPage, provider);
1506:                    }
1507:                    return provider;
1508:                }
1509:
1510:                public static JRVirtualPrintPage.IdentityDataProvider removeIdentityDataProvider(
1511:                        JRPrintPage printPage) {
1512:                    JRVirtualPrintPage.IdentityDataProvider provider = (JRVirtualPrintPage.IdentityDataProvider) providers
1513:                            .remove(printPage);
1514:                    return provider;
1515:                }
1516:            }
1517:
1518:            protected void addPageIdentityDataProvider() {
1519:                JRVirtualPrintPage.IdentityDataProvider pageProvider = PageIdentityDataProvider
1520:                        .getIdentityDataProvider(printPage);
1521:                JRVirtualPrintPage masterPage = (JRVirtualPrintPage) fillContext
1522:                        .getPrintPage();
1523:                masterPage.addIdentityDataProvider(pageProvider);
1524:            }
1525:
1526:            protected void removePageIdentityDataProvider() {
1527:                JRVirtualPrintPage.IdentityDataProvider pageProvider = PageIdentityDataProvider
1528:                        .removeIdentityDataProvider(printPage);
1529:                if (pageProvider != null) {
1530:                    ((JRVirtualPrintPage) fillContext.getPrintPage())
1531:                            .removeIdentityDataProvider(pageProvider);
1532:                }
1533:            }
1534:
1535:            /**
1536:             * Evaluates an expression
1537:             * @param expression the expression
1538:             * @param evaluation the evaluation type
1539:             * @return the evaluation result
1540:             * @throws JRException
1541:             */
1542:            protected Object evaluateExpression(JRExpression expression,
1543:                    byte evaluation) throws JRException {
1544:                return mainDataset.calculator.evaluate(expression, evaluation);
1545:            }
1546:
1547:            private void createDatasets() throws JRException {
1548:                datasetMap = new HashMap();
1549:
1550:                JRDataset[] datasets = jasperReport.getDatasets();
1551:                if (datasets != null && datasets.length > 0) {
1552:                    for (int i = 0; i < datasets.length; i++) {
1553:                        JRFillDataset fillDataset = factory
1554:                                .getDataset(datasets[i]);
1555:                        fillDataset.createCalculator(jasperReport);
1556:
1557:                        datasetMap.put(datasets[i].getName(), fillDataset);
1558:                    }
1559:                }
1560:            }
1561:
1562:            private void initDatasets(JRFillObjectFactory factory) {
1563:                for (Iterator it = datasetMap.values().iterator(); it.hasNext();) {
1564:                    JRFillDataset dataset = (JRFillDataset) it.next();
1565:                    dataset.inheritFromMain();
1566:                    dataset.initElementDatasets(factory);
1567:                }
1568:            }
1569:
1570:            protected byte getWhenResourceMissingType() {
1571:                return mainDataset.whenResourceMissingType;
1572:            }
1573:
1574:            /**
1575:             * Returns the report.
1576:             *
1577:             * @return the report
1578:             */
1579:            protected JasperReport getJasperReport() {
1580:                return jasperReport;
1581:            }
1582:
1583:            protected boolean isBandOverFlowAllowed() {
1584:                return bandOverFlowAllowed;
1585:            }
1586:
1587:            protected void setBandOverFlowAllowed(boolean splittableBand) {
1588:                this .bandOverFlowAllowed = splittableBand;
1589:            }
1590:
1591:            protected int getMasterColumnCount() {
1592:                JRBaseFiller filler = parentFiller;
1593:                int colCount = 1;
1594:
1595:                while (filler != null) {
1596:                    colCount *= filler.columnCount;
1597:                    filler = filler.parentFiller;
1598:                }
1599:
1600:                return colCount;
1601:            }
1602:
1603:            public JRFillDataset getMainDataset() {
1604:                return mainDataset;
1605:            }
1606:
1607:            protected void addBoundElement(JRFillElement element,
1608:                    JRPrintElement printElement, byte evaluationType,
1609:                    JRGroup group, JRFillBand band) {
1610:                JREvaluationTime evaluationTime = JREvaluationTime
1611:                        .getEvaluationTime(evaluationType, group, band);
1612:                addBoundElement(element, printElement, evaluationTime);
1613:            }
1614:
1615:            protected void addBoundElement(JRFillElement element,
1616:                    JRPrintElement printElement, JREvaluationTime evaluationTime) {
1617:                BoundElementMap boundElementsMap = (BoundElementMap) boundElements
1618:                        .get(evaluationTime);
1619:                boundElementsMap.put(printElement, element);
1620:            }
1621:
1622:            /**
1623:             * Collect all of the identity data the the JRBaseFiller needs to know.
1624:             * <p>
1625:             * All the bound elements on the page are collected and transformed into
1626:             * identity objects.
1627:             *
1628:             * @param page
1629:             *            the page to get the identity data for
1630:             */
1631:            public JRVirtualPrintPage.ObjectIDPair[] getIdentityData(
1632:                    JRVirtualPrintPage page) {
1633:                Map allElements = new HashMap();
1634:                List identityList = new ArrayList();
1635:
1636:                for (Iterator it = boundElements.values().iterator(); it
1637:                        .hasNext();) {
1638:                    BoundElementMap pageBoundElementsMap = (BoundElementMap) it
1639:                            .next();
1640:                    Map map = pageBoundElementsMap.getMap(page);
1641:                    if (map != null && !map.isEmpty()) {
1642:                        Map idMap = new HashMap();
1643:
1644:                        for (Iterator iter = map.entrySet().iterator(); iter
1645:                                .hasNext();) {
1646:                            Map.Entry entry = (Map.Entry) iter.next();
1647:                            Object key = entry.getKey();
1648:                            Integer id = (Integer) allElements.get(key);
1649:                            if (id == null) {
1650:                                JRVirtualPrintPage.ObjectIDPair idPair = new JRVirtualPrintPage.ObjectIDPair(
1651:                                        key);
1652:                                identityList.add(idPair);
1653:
1654:                                id = new Integer(idPair.getIdentity());
1655:                                allElements.put(key, id);
1656:                            }
1657:                            idMap.put(id, entry.getValue());
1658:                        }
1659:                        pageBoundElementsMap.putMap(page, idMap);
1660:                    }
1661:                }
1662:
1663:                JRVirtualPrintPage.ObjectIDPair[] identityData = null;
1664:                if (!identityList.isEmpty()) {
1665:                    identityData = new JRVirtualPrintPage.ObjectIDPair[identityList
1666:                            .size()];
1667:                    identityList.toArray(identityData);
1668:                }
1669:
1670:                return identityData;
1671:            }
1672:
1673:            /**
1674:             * Sets the identity date for a virtualized page.
1675:             * <p>
1676:             * The identity data consists of bound elements located on the page.
1677:             * Pairs of identity hash code and objects are stored when the page is
1678:             * virtualized. When the page gets devirtualized, the original objects
1679:             * are substituted in the bound maps based on their identity hash code.
1680:             *
1681:             * @param page
1682:             *            the virtualized page
1683:             * @param identityData
1684:             *            the identity data
1685:             */
1686:            public void setIdentityData(JRVirtualPrintPage page,
1687:                    JRVirtualPrintPage.ObjectIDPair[] identityData) {
1688:                if (identityData == null || identityData.length == 0) {
1689:                    return;
1690:                }
1691:
1692:                for (Iterator it = boundElements.values().iterator(); it
1693:                        .hasNext();) {
1694:                    BoundElementMap pageBoundElementsMap = (BoundElementMap) it
1695:                            .next();
1696:                    Map idMap = pageBoundElementsMap.getMap(page);
1697:                    if (idMap != null && !idMap.isEmpty()) {
1698:                        Map map = new HashMap();
1699:
1700:                        for (int i = 0; i < identityData.length; i++) {
1701:                            JRVirtualPrintPage.ObjectIDPair idPair = identityData[i];
1702:                            Integer id = new Integer(idPair.getIdentity());
1703:
1704:                            Object value = idMap.get(id);
1705:                            if (value != null) {
1706:                                map.put(idPair.getObject(), value);
1707:                            }
1708:                        }
1709:
1710:                        pageBoundElementsMap.putMap(page, map);
1711:                    }
1712:                }
1713:            }
1714:
1715:            //	protected JRStyle getConsolidatedStyle(String consolidatedStyleName)
1716:            //	{
1717:            //		return (JRStyle) consolidatedStyles.get(consolidatedStyleName);
1718:            //	}
1719:            //
1720:            //
1721:            //	protected void putConsolidatedStyle(JRStyle consolidatedStyle)
1722:            //	{
1723:            //		consolidatedStyles.put(consolidatedStyle.getName(), consolidatedStyle);
1724:            //	}
1725:
1726:            protected void setSubreportRunner(JRSubreportRunner runner) {
1727:                this .subreportRunner = runner;
1728:            }
1729:
1730:            protected void suspendSubreportRunner() throws JRException {
1731:                if (subreportRunner == null) {
1732:                    throw new JRRuntimeException("No subreport runner set.");
1733:                }
1734:
1735:                if (log.isDebugEnabled()) {
1736:                    log.debug("Fill " + fillerId
1737:                            + ": suspeding subreport runner");
1738:                }
1739:
1740:                subreportRunner.suspend();
1741:            }
1742:
1743:            protected void createReportTemplates(JRFillObjectFactory factory) {
1744:                JRReportTemplate[] templates = jasperReport.getTemplates();
1745:                if (templates != null) {
1746:                    reportTemplates = new JRFillReportTemplate[templates.length];
1747:
1748:                    for (int i = 0; i < templates.length; i++) {
1749:                        JRReportTemplate template = templates[i];
1750:                        reportTemplates[i] = factory
1751:                                .getReportTemplate(template);
1752:                    }
1753:                }
1754:            }
1755:
1756:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.