01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
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: * FunctionStorage.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.states;
30:
31: import java.util.HashMap;
32:
33: import org.jfree.report.ReportProcessingException;
34: import org.jfree.report.function.Expression;
35:
36: /**
37: * Creation-Date: Dec 15, 2006, 2:24:30 PM
38: *
39: * @author Thomas Morgner
40: */
41: public class FunctionStorage {
42: private HashMap storage;
43:
44: public FunctionStorage() {
45: storage = new HashMap();
46: }
47:
48: /**
49: * Stores expressions at the end of a run.
50: *
51: * @param key
52: * @param expressions
53: */
54: public void store(final FunctionStorageKey key,
55: final Expression[] expressions, final int length)
56: throws ReportProcessingException {
57: // Log.debug ("Store: " + key);
58: try {
59: final Expression[] copy = new Expression[length];
60: for (int i = 0; i < length; i++) {
61: copy[i] = (Expression) expressions[i].clone();
62: }
63: storage.put(key, copy);
64: } catch (CloneNotSupportedException e) {
65: throw new ReportProcessingException(
66: "Storing expressions failed.");
67: }
68: }
69:
70: public Expression[] restore(final FunctionStorageKey key)
71: throws ReportProcessingException {
72: try {
73: final Expression[] expressions = (Expression[]) storage
74: .get(key);
75: if (expressions == null) {
76: // Log.debug ("Failed to Restore: " + key);
77: return null;
78: }
79:
80: // Log.debug ("Success Restore: " + key);
81: final Expression[] copy = (Expression[]) expressions
82: .clone();
83: for (int i = 0; i < expressions.length; i++) {
84: copy[i] = (Expression) expressions[i].clone();
85: }
86: return copy;
87: } catch (CloneNotSupportedException e) {
88: throw new ReportProcessingException(
89: "Restoring expressions failed.");
90: }
91: }
92: }
|