KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportcalculator > CalculatedStrategy


1 package com.calipso.reportgenerator.reportcalculator;
2
3 import com.calipso.reportgenerator.common.ReportMetricSpec;
4 import com.calipso.reportgenerator.common.InfoException;
5 import com.calipso.reportgenerator.common.LanguageTraslator;
6 import com.calipso.reportgenerator.reportcalculator.expression.Expression;
7
8 import java.util.Map JavaDoc;
9 import java.util.Collection JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.io.Serializable JavaDoc;
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 implements Serializable JavaDoc {
22   ReportMetricSpec metricSpec;
23
24   public CalculatedStrategy(ReportMetricSpec metricSpec){
25     this.metricSpec = metricSpec;
26   }
27
28   public Object JavaDoc operate(Object JavaDoc[] node, int index, Object JavaDoc measure, Object JavaDoc[] aRow) {
29     Map JavaDoc map = metricSpec.getVariableIndexes();
30     Map JavaDoc context = fillContext(node, map);
31     return SharedFloat.newFrom(metricSpec.getValue(context));
32   }
33
34   public String JavaDoc getSQLFunction() throws InfoException {
35     throw new InfoException(LanguageTraslator.traslate("581") + "Calculated");
36   }
37
38   private Map JavaDoc fillContext(Object JavaDoc[] node, Map JavaDoc map) {
39     Map JavaDoc context = new HashMap JavaDoc();
40     Iterator JavaDoc iterator = map.entrySet().iterator();
41     while (iterator.hasNext()) {
42       Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
43       context.put(entry.getKey(), ((SharedFloat)node[((Integer JavaDoc) entry.getValue()).intValue()]).getValue());
44     }
45     return context;
46   }
47
48 }
49
Popular Tags