KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > design > JRReportCompileData


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.design;
29
30 import java.io.Serializable JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import net.sf.jasperreports.crosstabs.JRCrosstab;
35 import net.sf.jasperreports.engine.JRConstants;
36 import net.sf.jasperreports.engine.JRDataset;
37 import net.sf.jasperreports.engine.JRException;
38
39 /**
40  * Structure used to hold a report's expression evaluator compile data.
41  * <p>
42  * An instantce consists of expression evaluators for the main report dataset
43  * and for sub datasets.
44  *
45  * @author Lucian Chirita (lucianc@users.sourceforge.net)
46  * @version $Id: JRReportCompileData.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
47  *
48  * @see net.sf.jasperreports.engine.JasperReport#getCompileData()
49  */

50 public class JRReportCompileData implements Serializable JavaDoc
51 {
52     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
53
54     /**
55      * Main report dataset compile data.
56      */

57     private Serializable JavaDoc mainDatasetCompileData;
58     
59     /**
60      * Map containing compiled data per sub dataset name.
61      */

62     private Map JavaDoc datasetCompileData;
63     
64     /**
65      * Map containing compiled data per crosstab name.
66      */

67     private Map JavaDoc crosstabCompileData;
68     
69     
70     /**
71      * Default constructor.
72      */

73     public JRReportCompileData()
74     {
75         datasetCompileData = new HashMap JavaDoc();
76         crosstabCompileData = new HashMap JavaDoc();
77     }
78     
79     
80     /**
81      * Sets the main dataset compile data.
82      *
83      * @param compileData the main dataset compile data
84      */

85     public void setMainDatasetCompileData(Serializable JavaDoc compileData)
86     {
87         mainDatasetCompileData = compileData;
88     }
89     
90     
91     /**
92      * Sets the compile data for a dataset.
93      *
94      * @param dataset the dataset
95      * @param compileData the compile data
96      */

97     public void setDatasetCompileData(JRDataset dataset, Serializable JavaDoc compileData)
98     {
99         if (dataset.isMainDataset())
100         {
101             setMainDatasetCompileData(compileData);
102         }
103         else
104         {
105             datasetCompileData.put(dataset.getName(), compileData);
106         }
107     }
108     
109     
110     /**
111      * Sets the compile data for a crosstab.
112      *
113      * @param crosstabId the generated crosstab Id, which will be used to retreive the crosstab compile data at fill time.
114      * @param compileData the compile data
115      */

116     public void setCrosstabCompileData(int crosstabId, Serializable JavaDoc compileData)
117     {
118         crosstabCompileData.put(new Integer JavaDoc(crosstabId), compileData);
119     }
120     
121     
122     /**
123      * Returns the compile data for the main dataset.
124      *
125      * @return the compile data for the main dataset
126      */

127     public Serializable JavaDoc getMainDatasetCompileData()
128     {
129         return mainDatasetCompileData;
130     }
131     
132     
133     /**
134      * Returns the compile data for a dataset.
135      *
136      * @param dataset the dataset
137      * @return the compile data
138      * @throws JRException
139      */

140     public Serializable JavaDoc getDatasetCompileData(JRDataset dataset) throws JRException
141     {
142         Serializable JavaDoc compileData;
143         if (dataset.isMainDataset())
144         {
145             compileData = getMainDatasetCompileData();
146         }
147         else
148         {
149             compileData = (Serializable JavaDoc) datasetCompileData.get(dataset.getName());
150             if (compileData == null)
151             {
152                 throw new JRException("Compile data for dataset " + dataset.getName() + " not found in the report.");
153             }
154         }
155         
156         return compileData;
157     }
158     
159     
160     /**
161      * Returns the compile data for a crosstab.
162      *
163      * @param crosstab the crosstab
164      * @return the compile data
165      * @throws JRException
166      */

167     public Serializable JavaDoc getCrosstabCompileData(JRCrosstab crosstab) throws JRException
168     {
169         Serializable JavaDoc compileData = (Serializable JavaDoc) crosstabCompileData.get(new Integer JavaDoc(crosstab.getId()));
170         if (compileData == null)
171         {
172             throw new JRException("Compile data for crosstab not found in the report.");
173         }
174         
175         return compileData;
176     }
177 }
178
Popular Tags