| 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: RunningExpressionSlot.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 |
|
| 32 |
package org.jfree.report.data; |
| 33 |
|
| 34 |
import org.jfree.report.DataRow; |
| 35 |
import org.jfree.report.DataSourceException; |
| 36 |
import org.jfree.report.ReportData; |
| 37 |
import org.jfree.report.expressions.Expression; |
| 38 |
import org.jfree.report.expressions.ExpressionRuntime; |
| 39 |
import org.jfree.report.expressions.Function; |
| 40 |
import org.jfree.report.flow.ReportContext; |
| 41 |
import org.jfree.report.i18n.ResourceBundleFactory; |
| 42 |
import org.pentaho.reporting.libraries.base.config.Configuration; |
| 43 |
|
| 44 |
/** |
| 45 |
* Creation-Date: 25.11.2006, 15:18:58 |
| 46 |
* |
| 47 |
* @author Thomas Morgner |
| 48 |
*/ |
| 49 |
public class RunningExpressionSlot |
| 50 |
implements ExpressionSlot, ExpressionRuntime |
| 51 |
{ |
| 52 |
private StaticExpressionRuntimeData staticRuntimeData; |
| 53 |
private Expression expression; |
| 54 |
private Object value; |
| 55 |
private String name; |
| 56 |
private boolean queried; |
| 57 |
private DataRow dataRow; |
| 58 |
|
| 59 |
public RunningExpressionSlot(final Expression expression, |
| 60 |
final StaticExpressionRuntimeData runtimeData, |
| 61 |
final PrecomputeNode precomputeNode) |
| 62 |
{ |
| 63 |
this.staticRuntimeData = runtimeData; |
| 64 |
this.expression = expression; |
| 65 |
this.name = expression.getName(); |
| 66 |
this.expression.setRuntime(this); |
| 67 |
this.expression.setRuntime(null); |
| 68 |
} |
| 69 |
|
| 70 |
public Expression getExpression() |
| 71 |
{ |
| 72 |
return expression; |
| 73 |
} |
| 74 |
|
| 75 |
public Object getValue() throws DataSourceException |
| 76 |
{ |
| 77 |
if (queried == false) |
| 78 |
{ |
| 79 |
//noinspection SynchronizeOnNonFinalField |
| 80 |
synchronized (expression) |
| 81 |
{ |
| 82 |
expression.setRuntime(this); |
| 83 |
value = expression.computeValue(); |
| 84 |
expression.setRuntime(null); |
| 85 |
} |
| 86 |
queried = true; |
| 87 |
} |
| 88 |
return value; |
| 89 |
} |
| 90 |
|
| 91 |
public String getName() |
| 92 |
{ |
| 93 |
return name; |
| 94 |
} |
| 95 |
|
| 96 |
public DataRow getDataRow() |
| 97 |
{ |
| 98 |
return dataRow; |
| 99 |
} |
| 100 |
|
| 101 |
public Object clone() throws CloneNotSupportedException |
| 102 |
{ |
| 103 |
return super.clone(); |
| 104 |
} |
| 105 |
|
| 106 |
public void updateDataRow(final DataRow dataRow) |
| 107 |
{ |
| 108 |
this.dataRow = dataRow; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns the report data used in this section. If subreports are used, this |
| 113 |
* does not reflect the complete report data. |
| 114 |
* <p/> |
| 115 |
* All access to the report data must be properly synchronized. Failure to do |
| 116 |
* so may result in funny results. Do not assume that the report data will be |
| 117 |
* initialized on the current cursor positon. |
| 118 |
* |
| 119 |
* @return |
| 120 |
*/ |
| 121 |
public ReportData getData() |
| 122 |
{ |
| 123 |
return staticRuntimeData.getData(); |
| 124 |
} |
| 125 |
|
| 126 |
public Object getDeclaringParent() |
| 127 |
{ |
| 128 |
return staticRuntimeData.getDeclaringParent(); |
| 129 |
} |
| 130 |
|
| 131 |
public Configuration getConfiguration() |
| 132 |
{ |
| 133 |
return staticRuntimeData.getConfiguration(); |
| 134 |
} |
| 135 |
|
| 136 |
public ResourceBundleFactory getResourceBundleFactory() |
| 137 |
{ |
| 138 |
return staticRuntimeData.getResourceBundleFactory(); |
| 139 |
} |
| 140 |
|
| 141 |
public void advance() throws DataSourceException |
| 142 |
{ |
| 143 |
if (expression instanceof Function) |
| 144 |
{ |
| 145 |
Function f = (Function) expression; |
| 146 |
expression.setRuntime(this); |
| 147 |
expression = f.advance(); |
| 148 |
f.setRuntime(null); |
| 149 |
expression.setRuntime(null); |
| 150 |
} |
| 151 |
value = null; |
| 152 |
queried = false; |
| 153 |
} |
| 154 |
|
| 155 |
public boolean isDeepTraversing() |
| 156 |
{ |
| 157 |
return expression.isDeepTraversing(); |
| 158 |
} |
| 159 |
|
| 160 |
public int getCurrentRow() |
| 161 |
{ |
| 162 |
return staticRuntimeData.getCurrentRow(); |
| 163 |
} |
| 164 |
|
| 165 |
public ReportContext getReportContext() |
| 166 |
{ |
| 167 |
return staticRuntimeData.getReportContext(); |
| 168 |
} |
| 169 |
|
| 170 |
public boolean isPreserve() |
| 171 |
{ |
| 172 |
return expression.isPreserve(); |
| 173 |
} |
| 174 |
} |