KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > helper > PentahoDataFactory


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 package org.pentaho.plugin.jfreereport.helper;
14
15 import java.lang.reflect.Method JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import javax.swing.table.TableModel JavaDoc;
20
21 import org.jfree.report.DataRow;
22 import org.jfree.report.ReportInitialisationException;
23 import org.jfree.report.modules.misc.datafactory.StaticDataFactory;
24
25 /**
26  * This needs the latest CVS version of JFreeReport (0.8.7-5-cvs)...
27  *
28  * @author Thomas Morgner
29  */

30 public class PentahoDataFactory extends StaticDataFactory
31 {
32   private ClassLoader JavaDoc classLoader;
33
34   public PentahoDataFactory(final ClassLoader JavaDoc classLoader)
35   {
36     this.classLoader = classLoader;
37   }
38
39   public ClassLoader JavaDoc getClassLoader()
40   {
41     return classLoader;
42   }
43
44   public TableModel JavaDoc queryData(String JavaDoc string, DataRow dataRow)
45           throws ReportInitialisationException
46   {
47     final TableModel JavaDoc tableModel = super.queryData(string, dataRow);
48
49     try
50     {
51       Class JavaDoc cls = tableModel.getClass();
52       Map JavaDoc map = new HashMap JavaDoc();
53       for (int i = 0; i < dataRow.getColumnCount(); i++)
54       {
55         map.put (dataRow.getColumnName(i), dataRow.get(i));
56       }
57       Object JavaDoc[] args = {map};
58       Class JavaDoc[] argt = {Map JavaDoc.class};
59       Method JavaDoc theMethod = cls.getMethod("setParameters", argt); //$NON-NLS-1$
60
if (theMethod != null)
61       {
62         theMethod.invoke(tableModel, args);
63       }
64     }
65     catch (Exception JavaDoc ignored)
66     {
67       // Method does not exist... ok, ignore it.
68
}
69
70     return tableModel;
71   }
72 }
73
Popular Tags