KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import net.sf.jasperreports.engine.JRAbstractObjectFactory;
37 import net.sf.jasperreports.engine.JRChild;
38 import net.sf.jasperreports.engine.JRConstants;
39 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
40 import net.sf.jasperreports.engine.JRException;
41 import net.sf.jasperreports.engine.JRExpression;
42 import net.sf.jasperreports.engine.JRExpressionCollector;
43 import net.sf.jasperreports.engine.JRSubreport;
44 import net.sf.jasperreports.engine.JRSubreportParameter;
45 import net.sf.jasperreports.engine.JRSubreportReturnValue;
46 import net.sf.jasperreports.engine.util.JRStyleResolver;
47 import net.sf.jasperreports.engine.xml.JRXmlWriter;
48
49
50 /**
51  * @author Teodor Danciu (teodord@users.sourceforge.net)
52  * @version $Id: JRDesignSubreport.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
53  */

54 public class JRDesignSubreport extends JRDesignElement implements JRSubreport
55 {
56
57
58     /**
59      *
60      */

61     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
62
63     /**
64      *
65      */

66     protected Boolean JavaDoc isUsingCache = null;
67
68     /**
69      *
70      */

71     protected Map JavaDoc parametersMap = new HashMap JavaDoc();
72     
73     /**
74      * Values to be copied from the subreport into the master report.
75      */

76     protected List JavaDoc returnValues = new ArrayList JavaDoc();
77
78     /**
79      *
80      */

81     protected JRExpression parametersMapExpression = null;
82     protected JRExpression connectionExpression = null;
83     protected JRExpression dataSourceExpression = null;
84     protected JRExpression expression = null;
85
86
87     /**
88      *
89      */

90     public JRDesignSubreport(JRDefaultStyleProvider defaultStyleProvider)
91     {
92         super(defaultStyleProvider);
93     }
94         
95
96     /**
97      *
98      */

99     public byte getMode()
100     {
101         return JRStyleResolver.getMode(this, MODE_TRANSPARENT);
102     }
103
104
105     /**
106      *
107      */

108     public boolean isUsingCache()
109     {
110         if (isUsingCache == null)
111         {
112             JRExpression subreportExpression = getExpression();
113             if (subreportExpression != null)
114             {
115                 return String JavaDoc.class.getName().equals(subreportExpression.getValueClassName());
116             }
117             return true;
118         }
119         return isUsingCache.booleanValue();
120     }
121
122     /**
123      * @deprecated Replaced by {@link #setUsingCache(Boolean)}.
124      */

125     public void setUsingCache(boolean isUsingCache)
126     {
127         setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
128     }
129
130     /**
131      *
132      */

133     public JRExpression getParametersMapExpression()
134     {
135         return this.parametersMapExpression;
136     }
137
138     /**
139      *
140      */

141     public void setParametersMapExpression(JRExpression parametersMapExpression)
142     {
143         this.parametersMapExpression = parametersMapExpression;
144     }
145
146     /**
147      *
148      */

149     public JRSubreportParameter[] getParameters()
150     {
151         JRSubreportParameter[] parametersArray = new JRSubreportParameter[parametersMap.size()];
152         
153         parametersMap.values().toArray(parametersArray);
154
155         return parametersArray;
156     }
157     
158     /**
159      *
160      */

161     public Map JavaDoc getParametersMap()
162     {
163         return this.parametersMap;
164     }
165     
166     /**
167      *
168      */

169     public void addParameter(JRSubreportParameter subreportParameter) throws JRException
170     {
171         if (this.parametersMap.containsKey(subreportParameter.getName()))
172         {
173             throw new JRException("Duplicate declaration of subreport parameter : " + subreportParameter.getName());
174         }
175
176         this.parametersMap.put(subreportParameter.getName(), subreportParameter);
177     }
178     
179     /**
180      *
181      */

182     public JRSubreportParameter removeParameter(String JavaDoc name)
183     {
184         return (JRSubreportParameter)this.parametersMap.remove(name);
185     }
186
187     /**
188      *
189      */

190     public JRExpression getConnectionExpression()
191     {
192         return this.connectionExpression;
193     }
194
195     /**
196      *
197      */

198     public void setConnectionExpression(JRExpression connectionExpression)
199     {
200         this.connectionExpression = connectionExpression;
201         this.dataSourceExpression = null;
202     }
203
204     /**
205      *
206      */

207     public JRExpression getDataSourceExpression()
208     {
209         return this.dataSourceExpression;
210     }
211
212     /**
213      *
214      */

215     public void setDataSourceExpression(JRExpression dataSourceExpression)
216     {
217         this.dataSourceExpression = dataSourceExpression;
218     }
219
220     /**
221      *
222      */

223     public JRExpression getExpression()
224     {
225         return this.expression;
226     }
227
228     /**
229      *
230      */

231     public void setExpression(JRExpression expression)
232     {
233         this.expression = expression;
234     }
235     
236     /**
237      *
238      */

239     public JRChild getCopy(JRAbstractObjectFactory factory)
240     {
241         return factory.getSubreport(this);
242     }
243
244     /**
245      *
246      */

247     public void collectExpressions(JRExpressionCollector collector)
248     {
249         collector.collect(this);
250     }
251
252     /**
253      *
254      */

255     public void writeXml(JRXmlWriter xmlWriter) throws IOException JavaDoc
256     {
257         xmlWriter.writeSubreport(this);
258     }
259
260     
261     /**
262      * Adds a return value to the subreport.
263      *
264      * @param returnValue the return value to be added.
265      */

266     public void addReturnValue(JRSubreportReturnValue returnValue)
267     {
268         this.returnValues.add(returnValue);
269     }
270
271     
272     /**
273      * Returns the list of values to be copied from the subreport into the master.
274      *
275      * @return the list of values to be copied from the subreport into the master.
276      */

277     public JRSubreportReturnValue[] getReturnValues()
278     {
279         JRSubreportReturnValue[] returnValuesArray = new JRSubreportReturnValue[returnValues.size()];
280
281         returnValues.toArray(returnValuesArray);
282
283         return returnValuesArray;
284     }
285
286     
287     /**
288      * Returns the list of values to be copied from the subreport into the master.
289      *
290      * @return list of {@link JRSubreportReturnValue JRSubreportReturnValue} objects
291      */

292     public List JavaDoc getReturnValuesList()
293     {
294         return returnValues;
295     }
296
297     
298     /**
299      * Removes a return value from the subreport.
300      *
301      * @param returnValue the return value to be removed
302      * @return <code>true</code> if the return value was found and removed
303      */

304     public boolean removeReturnValue(JRSubreportReturnValue returnValue)
305     {
306         return this.returnValues.remove(returnValue);
307     }
308
309
310     public Boolean JavaDoc isOwnUsingCache()
311     {
312         return isUsingCache;
313     }
314
315
316     public void setUsingCache(Boolean JavaDoc isUsingCache)
317     {
318         this.isUsingCache = isUsingCache;
319     }
320 }
321
Popular Tags