Debian Codegraph @

source/org/jfree/report/data/ImportedVariablesDataRow.java

raw
1 /**
2 * ========================================
3 * JFreeReport : a free Java report library
4 * ========================================
5 *
6 * Project Info: http://reporting.pentaho.org/
7 *
8 * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
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 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23 * in the United States and other countries.]
24 *
25 * ------------
26 * $Id: ImportedVariablesDataRow.java 10756 2009-12-02 15:58:24Z tmorgner $
27 * ------------
28 * (C) Copyright 2000-2005, by Object Refinery Limited.
29 * (C) Copyright 2005-2007, by Pentaho Corporation.
30 */
31 package org.jfree.report.data;
32
33 import org.jfree.report.DataRow;
34 import org.jfree.report.DataSourceException;
35 import org.jfree.report.flow.ParameterMapping;
36
37 /**
38 * Creation-Date: 06.03.2006, 18:15:06
39 *
40 * @author Thomas Morgner
41 */
42 public class ImportedVariablesDataRow extends StaticDataRow
43 {
44 private String[] outerNames;
45 private String[] innerNames;
46
47 public ImportedVariablesDataRow(final GlobalMasterRow innerRow)
48 throws DataSourceException
49 {
50 final DataRow globalView = innerRow.getGlobalView();
51 final int cols = globalView.getColumnCount();
52 this.outerNames = new String[cols];
53 this.innerNames = outerNames;
54 final Object[] values = new Object[outerNames.length];
55 for (int i = 0; i < outerNames.length; i++)
56 {
57 outerNames[i] = globalView.getColumnName(i);
58 values[i] = globalView.get(i);
59 }
60 setData(outerNames, values);
61 }
62
63 /**
64 * Maps the inner-row into the outer data row. The parameter mapping's name
65 * represents the *outer* name and the innernames.
66 *
67 * @param innerRow
68 * @param parameterMappings
69 * @throws DataSourceException
70 */
71 public ImportedVariablesDataRow(final GlobalMasterRow innerRow,
72 final ParameterMapping[] parameterMappings)
73 throws DataSourceException
74 {
75 this.outerNames = new String[parameterMappings.length];
76 this.innerNames = new String[parameterMappings.length];
77 final Object[] values = new Object[parameterMappings.length];
78 final DataRow globalView = innerRow.getGlobalView();
79 for (int i = 0; i < parameterMappings.length; i++)
80 {
81 final ParameterMapping mapping = parameterMappings[i];
82 String name = mapping.getAlias();
83 values[i] = globalView.get(name);
84 innerNames[i] = name;
85 outerNames[i] = mapping.getName();
86 }
87 setData(outerNames, values);
88 }
89
90 protected ImportedVariablesDataRow(final ImportedVariablesDataRow dataRow)
91 {
92 super(dataRow);
93 outerNames = dataRow.outerNames;
94 innerNames = dataRow.innerNames;
95 }
96
97 public ImportedVariablesDataRow advance (final GlobalMasterRow innerRow)
98 throws DataSourceException
99 {
100 final DataRow globalView = innerRow.getGlobalView();
101 final Object[] values = new Object[outerNames.length];
102 for (int i = 0; i < innerNames.length; i++)
103 {
104 String name = innerNames[i];
105 values[i] = globalView.get(name);
106 }
107 ImportedVariablesDataRow idr = new ImportedVariablesDataRow(this);
108 idr.setData(outerNames, values);
109 return idr;
110 }
111 }