~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/base/JRBaseDatasetRun.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:51:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220175116-apwo6unuaedvgzo3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JasperReports - Free Java Reporting Library.
 
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 
4
 * http://www.jaspersoft.com
 
5
 *
 
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 
7
 * the following license terms apply:
 
8
 *
 
9
 * This program is part of JasperReports.
 
10
 *
 
11
 * JasperReports is free software: you can redistribute it and/or modify
 
12
 * it under the terms of the GNU Lesser General Public License as published by
 
13
 * the Free Software Foundation, either version 3 of the License, or
 
14
 * (at your option) any later version.
 
15
 *
 
16
 * JasperReports is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
 
23
 */
 
24
package net.sf.jasperreports.engine.base;
 
25
 
 
26
import java.io.Serializable;
 
27
 
 
28
import net.sf.jasperreports.engine.JRConstants;
 
29
import net.sf.jasperreports.engine.JRDatasetParameter;
 
30
import net.sf.jasperreports.engine.JRDatasetRun;
 
31
import net.sf.jasperreports.engine.JRExpression;
 
32
import net.sf.jasperreports.engine.JRRuntimeException;
 
33
 
 
34
/**
 
35
 * Base implementation of the {@link net.sf.jasperreports.engine.JRDatasetRun JRDatasetRun} interface.
 
36
 * 
 
37
 * @author Lucian Chirita (lucianc@users.sourceforge.net)
 
38
 * @version $Id: JRBaseDatasetRun.java 3033 2009-08-27 11:46:22Z teodord $
 
39
 */
 
40
public class JRBaseDatasetRun implements JRDatasetRun, Serializable
 
41
{
 
42
        private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
 
43
 
 
44
        protected String datasetName;
 
45
        protected JRExpression parametersMapExpression;
 
46
        protected JRDatasetParameter[] parameters;
 
47
        protected JRExpression connectionExpression;
 
48
        protected JRExpression dataSourceExpression;
 
49
        
 
50
        
 
51
        /**
 
52
         * Creates an empty object.
 
53
         */
 
54
        protected JRBaseDatasetRun()
 
55
        {
 
56
        }
 
57
 
 
58
        
 
59
        /**
 
60
         * Creates a copy of a dataset instantiation.
 
61
         * 
 
62
         * @param datasetRun the dataset instantiation
 
63
         * @param factory the base object factory
 
64
         */
 
65
        protected JRBaseDatasetRun(JRDatasetRun datasetRun, JRBaseObjectFactory factory)
 
66
        {
 
67
                factory.put(datasetRun, this);
 
68
                
 
69
                datasetName = datasetRun.getDatasetName();
 
70
                parametersMapExpression = factory.getExpression(datasetRun.getParametersMapExpression());
 
71
                connectionExpression = factory.getExpression(datasetRun.getConnectionExpression());
 
72
                dataSourceExpression = factory.getExpression(datasetRun.getDataSourceExpression());
 
73
                
 
74
                JRDatasetParameter[] datasetParams = datasetRun.getParameters();
 
75
                if (datasetParams != null && datasetParams.length > 0)
 
76
                {
 
77
                        parameters = new JRBaseDatasetParameter[datasetParams.length];
 
78
                        for (int i = 0; i < parameters.length; i++)
 
79
                        {
 
80
                                parameters[i] = factory.getDatasetParameter(datasetParams[i]);
 
81
                        }
 
82
                }
 
83
        }
 
84
 
 
85
        public String getDatasetName()
 
86
        {
 
87
                return datasetName;
 
88
        }
 
89
 
 
90
        public JRExpression getParametersMapExpression()
 
91
        {
 
92
                return parametersMapExpression;
 
93
        }
 
94
 
 
95
        public JRDatasetParameter[] getParameters()
 
96
        {
 
97
                return parameters;
 
98
        }
 
99
 
 
100
        public JRExpression getConnectionExpression()
 
101
        {
 
102
                return connectionExpression;
 
103
        }
 
104
 
 
105
        public JRExpression getDataSourceExpression()
 
106
        {
 
107
                return dataSourceExpression;
 
108
        }
 
109
 
 
110
        /**
 
111
         * 
 
112
         */
 
113
        public Object clone() 
 
114
        {
 
115
                JRBaseDatasetRun clone = null;
 
116
                
 
117
                try
 
118
                {
 
119
                        clone = (JRBaseDatasetRun)super.clone();
 
120
                }
 
121
                catch (CloneNotSupportedException e)
 
122
                {
 
123
                        throw new JRRuntimeException(e);
 
124
                }
 
125
 
 
126
                if (parametersMapExpression != null)
 
127
                {
 
128
                        clone.parametersMapExpression = (JRExpression)parametersMapExpression.clone();
 
129
                }
 
130
                if (connectionExpression != null)
 
131
                {
 
132
                        clone.connectionExpression = (JRExpression)connectionExpression.clone();
 
133
                }
 
134
                if (dataSourceExpression != null)
 
135
                {
 
136
                        clone.dataSourceExpression = (JRExpression)dataSourceExpression.clone();
 
137
                }
 
138
 
 
139
                if (parameters != null)
 
140
                {
 
141
                        clone.parameters = new JRDatasetParameter[parameters.length];
 
142
                        for(int i = 0; i < parameters.length; i++)
 
143
                        {
 
144
                                clone.parameters[i] = (JRDatasetParameter)parameters[i].clone();
 
145
                        }
 
146
                }
 
147
 
 
148
                return clone;
 
149
        }
 
150
}