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.xml;
029:
030: import net.sf.jasperreports.engine.design.JRDesignGroup;
031: import net.sf.jasperreports.engine.design.JRDesignVariable;
032:
033: import org.xml.sax.Attributes;
034:
035: /**
036: * @author Teodor Danciu (teodord@users.sourceforge.net)
037: * @version $Id: JRVariableFactory.java 1581 2007-02-12 14:19:02Z shertage $
038: */
039: public class JRVariableFactory extends JRBaseFactory {
040:
041: /**
042: *
043: */
044: public Object createObject(Attributes atts) {
045: JRDesignVariable variable = new JRDesignVariable();
046:
047: variable.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));
048:
049: if (atts.getValue(JRXmlConstants.ATTRIBUTE_class) != null) {
050: variable.setValueClassName(atts
051: .getValue(JRXmlConstants.ATTRIBUTE_class));
052: }
053:
054: Byte resetType = (Byte) JRXmlConstants.getResetTypeMap().get(
055: atts.getValue(JRXmlConstants.ATTRIBUTE_resetType));
056: if (resetType != null) {
057: variable.setResetType(resetType.byteValue());
058: }
059:
060: String groupName = atts
061: .getValue(JRXmlConstants.ATTRIBUTE_resetGroup);
062: if (groupName != null) {
063: JRDesignGroup group = new JRDesignGroup();
064: group.setName(groupName);
065: variable.setResetGroup(group);
066: }
067:
068: Byte incrementType = (Byte) JRXmlConstants
069: .getResetTypeMap()
070: .get(
071: atts
072: .getValue(JRXmlConstants.ATTRIBUTE_incrementType));
073: if (incrementType != null) {
074: variable.setIncrementType(incrementType.byteValue());
075: }
076:
077: groupName = atts
078: .getValue(JRXmlConstants.ATTRIBUTE_incrementGroup);
079: if (groupName != null) {
080: JRDesignGroup group = new JRDesignGroup();
081: group.setName(groupName);
082: variable.setIncrementGroup(group);
083: }
084:
085: Byte calculation = (Byte) JRXmlConstants
086: .getCalculationMap()
087: .get(
088: atts
089: .getValue(JRXmlConstants.ATTRIBUTE_calculation));
090: if (calculation != null) {
091: variable.setCalculation(calculation.byteValue());
092: }
093:
094: if (atts
095: .getValue(JRXmlConstants.ATTRIBUTE_incrementerFactoryClass) != null) {
096: variable
097: .setIncrementerFactoryClassName(atts
098: .getValue(JRXmlConstants.ATTRIBUTE_incrementerFactoryClass));
099: }
100:
101: return variable;
102: }
103:
104: }
|