Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2023 Cloud Software Group, Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.engine.fill;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JRVirtualizable;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.PrintElementVisitor;
import net.sf.jasperreports.engine.base.JRVirtualPrintPage;
import net.sf.jasperreports.engine.base.VirtualElementsData;
import net.sf.jasperreports.engine.base.VirtualizableElementList;
import net.sf.jasperreports.engine.base.VirtualizablePageElements;
import net.sf.jasperreports.engine.type.EvaluationTimeEnum;
import net.sf.jasperreports.engine.util.LinkedMap;
import net.sf.jasperreports.engine.util.UniformPrintElementVisitor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Lucian Chirita ([email protected])
*/
public class DelayedFillActions implements VirtualizationListener
{
private static final Log log = LogFactory.getLog(DelayedFillActions.class);
protected static final String FILL_CACHE_KEY_ID = DelayedFillActions.class.getName() + "#id";
public static final String EXCEPTION_MESSAGE_KEY_ELEMENT_NOT_FOUND = "fill.delayed.fill.actions.element.not.found";
private final int id;
private final BaseReportFiller reportFiller;
private final JRFillContext fillContext;
// we can use HashMap because the map is initialized in the beginning and doesn't change afterwards
private final HashMap>> actionsMap;
private Map fillElements;
private Set masterFillElementIds;
private Set listenedContexts;
private Set transferredIds;
public DelayedFillActions(BaseReportFiller reportFiller)
{
this.id = assignId(reportFiller);
this.reportFiller = reportFiller;
this.fillContext = reportFiller.fillContext;
this.actionsMap = new HashMap<>();
this.fillElements = new HashMap<>();
this.masterFillElementIds = new HashSet<>();
this.listenedContexts = new HashSet<>();
}
private static int assignId(BaseReportFiller reportFiller)
{
AtomicInteger counter = (AtomicInteger) reportFiller.fillContext.getFillCache(FILL_CACHE_KEY_ID);
if (counter == null)
{
// we just need a mutable integer, there's no actual concurrency here
counter = new AtomicInteger();
reportFiller.fillContext.setFillCache(FILL_CACHE_KEY_ID, counter);
}
return counter.incrementAndGet();
}
public int getId()
{
return id;
}
public void createDelayedEvaluationTime(JREvaluationTime evaluationTime)
{
LinkedHashMap> evaluationActions = new LinkedHashMap<>();
actionsMap.put(evaluationTime, evaluationActions);
}
protected void registerPage(JRPrintPage page)
{
if (page instanceof JRVirtualPrintPage)
{
JRVirtualizationContext virtualizationContext = ((JRVirtualPrintPage) page).getVirtualizationContext();
if (!listenedContexts.contains(virtualizationContext))
{
//FIXMEBOOK part reports use a single context which will collect all listeners
virtualizationContext.addListener(this);
listenedContexts.add(virtualizationContext);
if (log.isDebugEnabled())
{
log.debug(id + " registered virtualization listener on " + virtualizationContext);
}
}
}
}
public void dispose()
{
for (JRVirtualizationContext virtualizationContext : listenedContexts)
{
virtualizationContext.removeListener(this);
if (log.isDebugEnabled())
{
log.debug(id + " unregistered virtualization listener on " + virtualizationContext);
}
}
}
public void addDelayedAction(JRFillElement element, JRPrintElement printElement, JREvaluationTime evaluationTime, FillPageKey pageKey)
{
registerFillElement(element, evaluationTime);
ElementEvaluationAction action = new ElementEvaluationAction(element, printElement);
addDelayedAction(printElement, action, evaluationTime, pageKey);
}
protected void registerFillElement(JRFillElement element, JREvaluationTime evaluationTime)
{
int fillElementId = element.printElementOriginator.getSourceElementId();
if (!fillElements.containsKey(fillElementId))
{
fillElements.put(fillElementId, element);
if (evaluationTime.getType() == EvaluationTimeEnum.MASTER)
{
masterFillElementIds.add(fillElementId);
}
}
}
protected void registerTransferredId(int sourceId)
{
if (transferredIds == null)
{
transferredIds = new HashSet<>();
}
// duplicates are handled
boolean added = transferredIds.add(sourceId);
if (added && log.isDebugEnabled())
{
log.debug(id + " transferred id " + sourceId);
}
}
public void addDelayedAction(Object actionKey, EvaluationBoundAction action,
JREvaluationTime evaluationTime, FillPageKey pageKey)
{
if (log.isDebugEnabled())
{
log.debug(id + " adding delayed action " + action + " at " + evaluationTime + ", key " + pageKey);
}
// get the pages map for the evaluation
LinkedHashMap> pagesMap = actionsMap.get(evaluationTime);
fillContext.lockVirtualizationContext();
try
{
synchronized (pagesMap)
{
// get the actions map for the current page, creating if it does not yet exist
LinkedMap