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.util.ArrayList;
031: import java.util.HashMap;
032: import java.util.List;
033: import java.util.Map;
034:
035: import net.sf.jasperreports.engine.JRConstants;
036: import net.sf.jasperreports.engine.JRDatasetParameter;
037: import net.sf.jasperreports.engine.JRException;
038: import net.sf.jasperreports.engine.JRExpression;
039: import net.sf.jasperreports.engine.base.JRBaseDatasetRun;
040:
041: /**
042: * Implementation of {@link net.sf.jasperreports.engine.JRDatasetRun JRDatasetRun} to be used for report desing.
043: *
044: * @author Lucian Chirita (lucianc@users.sourceforge.net)
045: * @version $Id: JRDesignDatasetRun.java 1229 2006-04-19 10:27:35Z teodord $
046: */
047: public class JRDesignDatasetRun extends JRBaseDatasetRun {
048: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
049:
050: private Map parametersMap;
051: private List parametersList;
052:
053: /**
054: * Creates an empty dataset instantiation.
055: */
056: public JRDesignDatasetRun() {
057: parametersMap = new HashMap();
058: parametersList = new ArrayList();
059: }
060:
061: /**
062: * Adds a parameter value.
063: *
064: * @param parameter the parameter value
065: * @throws JRException
066: * @see net.sf.jasperreports.engine.JRDatasetRun#getParameters()
067: */
068: public void addParameter(JRDatasetParameter parameter)
069: throws JRException {
070: if (parametersMap.containsKey(parameter.getName())) {
071: throw new JRException(
072: "Duplicate declaration of dataset parameter : "
073: + parameter.getName());
074: }
075:
076: parametersMap.put(parameter.getName(), parameter);
077: parametersList.add(parameter);
078: }
079:
080: /**
081: * Removes a parameter value.
082: *
083: * @param parameterName the parameter name
084: * @return the removed parameter value
085: */
086: public JRDatasetParameter removeParameter(String parameterName) {
087: JRDatasetParameter param = (JRDatasetParameter) parametersMap
088: .remove(parameterName);
089: if (param != null) {
090: parametersList.remove(param);
091: }
092:
093: return param;
094: }
095:
096: /**
097: * Removes a parameter value.
098: *
099: * @param parameter the parameter value
100: * @return the paramter value
101: */
102: public JRDatasetParameter removeParameter(
103: JRDatasetParameter parameter) {
104: JRDatasetParameter param = (JRDatasetParameter) parametersMap
105: .remove(parameter.getName());
106: if (param != null) {
107: parametersList.remove(parameter);
108: }
109:
110: return param;
111: }
112:
113: /**
114: * Sets the connection expression.
115: *
116: * @param connectionExpression the connection expression
117: * @see net.sf.jasperreports.engine.JRDatasetRun#getConnectionExpression()
118: */
119: public void setConnectionExpression(
120: JRExpression connectionExpression) {
121: this .connectionExpression = connectionExpression;
122: }
123:
124: /**
125: * Sets the sub dataset name.
126: *
127: * @param datasetName the sub dataset name
128: * @see net.sf.jasperreports.engine.JRDatasetRun#getDatasetName()
129: */
130: public void setDatasetName(String datasetName) {
131: this .datasetName = datasetName;
132: }
133:
134: /**
135: * Sets the data source expression.
136: *
137: * @param dataSourceExpression the data source expression
138: * @see net.sf.jasperreports.engine.JRDatasetRun#getDataSourceExpression()
139: */
140: public void setDataSourceExpression(
141: JRExpression dataSourceExpression) {
142: this .dataSourceExpression = dataSourceExpression;
143: }
144:
145: /**
146: * Sets the parameters map expression.
147: *
148: * @param parametersMapExpression the parameters map expression
149: * @see net.sf.jasperreports.engine.JRDatasetRun#getParametersMapExpression()
150: */
151: public void setParametersMapExpression(
152: JRExpression parametersMapExpression) {
153: this .parametersMapExpression = parametersMapExpression;
154: }
155:
156: public JRDatasetParameter[] getParameters() {
157: JRDatasetParameter[] params = new JRDatasetParameter[parametersList
158: .size()];
159: parametersList.toArray(params);
160: return params;
161: }
162:
163: }
|