001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portlet.chart;
021:
022: import java.util.Map;
023:
024: import java.io.Serializable;
025: import java.sql.Connection;
026:
027: import org.jfree.data.JDBCXYDataset;
028: import org.jfree.data.XYDataset;
029: import org.jfree.data.XYSeries;
030: import org.jfree.data.XYSeriesCollection;
031: import org.jfree.chart.tooltips.XYToolTipGenerator;
032:
033: import com.nabhinc.core.Defaults;
034: import com.nabhinc.util.db.DBUtil;
035:
036: /**
037: *
038: *
039: * @author Padmanabh Dabke
040: * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
041: */
042: public class XYDatasetProducer extends XYSeriesCollection implements
043: XYToolTipGenerator, Serializable {
044:
045: private static final long serialVersionUID = 7293298012690102115L;
046:
047: private Map _parameters = null;
048: private String dataSourceName = null;
049: private String queryString = null;
050: private final static String[] defaultSeriesNames = { "population" };
051: private final static int SERIES_LENGTH = 1;
052: private final static int NUM_OF_ITEMS = 10;
053: double[] defaultXVals = { 1900, 1910, 1920, 1930, 1940, 1950, 1960,
054: 1970, 1980, 1990 };
055: double[] defaultYVals = { 100000, 200000, 300000, 400000, 550000,
056: 400000, 700000, 800000, 900000, 800000 };
057:
058: public XYDatasetProducer() {
059: XYSeries series = new XYSeries("Population");
060: for (int j = 0; j < defaultXVals.length; j++) {
061: series.add(defaultXVals[j], defaultYVals[j]);
062: }
063: addSeries(series);
064:
065: }
066:
067: public synchronized Object produceDataset(Map params) {
068: if (dataSourceName == null) {
069: dataSourceName = Defaults.getDataSourceName();
070: }
071:
072: if (queryString != null) {
073: JDBCXYDataset jdbdXYDataSet = null;
074: try {
075: Connection con = DBUtil.getConnection(dataSourceName);
076:
077: jdbdXYDataSet = new JDBCXYDataset(con);
078: jdbdXYDataSet.executeQuery(queryString);
079: } catch (Exception ex) {
080: System.out.println("XYDataSetProducer.produceDataset"
081: + ex);
082: }
083:
084: return jdbdXYDataSet;
085: }
086:
087: return this ;
088: }
089:
090: /**
091: *
092: */
093: public String generateLink(Object data, int series, int item) {
094: return "";
095: }
096:
097: public String generateToolTip(XYDataset data, int series, int item) {
098: return "";
099: }
100:
101: public void setParameters(Map parameters) {
102: _parameters = parameters;
103: }
104:
105: public void setDataSourceName(String dsName) {
106: dataSourceName = dsName;
107: }
108:
109: public void setQueryString(String qs) {
110: queryString = qs;
111: }
112: }
|