KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseSubreport


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

48 public class JRBaseSubreport extends JRBaseElement implements JRSubreport
49 {
50
51
52     /**
53      *
54      */

55     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
56
57     /**
58      *
59      */

60     protected Boolean JavaDoc isUsingCache = null;
61
62     /**
63      *
64      */

65     protected JRExpression parametersMapExpression = null;
66     protected JRSubreportParameter[] parameters = null;
67     protected JRExpression connectionExpression = null;
68     protected JRExpression dataSourceExpression = null;
69     protected JRExpression expression = null;
70     
71     /**
72      * Values to be copied from the subreport into the master report.
73      */

74     protected JRSubreportReturnValue[] returnValues = null;
75
76
77     /**
78      *
79      */

80     public byte getMode()
81     {
82         return JRStyleResolver.getMode(this, MODE_TRANSPARENT);
83     }
84
85
86     /**
87      *
88      */

89     protected JRBaseSubreport(JRSubreport subreport, JRBaseObjectFactory factory)
90     {
91         super(subreport, factory);
92         
93         isUsingCache = subreport.isOwnUsingCache();
94
95         parametersMapExpression = factory.getExpression(subreport.getParametersMapExpression());
96
97         /* */
98         JRSubreportParameter[] jrSubreportParameters = subreport.getParameters();
99         if (jrSubreportParameters != null && jrSubreportParameters.length > 0)
100         {
101             parameters = new JRSubreportParameter[jrSubreportParameters.length];
102             for(int i = 0; i < parameters.length; i++)
103             {
104                 parameters[i] = factory.getSubreportParameter(jrSubreportParameters[i]);
105             }
106         }
107
108         connectionExpression = factory.getExpression(subreport.getConnectionExpression());
109         dataSourceExpression = factory.getExpression(subreport.getDataSourceExpression());
110         
111         JRSubreportReturnValue[] subrepReturnValues = subreport.getReturnValues();
112         if (subrepReturnValues != null && subrepReturnValues.length > 0)
113         {
114             this.returnValues = new JRSubreportReturnValue[subrepReturnValues.length];
115             for (int i = 0; i < subrepReturnValues.length; i++)
116             {
117                 this.returnValues[i] = factory.getSubreportReturnValue(subrepReturnValues[i]);
118             }
119         }
120         
121         expression = factory.getExpression(subreport.getExpression());
122     }
123         
124
125     /**
126      *
127      */

128     public boolean isUsingCache()
129     {
130         if (isUsingCache == null)
131         {
132             JRExpression subreportExpression = getExpression();
133             if (subreportExpression != null)
134             {
135                 return String JavaDoc.class.getName().equals(subreportExpression.getValueClassName());
136             }
137             return true;
138         }
139         return isUsingCache.booleanValue();
140     }
141
142
143     /**
144      * @deprecated Replaced by {@link #setUsingCache(Boolean)}.
145      */

146     public void setUsingCache(boolean isUsingCache)
147     {
148         setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
149     }
150
151
152     /**
153      *
154      */

155     public JRExpression getParametersMapExpression()
156     {
157         return this.parametersMapExpression;
158     }
159
160
161     /**
162      *
163      */

164     public JRSubreportParameter[] getParameters()
165     {
166         return this.parameters;
167     }
168
169
170     /**
171      *
172      */

173     public JRExpression getConnectionExpression()
174     {
175         return this.connectionExpression;
176     }
177
178
179     /**
180      *
181      */

182     public JRExpression getDataSourceExpression()
183     {
184         return this.dataSourceExpression;
185     }
186
187
188     /**
189      *
190      */

191     public JRExpression getExpression()
192     {
193         return this.expression;
194     }
195     
196     /**
197      *
198      */

199     public JRChild getCopy(JRAbstractObjectFactory factory)
200     {
201         return factory.getSubreport(this);
202     }
203
204     /**
205      *
206      */

207     public void collectExpressions(JRExpressionCollector collector)
208     {
209         collector.collect(this);
210     }
211
212     /**
213      *
214      */

215     public void writeXml(JRXmlWriter xmlWriter) throws IOException JavaDoc
216     {
217         xmlWriter.writeSubreport(this);
218     }
219
220
221     /**
222      * Returns the list of values to be copied from the subreport into the master.
223      *
224      * @return the list of values to be copied from the subreport into the master.
225      */

226     public JRSubreportReturnValue[] getReturnValues()
227     {
228         return this.returnValues;
229     }
230
231
232     public Boolean JavaDoc isOwnUsingCache()
233     {
234         return isUsingCache;
235     }
236
237
238     public void setUsingCache(Boolean JavaDoc isUsingCache)
239     {
240         this.isUsingCache = isUsingCache;
241     }
242
243
244 }
245
Popular Tags