Frames | No Frames |
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: AbstractExpression.java 3525 2007-10-16 11:43:48Z 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.expressions; 32: 33: import java.util.Locale; 34: 35: import org.jfree.report.DataRow; 36: import org.jfree.report.flow.ReportContext; 37: import org.jfree.report.flow.ReportStructureRoot; 38: import org.jfree.report.i18n.ResourceBundleFactory; 39: import org.jfree.report.structure.Element; 40: import org.jfree.util.Configuration; 41: 42: /** 43: * A baseclass for simple, non-positionally parametrized expressions. 44: * 45: * @author Thomas Morgner 46: */ 47: public abstract class AbstractExpression implements Expression 48: { 49: private transient ExpressionRuntime runtime; 50: private String name; 51: private boolean deepTraversing; 52: private boolean precompute; 53: private boolean preserve; 54: 55: protected AbstractExpression() 56: { 57: } 58: 59: /** 60: * Returns the name of the expression. An expression without a name cannot be 61: * referenced from outside the element. 62: * 63: * @return the function name. 64: */ 65: public String getName() 66: { 67: return name; 68: } 69: 70: /** 71: * Sets the name of the expression. 72: * 73: * @param name the name. 74: */ 75: public void setName(final String name) 76: { 77: this.name = name; 78: } 79: 80: /** 81: * Clones the expression, expression should be reinitialized after the 82: * cloning. <P> Expression maintain no state, cloning is done at the beginning 83: * of the report processing to disconnect the used expression from any other 84: * object space. 85: * 86: * @return A clone of this expression. 87: * @throws CloneNotSupportedException this should never happen. 88: */ 89: public Object clone() throws CloneNotSupportedException 90: { 91: return super.clone(); 92: } 93: 94: /** 95: * Return a new instance of this expression. The copy is initialized and uses 96: * the same parameters as the original, but does not share any objects. 97: * 98: * @return a copy of this function. 99: */ 100: public Expression getInstance() 101: { 102: try 103: { 104: final AbstractExpression abstractExpression = (AbstractExpression) clone(); 105: abstractExpression.runtime = null; 106: return abstractExpression; 107: } 108: catch (CloneNotSupportedException cne) 109: { 110: return null; 111: } 112: } 113: 114: /** 115: * Defines the DataRow used in this expression. The dataRow is set when the 116: * report processing starts and can be used to access the values of functions, 117: * expressions and the reports datasource. 118: * 119: * @param runtime the runtime information for the expression 120: */ 121: public void setRuntime(final ExpressionRuntime runtime) 122: { 123: this.runtime = runtime; 124: } 125: 126: public ExpressionRuntime getRuntime() 127: { 128: return runtime; 129: } 130: 131: /** 132: * Returns the current {@link DataRow}. 133: * 134: * @return the data row. 135: */ 136: protected DataRow getDataRow() 137: { 138: if (runtime == null) 139: { 140: return null; 141: } 142: return runtime.getDataRow(); 143: } 144: 145: protected ResourceBundleFactory getResourceBundleFactory() 146: { 147: if (runtime == null) 148: { 149: return null; 150: } 151: return runtime.getResourceBundleFactory(); 152: } 153: 154: protected Configuration getReportConfiguration() 155: { 156: if (runtime == null) 157: { 158: return null; 159: } 160: return runtime.getConfiguration(); 161: } 162: 163: protected Locale getParentLocale () 164: { 165: if (runtime == null) 166: { 167: return null; 168: } 169: 170: final Object declaringParent = runtime.getDeclaringParent(); 171: if (declaringParent instanceof Element) 172: { 173: final Element declaringElement = (Element) declaringParent; 174: return declaringElement.getLocale(); 175: } 176: 177: final ReportContext reportContext = runtime.getReportContext(); 178: final ReportStructureRoot reportStructureRoot = reportContext.getReportStructureRoot(); 179: return reportStructureRoot.getLocale(); 180: } 181: 182: public boolean isPrecompute() 183: { 184: return precompute; 185: } 186: 187: public void setPrecompute(final boolean precompute) 188: { 189: this.precompute = precompute; 190: } 191: 192: public boolean isDeepTraversing() 193: { 194: return deepTraversing; 195: } 196: 197: public void setDeepTraversing(final boolean deepTraversing) 198: { 199: this.deepTraversing = deepTraversing; 200: } 201: 202: public boolean isPreserve() 203: { 204: return preserve; 205: } 206: 207: public void setPreserve(final boolean preserve) 208: { 209: this.preserve = preserve; 210: } 211: }