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.JRExpression;
034: import net.sf.jasperreports.engine.JRGroup;
035: import net.sf.jasperreports.engine.JRRuntimeException;
036: import net.sf.jasperreports.engine.JRVariable;
037: import net.sf.jasperreports.engine.util.JRClassLoader;
038:
039: /**
040: * @author Teodor Danciu (teodord@users.sourceforge.net)
041: * @version $Id: JRBaseVariable.java 1712 2007-04-30 18:04:51Z teodord $
042: */
043: public class JRBaseVariable implements JRVariable, Serializable {
044:
045: /**
046: *
047: */
048: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
049:
050: /**
051: *
052: */
053: protected String name = null;
054: protected String valueClassName = java.lang.String.class.getName();
055: protected String valueClassRealName = null;
056: protected String incrementerFactoryClassName = null;
057: protected String incrementerFactoryClassRealName = null;
058: protected byte resetType = RESET_TYPE_REPORT;
059: protected byte incrementType = RESET_TYPE_NONE;
060: protected byte calculation = CALCULATION_NOTHING;
061: protected boolean isSystemDefined = false;
062:
063: protected transient Class valueClass = null;
064: protected transient Class incrementerFactoryClass = null;
065:
066: /**
067: *
068: */
069: protected JRExpression expression = null;
070: protected JRExpression initialValueExpression = null;
071: protected JRGroup resetGroup = null;
072: protected JRGroup incrementGroup = null;
073:
074: /**
075: *
076: */
077: protected JRBaseVariable() {
078: }
079:
080: /**
081: *
082: */
083: protected JRBaseVariable(JRVariable variable,
084: JRBaseObjectFactory factory) {
085: factory.put(variable, this );
086:
087: name = variable.getName();
088: valueClassName = variable.getValueClassName();
089: incrementerFactoryClassName = variable
090: .getIncrementerFactoryClassName();
091: resetType = variable.getResetType();
092: incrementType = variable.getIncrementType();
093: calculation = variable.getCalculation();
094: isSystemDefined = variable.isSystemDefined();
095:
096: expression = factory.getExpression(variable.getExpression());
097: initialValueExpression = factory.getExpression(variable
098: .getInitialValueExpression());
099:
100: resetGroup = factory.getGroup(variable.getResetGroup());
101: incrementGroup = factory.getGroup(variable.getIncrementGroup());
102: }
103:
104: /**
105: *
106: */
107: public String getName() {
108: return this .name;
109: }
110:
111: /**
112: *
113: */
114: public Class getValueClass() {
115: if (valueClass == null) {
116: String className = getValueClassRealName();
117: if (className != null) {
118: try {
119: valueClass = JRClassLoader
120: .loadClassForName(className);
121: } catch (ClassNotFoundException e) {
122: throw new JRRuntimeException(e);
123: }
124: }
125: }
126:
127: return valueClass;
128: }
129:
130: /**
131: *
132: */
133: public String getValueClassName() {
134: return valueClassName;
135: }
136:
137: /**
138: *
139: */
140: private String getValueClassRealName() {
141: if (valueClassRealName == null) {
142: valueClassRealName = JRClassLoader
143: .getClassRealName(valueClassName);
144: }
145:
146: return valueClassRealName;
147: }
148:
149: /**
150: *
151: */
152: public Class getIncrementerFactoryClass() {
153: if (incrementerFactoryClass == null) {
154: String className = getIncrementerFactoryClassRealName();
155: if (className != null) {
156: try {
157: incrementerFactoryClass = JRClassLoader
158: .loadClassForName(className);
159: } catch (ClassNotFoundException e) {
160: throw new JRRuntimeException(e);
161: }
162: }
163: }
164:
165: return incrementerFactoryClass;
166: }
167:
168: /**
169: *
170: */
171: public String getIncrementerFactoryClassName() {
172: return incrementerFactoryClassName;
173: }
174:
175: /**
176: *
177: */
178: private String getIncrementerFactoryClassRealName() {
179: if (incrementerFactoryClassRealName == null) {
180: incrementerFactoryClassRealName = JRClassLoader
181: .getClassRealName(incrementerFactoryClassName);
182: }
183:
184: return incrementerFactoryClassRealName;
185: }
186:
187: /**
188: *
189: */
190: public byte getResetType() {
191: return this .resetType;
192: }
193:
194: /**
195: *
196: */
197: public byte getIncrementType() {
198: return this .incrementType;
199: }
200:
201: /**
202: *
203: */
204: public byte getCalculation() {
205: return this .calculation;
206: }
207:
208: /**
209: *
210: */
211: public boolean isSystemDefined() {
212: return this .isSystemDefined;
213: }
214:
215: /**
216: *
217: */
218: public JRExpression getExpression() {
219: return this .expression;
220: }
221:
222: /**
223: *
224: */
225: public JRExpression getInitialValueExpression() {
226: return this .initialValueExpression;
227: }
228:
229: /**
230: *
231: */
232: public JRGroup getResetGroup() {
233: return this .resetGroup;
234: }
235:
236: /**
237: *
238: */
239: public JRGroup getIncrementGroup() {
240: return this.incrementGroup;
241: }
242:
243: }
|