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.fill;
029:
030: import net.sf.jasperreports.engine.JRRuntimeException;
031: import net.sf.jasperreports.engine.JRSubreportReturnValue;
032: import net.sf.jasperreports.engine.JRVariable;
033: import net.sf.jasperreports.engine.util.JRClassLoader;
034:
035: /**
036: * Implementation of {@link net.sf.jasperreports.engine.JRSubreportReturnValue JRSubreportReturnValue}
037: * used by the filler.
038: *
039: * @author Lucian Chirita (lucianc@users.sourceforge.net)
040: * @version $Id: JRFillSubreportReturnValue.java 1280 2006-06-07 12:21:28Z teodord $
041: */
042: public class JRFillSubreportReturnValue implements
043: JRSubreportReturnValue {
044: protected final JRSubreportReturnValue parent;
045:
046: protected JRIncrementer incrementer = null;
047:
048: protected final JRBaseFiller filler;
049:
050: protected JRFillSubreportReturnValue(
051: JRSubreportReturnValue returnValue,
052: JRFillObjectFactory factory, JRBaseFiller filler) {
053: factory.put(returnValue, this );
054:
055: parent = returnValue;
056:
057: this .filler = filler;
058: }
059:
060: public String getSubreportVariable() {
061: return parent.getSubreportVariable();
062: }
063:
064: public String getToVariable() {
065: return parent.getToVariable();
066: }
067:
068: public String getIncrementerFactoryClassName() {
069: return parent.getIncrementerFactoryClassName();
070: }
071:
072: public byte getCalculation() {
073: return parent.getCalculation();
074: }
075:
076: /**
077: * Gets the incrementer to be used for this copied value.
078: */
079: public JRIncrementer getIncrementer() {
080: if (incrementer == null) {
081: String incrementerFactoryClassName = getIncrementerFactoryClassName();
082:
083: JRIncrementerFactory incrementerFactory;
084: if (incrementerFactoryClassName == null) {
085: JRVariable toVariable = filler
086: .getVariable(getToVariable());
087: incrementerFactory = JRDefaultIncrementerFactory
088: .getFactory(toVariable.getValueClass());
089: } else {
090: try {
091: Class incrementerFactoryClass = JRClassLoader
092: .loadClassForName(incrementerFactoryClassName);
093: incrementerFactory = JRIncrementerFactoryCache
094: .getInstance(incrementerFactoryClass);
095: } catch (ClassNotFoundException e) {
096: throw new JRRuntimeException("Increment class "
097: + incrementerFactoryClassName
098: + " not found.", e);
099: }
100: }
101:
102: incrementer = incrementerFactory
103: .getIncrementer(getCalculation());
104: }
105:
106: return incrementer;
107: }
108: }
|