KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > xml > JRChartDatasetFactory


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2005 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 185, Berry Street, Suite 6200
25  * San Francisco CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.xml;
29
30 import java.util.Set;
31
32 import net.sf.jasperreports.engine.JRVariable;
33 import net.sf.jasperreports.engine.design.JRDesignChartDataset;
34 import net.sf.jasperreports.engine.design.JRDesignGroup;
35
36 import org.xml.sax.Attributes;
37
38
39 /**
40  * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
41  * @version $Id: JRChartDatasetFactory.java,v 1.3 2005/07/01 16:15:38 flavius_sana Exp $
42  */

43 public class JRChartDatasetFactory extends JRBaseFactory
44 {
45
46     private static final String ATTRIBUTE_resetType = "resetType";
47     private static final String ATTRIBUTE_resetGroup = "resetGroup";
48     private static final String ATTRIBUTE_incrementType = "incrementType";
49     private static final String ATTRIBUTE_incrementGroup = "incrementGroup";
50
51
52     /**
53      *
54      */

55     public Object createObject(Attributes atts)
56     {
57         JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
58         Set groupBoundDatasets = xmlLoader.getGroupBoundDatasets();
59
60         JRDesignChartDataset dataset = (JRDesignChartDataset) digester.peek();
61         
62         Byte resetType = (Byte)JRXmlConstants.getResetTypeMap().get(atts.getValue(ATTRIBUTE_resetType));
63         if (resetType != null)
64         {
65             dataset.setResetType(resetType.byteValue());
66         }
67         if (dataset.getResetType() == JRVariable.RESET_TYPE_GROUP)
68         {
69             groupBoundDatasets.add(dataset);
70
71             String groupName = atts.getValue(ATTRIBUTE_resetGroup);
72             if (groupName != null)
73             {
74                 JRDesignGroup group = new JRDesignGroup();
75                 group.setName(groupName);
76                 dataset.setResetGroup(group);
77             }
78         }
79
80         Byte incrementType = (Byte)JRXmlConstants.getResetTypeMap().get(atts.getValue(ATTRIBUTE_incrementType));
81         if (incrementType != null)
82         {
83             dataset.setIncrementType(incrementType.byteValue());
84         }
85         if (dataset.getIncrementType() == JRVariable.RESET_TYPE_GROUP)
86         {
87             groupBoundDatasets.add(dataset);
88
89             String groupName = atts.getValue(ATTRIBUTE_incrementGroup);
90             if (groupName != null)
91             {
92                 JRDesignGroup group = new JRDesignGroup();
93                 group.setName(groupName);
94                 dataset.setIncrementGroup(group);
95             }
96         }
97
98         return dataset;
99     }
100
101 }
102
Popular Tags