KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import net.sf.jasperreports.engine.JRConstants;
36 import net.sf.jasperreports.engine.JRDatasetParameter;
37 import net.sf.jasperreports.engine.JRException;
38 import net.sf.jasperreports.engine.JRExpression;
39 import net.sf.jasperreports.engine.base.JRBaseDatasetRun;
40
41 /**
42  * Implementation of {@link net.sf.jasperreports.engine.JRDatasetRun JRDatasetRun} to be used for report desing.
43  *
44  * @author Lucian Chirita (lucianc@users.sourceforge.net)
45  * @version $Id: JRDesignDatasetRun.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
46  */

47 public class JRDesignDatasetRun extends JRBaseDatasetRun
48 {
49     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
50
51     private Map JavaDoc parametersMap;
52     private List JavaDoc parametersList;
53     
54     
55     /**
56      * Creates an empty dataset instantiation.
57      */

58     public JRDesignDatasetRun()
59     {
60         parametersMap = new HashMap JavaDoc();
61         parametersList = new ArrayList JavaDoc();
62     }
63     
64     
65     /**
66      * Adds a parameter value.
67      *
68      * @param parameter the parameter value
69      * @throws JRException
70      * @see net.sf.jasperreports.engine.JRDatasetRun#getParameters()
71      */

72     public void addParameter(JRDatasetParameter parameter) throws JRException
73     {
74         if (parametersMap.containsKey(parameter.getName()))
75         {
76             throw new JRException("Duplicate declaration of dataset parameter : " + parameter.getName());
77         }
78         
79         parametersMap.put(parameter.getName(), parameter);
80         parametersList.add(parameter);
81     }
82     
83     
84     /**
85      * Removes a parameter value.
86      *
87      * @param parameterName the parameter name
88      * @return the removed parameter value
89      */

90     public JRDatasetParameter removeParameter(String JavaDoc parameterName)
91     {
92         JRDatasetParameter param = (JRDatasetParameter) parametersMap.remove(parameterName);
93         if (param != null)
94         {
95             parametersList.remove(param);
96         }
97         
98         return param;
99     }
100     
101     
102     /**
103      * Removes a parameter value.
104      *
105      * @param parameter the parameter value
106      * @return the paramter value
107      */

108     public JRDatasetParameter removeParameter(JRDatasetParameter parameter)
109     {
110         JRDatasetParameter param = (JRDatasetParameter) parametersMap.remove(parameter.getName());
111         if (param != null)
112         {
113             parametersList.remove(parameter);
114         }
115         
116         return param;
117     }
118
119     
120     /**
121      * Sets the connection expression.
122      *
123      * @param connectionExpression the connection expression
124      * @see net.sf.jasperreports.engine.JRDatasetRun#getConnectionExpression()
125      */

126     public void setConnectionExpression(JRExpression connectionExpression)
127     {
128         this.connectionExpression = connectionExpression;
129     }
130
131     
132     /**
133      * Sets the sub dataset name.
134      *
135      * @param datasetName the sub dataset name
136      * @see net.sf.jasperreports.engine.JRDatasetRun#getDatasetName()
137      */

138     public void setDatasetName(String JavaDoc datasetName)
139     {
140         this.datasetName = datasetName;
141     }
142
143     
144     /**
145      * Sets the data source expression.
146      *
147      * @param dataSourceExpression the data source expression
148      * @see net.sf.jasperreports.engine.JRDatasetRun#getDataSourceExpression()
149      */

150     public void setDataSourceExpression(JRExpression dataSourceExpression)
151     {
152         this.dataSourceExpression = dataSourceExpression;
153     }
154
155     
156     /**
157      * Sets the parameters map expression.
158      *
159      * @param parametersMapExpression the parameters map expression
160      * @see net.sf.jasperreports.engine.JRDatasetRun#getParametersMapExpression()
161      */

162     public void setParametersMapExpression(JRExpression parametersMapExpression)
163     {
164         this.parametersMapExpression = parametersMapExpression;
165     }
166
167     public JRDatasetParameter[] getParameters()
168     {
169         JRDatasetParameter[] params = new JRDatasetParameter[parametersList.size()];
170         parametersList.toArray(params);
171         return params;
172     }
173
174 }
175
Popular Tags