01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * 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;
16: import java.util.HashMap;
17: import java.util.Map;
18: import javax.swing.table.TableModel;
19: import org.jfree.report.DataRow;
20: import org.jfree.report.ReportDataFactoryException;
21: import org.jfree.report.modules.misc.datafactory.StaticDataFactory;
22:
23: /**
24: * This needs the latest CVS version of JFreeReport (0.8.7-5-cvs)...
25: *
26: * @author Thomas Morgner
27: */
28: public class PentahoDataFactory extends StaticDataFactory {
29: private ClassLoader classLoader;
30:
31: public PentahoDataFactory(final ClassLoader classLoader) {
32: this .classLoader = classLoader;
33: }
34:
35: public ClassLoader getClassLoader() {
36: return classLoader;
37: }
38:
39: public TableModel queryData(final String string,
40: final DataRow dataRow) throws ReportDataFactoryException {
41: final TableModel tableModel = super .queryData(string, dataRow);
42:
43: try {
44: final Class cls = tableModel.getClass();
45: final Map map = new HashMap();
46: for (int i = 0; i < dataRow.getColumnCount(); i++) {
47: map.put(dataRow.getColumnName(i), dataRow.get(i));
48: }
49: final Object[] args = { map };
50: final Class[] argt = { Map.class };
51: final Method theMethod = cls.getMethod(
52: "setParameters", argt); //$NON-NLS-1$
53: if (theMethod != null) {
54: theMethod.invoke(tableModel, args);
55: }
56: } catch (Exception ignored) {
57: // Method does not exist... ok, ignore it.
58: }
59:
60: return tableModel;
61: }
62: }
|