KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > tags > ScalarOlapModelTag


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.tags;
14
15 import com.tonbeller.jpivot.olap.model.OlapModel;
16 import com.tonbeller.jpivot.olap.model.impl.ScalarOlapModel;
17 import com.tonbeller.wcf.controller.RequestContext;
18 import com.tonbeller.wcf.expr.ExprUtils;
19
20 /**
21  * jsp tag that defines a scalar query
22  */

23 public class ScalarOlapModelTag extends OlapModelTag {
24
25   String JavaDoc value;
26   String JavaDoc formattedValue;
27   String JavaDoc caption;
28   
29   protected OlapModel getOlapModel(RequestContext context) throws Exception JavaDoc {
30     ScalarOlapModel som = new ScalarOlapModel();
31     som.setValue(evalNum(context, value));
32     som.setFormattedValue(evalStr(context, formattedValue));
33     som.setCaption(caption);
34     return som;
35   }
36   
37   private String JavaDoc evalStr(RequestContext context, String JavaDoc el) {
38     Object JavaDoc obj = eval(context, el);
39     if (obj == null)
40       return null;
41     return String.valueOf(obj);
42   }
43
44   private Number JavaDoc evalNum(RequestContext context, String JavaDoc el) {
45     Object JavaDoc obj = eval(context, el);
46     if (obj instanceof Number JavaDoc)
47       return (Number JavaDoc)obj;
48     return new Double JavaDoc(String.valueOf(obj));
49   }
50
51   private Object JavaDoc eval(RequestContext context, String JavaDoc el) {
52     if (ExprUtils.isExpression(el))
53       return context.getModelReference(el);
54     return el;
55   }
56
57   public void setCaption(String JavaDoc caption) {
58     this.caption = caption;
59   }
60   public void setFormattedValue(String JavaDoc formattedValue) {
61     this.formattedValue = formattedValue;
62   }
63   public void setValue(String JavaDoc value) {
64     this.value = value;
65   }
66
67 }
Popular Tags