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.Serializable;
031:
032: import net.sf.jasperreports.engine.JRConstants;
033: import net.sf.jasperreports.engine.JRDataset;
034: import net.sf.jasperreports.engine.JRExpression;
035: import net.sf.jasperreports.engine.JRField;
036: import net.sf.jasperreports.engine.JRGroup;
037: import net.sf.jasperreports.engine.JRParameter;
038: import net.sf.jasperreports.engine.JRPropertiesMap;
039: import net.sf.jasperreports.engine.JRQuery;
040: import net.sf.jasperreports.engine.JRSortField;
041: import net.sf.jasperreports.engine.JRVariable;
042:
043: /**
044: * The base implementation of {@link net.sf.jasperreports.engine.JRDataset JRDataset}.
045: *
046: * @author Lucian Chirita (lucianc@users.sourceforge.net)
047: * @version $Id: JRBaseDataset.java 1669 2007-03-26 14:50:07Z lucianc $
048: */
049: public class JRBaseDataset implements JRDataset, Serializable {
050: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
051:
052: protected final boolean isMain;
053: protected String name = null;
054: protected String scriptletClass = null;
055: protected JRParameter[] parameters = null;
056: protected JRQuery query = null;
057: protected JRField[] fields = null;
058: protected JRSortField[] sortFields = null;
059: protected JRVariable[] variables = null;
060: protected JRGroup[] groups = null;
061: protected String resourceBundle = null;
062: protected byte whenResourceMissingType = WHEN_RESOURCE_MISSING_TYPE_NULL;
063: protected JRPropertiesMap propertiesMap;
064: protected JRExpression filterExpression;
065:
066: protected JRBaseDataset(boolean isMain) {
067: this .isMain = isMain;
068:
069: propertiesMap = new JRPropertiesMap();
070: }
071:
072: protected JRBaseDataset(JRDataset dataset,
073: JRBaseObjectFactory factory) {
074: factory.put(dataset, this );
075:
076: name = dataset.getName();
077: scriptletClass = dataset.getScriptletClass();
078: resourceBundle = dataset.getResourceBundle();
079: whenResourceMissingType = dataset.getWhenResourceMissingType();
080:
081: /* */
082: this .propertiesMap = dataset.getPropertiesMap()
083: .cloneProperties();
084:
085: query = factory.getQuery(dataset.getQuery());
086:
087: isMain = dataset.isMainDataset();
088:
089: /* */
090: JRParameter[] jrParameters = dataset.getParameters();
091: if (jrParameters != null && jrParameters.length > 0) {
092: parameters = new JRParameter[jrParameters.length];
093: for (int i = 0; i < parameters.length; i++) {
094: parameters[i] = factory.getParameter(jrParameters[i]);
095: }
096: }
097:
098: /* */
099: JRField[] jrFields = dataset.getFields();
100: if (jrFields != null && jrFields.length > 0) {
101: fields = new JRField[jrFields.length];
102: for (int i = 0; i < fields.length; i++) {
103: fields[i] = factory.getField(jrFields[i]);
104: }
105: }
106:
107: /* */
108: JRSortField[] jrSortFields = dataset.getSortFields();
109: if (jrSortFields != null && jrSortFields.length > 0) {
110: sortFields = new JRSortField[jrSortFields.length];
111: for (int i = 0; i < sortFields.length; i++) {
112: sortFields[i] = factory.getSortField(jrSortFields[i]);
113: }
114: }
115:
116: /* */
117: JRVariable[] jrVariables = dataset.getVariables();
118: if (jrVariables != null && jrVariables.length > 0) {
119: variables = new JRVariable[jrVariables.length];
120: for (int i = 0; i < variables.length; i++) {
121: variables[i] = factory.getVariable(jrVariables[i]);
122: }
123: }
124:
125: /* */
126: JRGroup[] jrGroups = dataset.getGroups();
127: if (jrGroups != null && jrGroups.length > 0) {
128: groups = new JRGroup[jrGroups.length];
129: for (int i = 0; i < groups.length; i++) {
130: groups[i] = factory.getGroup(jrGroups[i]);
131: }
132: }
133:
134: filterExpression = factory.getExpression(dataset
135: .getFilterExpression());
136: }
137:
138: /**
139: *
140: */
141: public String getName() {
142: return name;
143: }
144:
145: /**
146: *
147: */
148: public String getScriptletClass() {
149: return scriptletClass;
150: }
151:
152: /**
153: *
154: */
155: public JRQuery getQuery() {
156: return query;
157: }
158:
159: /**
160: *
161: */
162: public JRParameter[] getParameters() {
163: return parameters;
164: }
165:
166: /**
167: *
168: */
169: public JRField[] getFields() {
170: return fields;
171: }
172:
173: /**
174: *
175: */
176: public JRSortField[] getSortFields() {
177: return sortFields;
178: }
179:
180: /**
181: *
182: */
183: public JRVariable[] getVariables() {
184: return variables;
185: }
186:
187: /**
188: *
189: */
190: public JRGroup[] getGroups() {
191: return groups;
192: }
193:
194: public boolean isMainDataset() {
195: return isMain;
196: }
197:
198: public String getResourceBundle() {
199: return resourceBundle;
200: }
201:
202: public byte getWhenResourceMissingType() {
203: return whenResourceMissingType;
204: }
205:
206: public void setWhenResourceMissingType(byte whenResourceMissingType) {
207: this .whenResourceMissingType = whenResourceMissingType;
208: }
209:
210: public JRPropertiesMap getPropertiesMap() {
211: return propertiesMap;
212: }
213:
214: public JRExpression getFilterExpression() {
215: return filterExpression;
216: }
217: }
|