01: package com.calipso.reportgenerator.reportcalculator;
02:
03: import com.calipso.reportgenerator.common.ReportMetricSpec;
04: import com.calipso.reportgenerator.common.InfoException;
05: import com.calipso.reportgenerator.common.LanguageTraslator;
06: import com.calipso.reportgenerator.reportcalculator.expression.Expression;
07:
08: import java.util.Map;
09: import java.util.Collection;
10: import java.util.Iterator;
11: import java.util.HashMap;
12: import java.io.Serializable;
13:
14: /**
15: *
16: * User: jbassino
17: * Date: 19-may-2005
18: * Time: 13:45:50
19: * Calipso Software
20: */
21: public class CalculatedStrategy extends MetricCalculationStrategy
22: implements Serializable {
23: ReportMetricSpec metricSpec;
24:
25: public CalculatedStrategy(ReportMetricSpec metricSpec) {
26: this .metricSpec = metricSpec;
27: }
28:
29: public Object operate(Object[] node, int index, Object measure,
30: Object[] aRow) {
31: Map map = metricSpec.getVariableIndexes();
32: Map context = fillContext(node, map);
33: return SharedFloat.newFrom(metricSpec.getValue(context));
34: }
35:
36: public String getSQLFunction() throws InfoException {
37: throw new InfoException(LanguageTraslator.traslate("581")
38: + "Calculated");
39: }
40:
41: private Map fillContext(Object[] node, Map map) {
42: Map context = new HashMap();
43: Iterator iterator = map.entrySet().iterator();
44: while (iterator.hasNext()) {
45: Map.Entry entry = (Map.Entry) iterator.next();
46: context.put(entry.getKey(),
47: ((SharedFloat) node[((Integer) entry.getValue())
48: .intValue()]).getValue());
49: }
50: return context;
51: }
52:
53: }
|