001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.design;
029:
030: import java.io.Serializable;
031: import java.util.HashMap;
032: import java.util.Map;
033:
034: import net.sf.jasperreports.crosstabs.JRCrosstab;
035: import net.sf.jasperreports.engine.JRConstants;
036: import net.sf.jasperreports.engine.JRDataset;
037: import net.sf.jasperreports.engine.JRException;
038:
039: /**
040: * Structure used to hold a report's expression evaluator compile data.
041: * <p>
042: * An instantce consists of expression evaluators for the main report dataset
043: * and for sub datasets.
044: *
045: * @author Lucian Chirita (lucianc@users.sourceforge.net)
046: * @version $Id: JRReportCompileData.java 1229 2006-04-19 10:27:35Z teodord $
047: *
048: * @see net.sf.jasperreports.engine.JasperReport#getCompileData()
049: */
050: public class JRReportCompileData implements Serializable {
051: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
052:
053: /**
054: * Main report dataset compile data.
055: */
056: private Serializable mainDatasetCompileData;
057:
058: /**
059: * Map containing compiled data per sub dataset name.
060: */
061: private Map datasetCompileData;
062:
063: /**
064: * Map containing compiled data per crosstab name.
065: */
066: private Map crosstabCompileData;
067:
068: /**
069: * Default constructor.
070: */
071: public JRReportCompileData() {
072: datasetCompileData = new HashMap();
073: crosstabCompileData = new HashMap();
074: }
075:
076: /**
077: * Sets the main dataset compile data.
078: *
079: * @param compileData the main dataset compile data
080: */
081: public void setMainDatasetCompileData(Serializable compileData) {
082: mainDatasetCompileData = compileData;
083: }
084:
085: /**
086: * Sets the compile data for a dataset.
087: *
088: * @param dataset the dataset
089: * @param compileData the compile data
090: */
091: public void setDatasetCompileData(JRDataset dataset,
092: Serializable compileData) {
093: if (dataset.isMainDataset()) {
094: setMainDatasetCompileData(compileData);
095: } else {
096: datasetCompileData.put(dataset.getName(), compileData);
097: }
098: }
099:
100: /**
101: * Sets the compile data for a crosstab.
102: *
103: * @param crosstabId the generated crosstab Id, which will be used to retreive the crosstab compile data at fill time.
104: * @param compileData the compile data
105: */
106: public void setCrosstabCompileData(int crosstabId,
107: Serializable compileData) {
108: crosstabCompileData.put(new Integer(crosstabId), compileData);
109: }
110:
111: /**
112: * Returns the compile data for the main dataset.
113: *
114: * @return the compile data for the main dataset
115: */
116: public Serializable getMainDatasetCompileData() {
117: return mainDatasetCompileData;
118: }
119:
120: /**
121: * Returns the compile data for a dataset.
122: *
123: * @param dataset the dataset
124: * @return the compile data
125: * @throws JRException
126: */
127: public Serializable getDatasetCompileData(JRDataset dataset)
128: throws JRException {
129: Serializable compileData;
130: if (dataset.isMainDataset()) {
131: compileData = getMainDatasetCompileData();
132: } else {
133: compileData = (Serializable) datasetCompileData.get(dataset
134: .getName());
135: if (compileData == null) {
136: throw new JRException("Compile data for dataset "
137: + dataset.getName()
138: + " not found in the report.");
139: }
140: }
141:
142: return compileData;
143: }
144:
145: /**
146: * Returns the compile data for a crosstab.
147: *
148: * @param crosstab the crosstab
149: * @return the compile data
150: * @throws JRException
151: */
152: public Serializable getCrosstabCompileData(JRCrosstab crosstab)
153: throws JRException {
154: Serializable compileData = (Serializable) crosstabCompileData
155: .get(new Integer(crosstab.getId()));
156: if (compileData == null) {
157: throw new JRException(
158: "Compile data for crosstab not found in the report.");
159: }
160:
161: return compileData;
162: }
163: }
|