KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > test > XmlaTester


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.test;
21
22 import com.tonbeller.jpivot.olap.model.OlapException;
23 import com.tonbeller.jpivot.xmla.XMLA_Model;
24 import org.apache.log4j.Logger;
25 import org.jfree.chart.ChartRenderingInfo;
26 import org.jfree.chart.ChartUtilities;
27 import org.jfree.chart.JFreeChart;
28 import org.jfree.chart.axis.CategoryAxis;
29 import org.jfree.chart.axis.NumberAxis;
30 import org.jfree.chart.axis.ValueAxis;
31 import org.jfree.chart.entity.StandardEntityCollection;
32 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
33 import org.jfree.chart.plot.CategoryPlot;
34 import org.jfree.chart.plot.PlotOrientation;
35 import org.jfree.chart.renderer.category.BarRenderer;
36 import org.jfree.data.category.DefaultCategoryDataset;
37 import org.openi.chart.AxisLabelGenerator;
38 import org.openi.xmla.DatasetAdapter;
39 import org.openi.xmla.XmlaConnector;
40 import org.xml.sax.SAXException JavaDoc;
41 import java.awt.Font JavaDoc;
42 import java.io.File JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.util.Locale JavaDoc;
45
46
47 public class XmlaTester {
48     private static Logger logger = Logger.getLogger(XmlaTester.class);
49
50     /**
51      * Constructor
52      * @param arg0
53      */

54     public XmlaTester() {
55         // super(arg0);
56
Util.setupLog4j();
57     }
58
59     public void query() throws IOException JavaDoc, OlapException, SAXException JavaDoc {
60         long start = System.currentTimeMillis();
61
62         /*
63            select {[Measures].[Unit Sales], [Measures].[Store Cost]} ON columns,
64            Filter([Product].[Brand Name].Members, ([Measures].[Unit Sales] > 100000.0)) ON rows
65            from [Sales] where [Time].[1997]
66          */

67
68         // first step
69
String JavaDoc url = "";
70         String JavaDoc catalog = "";
71         String JavaDoc apple = "";
72         XmlaConnector connector = new XmlaConnector();
73         XMLA_Model model = connector.query(url, catalog, apple);
74         logger.debug("query time: " + (System.currentTimeMillis() - start)
75             + "ms");
76
77         // soap requests happen on demand?
78

79         // convert xmla model into jfreechart dataset
80
DatasetAdapter adapter = new DatasetAdapter(Locale.getDefault());
81         logger.debug("building a category dataset");
82
83         DefaultCategoryDataset dataset = adapter.buildCategoryDataset(model);
84
85         //create chart
86
String JavaDoc chartTitle = "chartTitle";
87         Font JavaDoc titleFont = new Font JavaDoc("name", 1, 12);
88         // String horizAxisLabel = "horizAxisLabel";
89
// String vertAxisLabel = "vertAxisLabel";
90
logger.debug("building axis label");
91
92         AxisLabelGenerator axisLabel = new AxisLabelGenerator();
93         String JavaDoc horizAxisLabel = axisLabel.getHorizAxisLabel(model);
94         String JavaDoc vertAxisLabel = axisLabel.getVertAxisLabel(model);
95         boolean showLegend = true;
96         boolean showTooltips = true;
97         boolean drillThroughEnabled = false;
98
99         /*
100            JFreeChart chart = EnhancedChartFactory.createBarChart(chartTitle, titleFont,
101                    horizAxisLabel, vertAxisLabel,
102                    dataset,
103                    PlotOrientation.HORIZONTAL,
104                    showLegend, showTooltips,
105                    drillThroughEnabled, null);
106          */

107         CategoryAxis categoryAxis = new CategoryAxis(horizAxisLabel);
108         ValueAxis valueAxis = new NumberAxis(vertAxisLabel);
109         BarRenderer renderer = new BarRenderer();
110
111         if (showTooltips) {
112             renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
113         }
114
115         CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
116                 renderer);
117         plot.setOrientation(PlotOrientation.HORIZONTAL);
118
119         JFreeChart chart = new JFreeChart(chartTitle, titleFont, plot,
120                 showLegend);
121
122         // chart.setBackgroundPaint(new java.awt.Color(255, 255, 255));
123
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
124         String JavaDoc renderFile = "/home/plucas/results/"
125             + XmlaTester.class.getName();
126         ChartUtilities.saveChartAsPNG(new File JavaDoc(renderFile + ".png"), chart,
127             640, 480, info);
128         ChartUtilities.saveChartAsJPEG(new File JavaDoc(renderFile + ".jpg"), chart,
129             640, 480);
130
131         /*
132            Axis[] axes = result.getAxes();
133            List positions = axes[0].getPositions();
134            // unlike mondrian, the measures axis has 2 positions
135            positions = axes[1].getPositions();
136          */

137     }
138
139     public static void main(String JavaDoc[] args) {
140         try {
141             XmlaTester tester = new XmlaTester();
142             tester.query();
143         } catch (Exception JavaDoc e) {
144             e.printStackTrace();
145         }
146     }
147 } // EmptyResult
148
Popular Tags