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.base;
029:
030: import java.io.IOException;
031:
032: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
033: import net.sf.jasperreports.engine.JRChild;
034: import net.sf.jasperreports.engine.JRConstants;
035: import net.sf.jasperreports.engine.JRExpression;
036: import net.sf.jasperreports.engine.JRExpressionCollector;
037: import net.sf.jasperreports.engine.JRSubreport;
038: import net.sf.jasperreports.engine.JRSubreportParameter;
039: import net.sf.jasperreports.engine.JRSubreportReturnValue;
040: import net.sf.jasperreports.engine.util.JRStyleResolver;
041: import net.sf.jasperreports.engine.xml.JRXmlWriter;
042:
043: /**
044: * @author Teodor Danciu (teodord@users.sourceforge.net)
045: * @version $Id: JRBaseSubreport.java 1229 2006-04-19 10:27:35Z teodord $
046: */
047: public class JRBaseSubreport extends JRBaseElement implements
048: JRSubreport {
049:
050: /**
051: *
052: */
053: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
054:
055: /**
056: *
057: */
058: protected Boolean isUsingCache = null;
059:
060: /**
061: *
062: */
063: protected JRExpression parametersMapExpression = null;
064: protected JRSubreportParameter[] parameters = null;
065: protected JRExpression connectionExpression = null;
066: protected JRExpression dataSourceExpression = null;
067: protected JRExpression expression = null;
068:
069: /**
070: * Values to be copied from the subreport into the master report.
071: */
072: protected JRSubreportReturnValue[] returnValues = null;
073:
074: /**
075: *
076: */
077: public byte getMode() {
078: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
079: }
080:
081: /**
082: *
083: */
084: protected JRBaseSubreport(JRSubreport subreport,
085: JRBaseObjectFactory factory) {
086: super (subreport, factory);
087:
088: isUsingCache = subreport.isOwnUsingCache();
089:
090: parametersMapExpression = factory.getExpression(subreport
091: .getParametersMapExpression());
092:
093: /* */
094: JRSubreportParameter[] jrSubreportParameters = subreport
095: .getParameters();
096: if (jrSubreportParameters != null
097: && jrSubreportParameters.length > 0) {
098: parameters = new JRSubreportParameter[jrSubreportParameters.length];
099: for (int i = 0; i < parameters.length; i++) {
100: parameters[i] = factory
101: .getSubreportParameter(jrSubreportParameters[i]);
102: }
103: }
104:
105: connectionExpression = factory.getExpression(subreport
106: .getConnectionExpression());
107: dataSourceExpression = factory.getExpression(subreport
108: .getDataSourceExpression());
109:
110: JRSubreportReturnValue[] subrepReturnValues = subreport
111: .getReturnValues();
112: if (subrepReturnValues != null && subrepReturnValues.length > 0) {
113: this .returnValues = new JRSubreportReturnValue[subrepReturnValues.length];
114: for (int i = 0; i < subrepReturnValues.length; i++) {
115: this .returnValues[i] = factory
116: .getSubreportReturnValue(subrepReturnValues[i]);
117: }
118: }
119:
120: expression = factory.getExpression(subreport.getExpression());
121: }
122:
123: /**
124: *
125: */
126: public boolean isUsingCache() {
127: if (isUsingCache == null) {
128: JRExpression subreportExpression = getExpression();
129: if (subreportExpression != null) {
130: return String.class.getName().equals(
131: subreportExpression.getValueClassName());
132: }
133: return true;
134: }
135: return isUsingCache.booleanValue();
136: }
137:
138: /**
139: * @deprecated Replaced by {@link #setUsingCache(Boolean)}.
140: */
141: public void setUsingCache(boolean isUsingCache) {
142: setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
143: }
144:
145: /**
146: *
147: */
148: public JRExpression getParametersMapExpression() {
149: return this .parametersMapExpression;
150: }
151:
152: /**
153: *
154: */
155: public JRSubreportParameter[] getParameters() {
156: return this .parameters;
157: }
158:
159: /**
160: *
161: */
162: public JRExpression getConnectionExpression() {
163: return this .connectionExpression;
164: }
165:
166: /**
167: *
168: */
169: public JRExpression getDataSourceExpression() {
170: return this .dataSourceExpression;
171: }
172:
173: /**
174: *
175: */
176: public JRExpression getExpression() {
177: return this .expression;
178: }
179:
180: /**
181: *
182: */
183: public JRChild getCopy(JRAbstractObjectFactory factory) {
184: return factory.getSubreport(this );
185: }
186:
187: /**
188: *
189: */
190: public void collectExpressions(JRExpressionCollector collector) {
191: collector.collect(this );
192: }
193:
194: /**
195: *
196: */
197: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
198: xmlWriter.writeSubreport(this );
199: }
200:
201: /**
202: * Returns the list of values to be copied from the subreport into the master.
203: *
204: * @return the list of values to be copied from the subreport into the master.
205: */
206: public JRSubreportReturnValue[] getReturnValues() {
207: return this .returnValues;
208: }
209:
210: public Boolean isOwnUsingCache() {
211: return isUsingCache;
212: }
213:
214: public void setUsingCache(Boolean isUsingCache) {
215: this.isUsingCache = isUsingCache;
216: }
217:
218: }
|