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.IOException;
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.List;
034: import java.util.Map;
035:
036: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
037: import net.sf.jasperreports.engine.JRChild;
038: import net.sf.jasperreports.engine.JRConstants;
039: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
040: import net.sf.jasperreports.engine.JRException;
041: import net.sf.jasperreports.engine.JRExpression;
042: import net.sf.jasperreports.engine.JRExpressionCollector;
043: import net.sf.jasperreports.engine.JRSubreport;
044: import net.sf.jasperreports.engine.JRSubreportParameter;
045: import net.sf.jasperreports.engine.JRSubreportReturnValue;
046: import net.sf.jasperreports.engine.util.JRStyleResolver;
047: import net.sf.jasperreports.engine.xml.JRXmlWriter;
048:
049: /**
050: * @author Teodor Danciu (teodord@users.sourceforge.net)
051: * @version $Id: JRDesignSubreport.java 1229 2006-04-19 10:27:35Z teodord $
052: */
053: public class JRDesignSubreport extends JRDesignElement implements
054: JRSubreport {
055:
056: /**
057: *
058: */
059: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
060:
061: /**
062: *
063: */
064: protected Boolean isUsingCache = null;
065:
066: /**
067: *
068: */
069: protected Map parametersMap = new HashMap();
070:
071: /**
072: * Values to be copied from the subreport into the master report.
073: */
074: protected List returnValues = new ArrayList();
075:
076: /**
077: *
078: */
079: protected JRExpression parametersMapExpression = null;
080: protected JRExpression connectionExpression = null;
081: protected JRExpression dataSourceExpression = null;
082: protected JRExpression expression = null;
083:
084: /**
085: *
086: */
087: public JRDesignSubreport(JRDefaultStyleProvider defaultStyleProvider) {
088: super (defaultStyleProvider);
089: }
090:
091: /**
092: *
093: */
094: public byte getMode() {
095: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
096: }
097:
098: /**
099: *
100: */
101: public boolean isUsingCache() {
102: if (isUsingCache == null) {
103: JRExpression subreportExpression = getExpression();
104: if (subreportExpression != null) {
105: return String.class.getName().equals(
106: subreportExpression.getValueClassName());
107: }
108: return true;
109: }
110: return isUsingCache.booleanValue();
111: }
112:
113: /**
114: * @deprecated Replaced by {@link #setUsingCache(Boolean)}.
115: */
116: public void setUsingCache(boolean isUsingCache) {
117: setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
118: }
119:
120: /**
121: *
122: */
123: public JRExpression getParametersMapExpression() {
124: return this .parametersMapExpression;
125: }
126:
127: /**
128: *
129: */
130: public void setParametersMapExpression(
131: JRExpression parametersMapExpression) {
132: this .parametersMapExpression = parametersMapExpression;
133: }
134:
135: /**
136: *
137: */
138: public JRSubreportParameter[] getParameters() {
139: JRSubreportParameter[] parametersArray = new JRSubreportParameter[parametersMap
140: .size()];
141:
142: parametersMap.values().toArray(parametersArray);
143:
144: return parametersArray;
145: }
146:
147: /**
148: *
149: */
150: public Map getParametersMap() {
151: return this .parametersMap;
152: }
153:
154: /**
155: *
156: */
157: public void addParameter(JRSubreportParameter subreportParameter)
158: throws JRException {
159: if (this .parametersMap
160: .containsKey(subreportParameter.getName())) {
161: throw new JRException(
162: "Duplicate declaration of subreport parameter : "
163: + subreportParameter.getName());
164: }
165:
166: this .parametersMap.put(subreportParameter.getName(),
167: subreportParameter);
168: }
169:
170: /**
171: *
172: */
173: public JRSubreportParameter removeParameter(String name) {
174: return (JRSubreportParameter) this .parametersMap.remove(name);
175: }
176:
177: /**
178: *
179: */
180: public JRExpression getConnectionExpression() {
181: return this .connectionExpression;
182: }
183:
184: /**
185: *
186: */
187: public void setConnectionExpression(
188: JRExpression connectionExpression) {
189: this .connectionExpression = connectionExpression;
190: this .dataSourceExpression = null;
191: }
192:
193: /**
194: *
195: */
196: public JRExpression getDataSourceExpression() {
197: return this .dataSourceExpression;
198: }
199:
200: /**
201: *
202: */
203: public void setDataSourceExpression(
204: JRExpression dataSourceExpression) {
205: this .dataSourceExpression = dataSourceExpression;
206: }
207:
208: /**
209: *
210: */
211: public JRExpression getExpression() {
212: return this .expression;
213: }
214:
215: /**
216: *
217: */
218: public void setExpression(JRExpression expression) {
219: this .expression = expression;
220: }
221:
222: /**
223: *
224: */
225: public JRChild getCopy(JRAbstractObjectFactory factory) {
226: return factory.getSubreport(this );
227: }
228:
229: /**
230: *
231: */
232: public void collectExpressions(JRExpressionCollector collector) {
233: collector.collect(this );
234: }
235:
236: /**
237: *
238: */
239: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
240: xmlWriter.writeSubreport(this );
241: }
242:
243: /**
244: * Adds a return value to the subreport.
245: *
246: * @param returnValue the return value to be added.
247: */
248: public void addReturnValue(JRSubreportReturnValue returnValue) {
249: this .returnValues.add(returnValue);
250: }
251:
252: /**
253: * Returns the list of values to be copied from the subreport into the master.
254: *
255: * @return the list of values to be copied from the subreport into the master.
256: */
257: public JRSubreportReturnValue[] getReturnValues() {
258: JRSubreportReturnValue[] returnValuesArray = new JRSubreportReturnValue[returnValues
259: .size()];
260:
261: returnValues.toArray(returnValuesArray);
262:
263: return returnValuesArray;
264: }
265:
266: /**
267: * Returns the list of values to be copied from the subreport into the master.
268: *
269: * @return list of {@link JRSubreportReturnValue JRSubreportReturnValue} objects
270: */
271: public List getReturnValuesList() {
272: return returnValues;
273: }
274:
275: /**
276: * Removes a return value from the subreport.
277: *
278: * @param returnValue the return value to be removed
279: * @return <code>true</code> if the return value was found and removed
280: */
281: public boolean removeReturnValue(JRSubreportReturnValue returnValue) {
282: return this .returnValues.remove(returnValue);
283: }
284:
285: public Boolean isOwnUsingCache() {
286: return isUsingCache;
287: }
288:
289: public void setUsingCache(Boolean isUsingCache) {
290: this.isUsingCache = isUsingCache;
291: }
292: }
|