KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > param > SetParamTagBase


1 package com.tonbeller.wcf.param;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
5
6 import org.apache.log4j.Logger;
7
8 import com.tonbeller.wcf.expr.ExprUtils;
9
10 /**
11  * @author av
12  * @since 01.03.2005
13  */

14 public class SetParamTagBase extends TagSupport JavaDoc {
15   String JavaDoc displayName;
16   String JavaDoc displayValue;
17   String JavaDoc paramName;
18   String JavaDoc sqlValue;
19   String JavaDoc mdxValue;
20   String JavaDoc textValue;
21
22   private static final Logger logger = Logger.getLogger(SetParamTagBase.class);
23   
24   // the parameter in the pool before it was replaced by a new one
25
SessionParam oldParam;
26   SessionParam newParam;
27
28   public int doStartTag() throws JspException JavaDoc {
29     SessionParamPool pool = SessionParamPool.instance(pageContext);
30     // remember the old parameter
31
oldParam = pool.getParam(paramName);
32     
33     // create a new one, copies default values
34
try {
35       if (oldParam == null) {
36         newParam = new SessionParam();
37         newParam.setName(paramName);
38       }
39       else
40         newParam = (SessionParam) oldParam.clone();
41     } catch (CloneNotSupportedException JavaDoc e) {
42       logger.error(null, e);
43       throw new JspException JavaDoc(e);
44     }
45
46     // initialize + store
47
initialize(newParam);
48     pool.setParam(newParam);
49     return EVAL_BODY_INCLUDE;
50   }
51   
52   protected void initialize(SessionParam p) {
53     if (displayName != null)
54       p.setDisplayName(evalStr(displayName));
55     if (displayValue != null)
56       p.setDisplayValue(evalStr(displayValue));
57     if (paramName != null)
58       p.setName(evalStr(paramName));
59     if (sqlValue != null)
60       p.setSqlValue(evalObj(sqlValue));
61     if (mdxValue != null)
62       p.setMdxValue(evalStr(mdxValue));
63     if (textValue != null)
64       p.setMdxValue(evalStr(mdxValue));
65   }
66   
67   protected Object JavaDoc evalObj(String JavaDoc s) {
68     if (ExprUtils.isExpression(s))
69       return ExprUtils.getModelReference(pageContext, s);
70     return s;
71   }
72
73   protected String JavaDoc evalStr(String JavaDoc s) {
74     if (ExprUtils.isExpression(s))
75       return String.valueOf(ExprUtils.getModelReference(pageContext, s));
76     return s;
77   }
78
79   public void setDisplayName(String JavaDoc displayName) {
80     this.displayName = displayName;
81   }
82
83   public void setDisplayValue(String JavaDoc displayValue) {
84     this.displayValue = displayValue;
85   }
86
87   public void setMdxValue(String JavaDoc mdxValue) {
88     this.mdxValue = mdxValue;
89   }
90
91   public void setParamName(String JavaDoc paramName) {
92     this.paramName = paramName;
93   }
94
95   public void setSqlValue(String JavaDoc sqlExpr) {
96     this.sqlValue = sqlExpr;
97   }
98
99   public void setTextValue(String JavaDoc textValue) {
100     this.textValue = textValue;
101   }
102
103 }
104
Popular Tags