KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > laures > cewolf > example > PageViewCountData


1 /* ================================================================
2  * Cewolf : Chart enabling Web Objects Framework
3  * ================================================================
4  *
5  * Project Info: http://cewolf.sourceforge.net
6  * Project Lead: Guido Laures (guido@laures.de);
7  *
8  * (C) Copyright 2002, by Guido Laures
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either 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, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23 package de.laures.cewolf.example;
24
25 import java.io.Serializable JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.jfree.data.category.CategoryDataset;
32 import org.jfree.data.category.DefaultCategoryDataset;
33
34 import de.laures.cewolf.DatasetProduceException;
35 import de.laures.cewolf.DatasetProducer;
36 import de.laures.cewolf.links.CategoryItemLinkGenerator;
37 import de.laures.cewolf.tooltips.CategoryToolTipGenerator;
38
39 /**
40  * An example data producer.
41  * @author Guido Laures
42  */

43 public class PageViewCountData implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable JavaDoc {
44
45     private static final Log log = LogFactory.getLog(PageViewCountData.class);
46
47     // These values would normally not be hard coded but produced by
48
// some kind of data source like a database or a file
49
private final String JavaDoc[] categories = {"mon", "tue", "wen", "thu", "fri", "sat", "sun"};
50     private final String JavaDoc[] seriesNames = {"cewolfset.jsp", "tutorial.jsp", "testpage.jsp", "performancetest.jsp"};
51
52     /**
53      * Produces some random data.
54      */

55     public Object JavaDoc produceDataset(Map JavaDoc params) throws DatasetProduceException {
56         log.debug("producing data.");
57         DefaultCategoryDataset dataset = new DefaultCategoryDataset(){
58             /**
59              * @see java.lang.Object#finalize()
60              */

61             protected void finalize() throws Throwable JavaDoc {
62                 super.finalize();
63                 log.debug(this +" finalized.");
64             }
65         };
66         for (int series = 0; series < seriesNames.length; series ++) {
67             int lastY = (int)(Math.random() * 1000 + 1000);
68             for (int i = 0; i < categories.length; i++) {
69                 final int y = lastY + (int)(Math.random() * 200 - 100);
70                 lastY = y;
71                 dataset.addValue(y, seriesNames[series], categories[i]);
72             }
73         }
74         return dataset;
75     }
76
77     /**
78      * This producer's data is invalidated after 5 seconds. By this method the
79      * producer can influence Cewolf's caching behaviour the way it wants to.
80      */

81     public boolean hasExpired(Map JavaDoc params, Date JavaDoc since) {
82         log.debug(getClass().getName() + "hasExpired()");
83         return (System.currentTimeMillis() - since.getTime()) > 5000;
84     }
85
86     /**
87      * Returns a unique ID for this DatasetProducer
88      */

89     public String JavaDoc getProducerId() {
90         return "PageViewCountData DatasetProducer";
91     }
92
93     /**
94      * Returns a link target for a special data item.
95      */

96     public String JavaDoc generateLink(Object JavaDoc data, int series, Object JavaDoc category) {
97         return seriesNames[series];
98     }
99     
100     /**
101      * @see java.lang.Object#finalize()
102      */

103     protected void finalize() throws Throwable JavaDoc {
104         super.finalize();
105         log.debug(this + " finalized.");
106     }
107
108     /**
109      * @see org.jfree.chart.tooltips.CategoryToolTipGenerator#generateToolTip(CategoryDataset, int, int)
110      */

111     public String JavaDoc generateToolTip(CategoryDataset arg0, int series, int arg2) {
112         return seriesNames[series];
113     }
114
115 }
116
Popular Tags