| 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: ReportContextImpl.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 java.util.HashMap; |
| 35 |
|
| 36 |
import org.jfree.report.flow.ReportContext; |
| 37 |
import org.jfree.report.flow.ReportStructureRoot; |
| 38 |
import org.jfree.report.flow.layoutprocessor.LayoutControllerFactory; |
| 39 |
import org.jfree.report.i18n.ResourceBundleFactory; |
| 40 |
import org.pentaho.reporting.libraries.formula.FormulaContext; |
| 41 |
|
| 42 |
/** |
| 43 |
* Creation-Date: 20.11.2006, 12:19:34 |
| 44 |
* |
| 45 |
* @author Thomas Morgner |
| 46 |
*/ |
| 47 |
public class ReportContextImpl implements ReportContext |
| 48 |
{ |
| 49 |
private static class DataCarrier |
| 50 |
{ |
| 51 |
private boolean locked; |
| 52 |
private Object value; |
| 53 |
|
| 54 |
public DataCarrier(final Object value) |
| 55 |
{ |
| 56 |
this.value = value; |
| 57 |
} |
| 58 |
|
| 59 |
public void lock () |
| 60 |
{ |
| 61 |
locked = true; |
| 62 |
} |
| 63 |
|
| 64 |
public boolean isLocked() |
| 65 |
{ |
| 66 |
return locked; |
| 67 |
} |
| 68 |
|
| 69 |
public Object getValue() |
| 70 |
{ |
| 71 |
return value; |
| 72 |
} |
| 73 |
|
| 74 |
public void setValue(final Object value) |
| 75 |
{ |
| 76 |
this.value = value; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
private HashMap backend; |
| 81 |
private String exportDescriptor; |
| 82 |
private FormulaContext formulaContext; |
| 83 |
private LayoutControllerFactory layoutControllerFactory; |
| 84 |
private ResourceBundleFactory resourceBundleFactory; |
| 85 |
private ReportStructureRoot reportStructureRoot; |
| 86 |
|
| 87 |
public ReportContextImpl() |
| 88 |
{ |
| 89 |
backend = new HashMap(); |
| 90 |
} |
| 91 |
|
| 92 |
public void setReportStructureRoot(final ReportStructureRoot reportStructureRoot) |
| 93 |
{ |
| 94 |
this.reportStructureRoot = reportStructureRoot; |
| 95 |
} |
| 96 |
|
| 97 |
public ReportStructureRoot getReportStructureRoot() |
| 98 |
{ |
| 99 |
return reportStructureRoot; |
| 100 |
} |
| 101 |
|
| 102 |
public String getExportDescriptor() |
| 103 |
{ |
| 104 |
return exportDescriptor; |
| 105 |
} |
| 106 |
|
| 107 |
public void setExportDescriptor(final String exportDescriptor) |
| 108 |
{ |
| 109 |
this.exportDescriptor = exportDescriptor; |
| 110 |
} |
| 111 |
|
| 112 |
public FormulaContext getFormulaContext() |
| 113 |
{ |
| 114 |
return formulaContext; |
| 115 |
} |
| 116 |
|
| 117 |
public void setFormulaContext(final FormulaContext formulaContext) |
| 118 |
{ |
| 119 |
this.formulaContext = formulaContext; |
| 120 |
} |
| 121 |
|
| 122 |
public LayoutControllerFactory getLayoutControllerFactory() |
| 123 |
{ |
| 124 |
return layoutControllerFactory; |
| 125 |
} |
| 126 |
|
| 127 |
public void setLayoutControllerFactory(final LayoutControllerFactory layoutControllerFactory) |
| 128 |
{ |
| 129 |
this.layoutControllerFactory = layoutControllerFactory; |
| 130 |
} |
| 131 |
|
| 132 |
public void setAttribute(Object key, Object value) |
| 133 |
{ |
| 134 |
final DataCarrier dc = (DataCarrier) backend.get(key); |
| 135 |
if (dc == null) |
| 136 |
{ |
| 137 |
if (value == null) |
| 138 |
{ |
| 139 |
return; |
| 140 |
} |
| 141 |
|
| 142 |
final DataCarrier ndc = new DataCarrier(value); |
| 143 |
backend.put (key, ndc); |
| 144 |
return; |
| 145 |
} |
| 146 |
|
| 147 |
if (dc.isLocked()) |
| 148 |
{ |
| 149 |
throw new IllegalStateException("Context-Entry is locked."); |
| 150 |
} |
| 151 |
dc.setValue (value); |
| 152 |
} |
| 153 |
|
| 154 |
public void setSystemAttribute(Object key, Object value) |
| 155 |
{ |
| 156 |
final DataCarrier dc = (DataCarrier) backend.get(key); |
| 157 |
if (dc == null) |
| 158 |
{ |
| 159 |
if (value == null) |
| 160 |
{ |
| 161 |
return; |
| 162 |
} |
| 163 |
|
| 164 |
final DataCarrier ndc = new DataCarrier(value); |
| 165 |
ndc.lock(); |
| 166 |
backend.put (key, ndc); |
| 167 |
return; |
| 168 |
} |
| 169 |
|
| 170 |
if (dc.isLocked()) |
| 171 |
{ |
| 172 |
throw new IllegalStateException("Context-Entry is locked."); |
| 173 |
} |
| 174 |
dc.setValue (value); |
| 175 |
} |
| 176 |
|
| 177 |
public Object getAttribute(Object key) |
| 178 |
{ |
| 179 |
final DataCarrier dc = (DataCarrier) backend.get(key); |
| 180 |
if (dc == null) |
| 181 |
{ |
| 182 |
return null; |
| 183 |
} |
| 184 |
return dc.getValue(); |
| 185 |
} |
| 186 |
|
| 187 |
public boolean isSystemAttribute(Object key) |
| 188 |
{ |
| 189 |
final DataCarrier dc = (DataCarrier) backend.get(key); |
| 190 |
if (dc == null) |
| 191 |
{ |
| 192 |
return false; |
| 193 |
} |
| 194 |
return dc.isLocked(); |
| 195 |
} |
| 196 |
|
| 197 |
public ResourceBundleFactory getResourceBundleFactory() |
| 198 |
{ |
| 199 |
return resourceBundleFactory; |
| 200 |
} |
| 201 |
|
| 202 |
public void setResourceBundleFactory(final ResourceBundleFactory resourceBundleFactory) |
| 203 |
{ |
| 204 |
this.resourceBundleFactory = resourceBundleFactory; |
| 205 |
} |
| 206 |
} |