KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > navi > AbstractClickableMember


1 /*
2  * Copyright (c) 1971-2003 TONBELLER AG, Bensheim.
3  * All rights reserved.
4  */

5 package com.tonbeller.jpivot.table.navi;
6
7 import org.apache.log4j.Logger;
8
9 import com.tonbeller.jpivot.olap.model.Dimension;
10 import com.tonbeller.jpivot.olap.model.Expression;
11 import com.tonbeller.jpivot.olap.model.Hierarchy;
12 import com.tonbeller.jpivot.olap.model.Level;
13 import com.tonbeller.jpivot.olap.model.Member;
14 import com.tonbeller.jpivot.olap.model.OlapModel;
15 import com.tonbeller.jpivot.olap.navi.ExpressionParser;
16 import com.tonbeller.jpivot.olap.navi.ExpressionParser.InvalidSyntaxException;
17 import com.tonbeller.jpivot.table.ClickableMember;
18 import com.tonbeller.jpivot.table.TableComponent;
19 import com.tonbeller.wcf.controller.RequestContext;
20
21 public abstract class AbstractClickableMember implements ClickableMember {
22   private static final Logger logger = Logger.getLogger(AbstractClickableMember.class);
23   
24   boolean suppressAllMember = true;
25   boolean suppressCalcMember = true;
26   boolean suppressMeasures = true;
27
28   /**
29    * parsed version of uniqueName
30    */

31   private Expression expression;
32
33   /**
34    * needed to format the urlPattern
35    */

36   protected ExpressionParser parser;
37
38   /**
39    * unique name of the member, level, hierarchy or dimension which shall
40    * be clickable.
41    */

42   private String JavaDoc uniqueName;
43
44   protected AbstractClickableMember(String JavaDoc uniqueName) {
45     this.uniqueName = uniqueName;
46   }
47
48   protected boolean match(Member member) {
49     if (suppressCalcMember && member.isCalculated())
50       return false;
51     if (suppressAllMember && member.isAll())
52       return false;
53     if (suppressMeasures && member.getLevel().getHierarchy().getDimension().isMeasure())
54       return false;
55     
56     // wenn kein Name angegeben wurde, dann akzeptieren wir alle Member
57
if (empty(uniqueName))
58       return true;
59     
60     if (parser == null || expression == null)
61       return false;
62     if (expression instanceof Level)
63       return expression.equals(member.getLevel());
64     if (expression instanceof Hierarchy)
65       return expression.equals(member.getLevel().getHierarchy());
66     if (expression instanceof Dimension)
67       return expression.equals(member.getLevel().getHierarchy().getDimension());
68     throw new IllegalArgumentException JavaDoc("unknown type: " + uniqueName);
69   }
70
71   private boolean empty(String JavaDoc s) {
72     return s == null || s.length() == 0;
73   }
74
75   public void startRendering(RequestContext context, TableComponent table) {
76     expression = null;
77     parser = null;
78     OlapModel model = table.getOlapModel();
79     
80     // wenn kein uniqueName angegeben ist, müssen wir auch nichts parsen
81
if (empty(uniqueName))
82       return;
83     
84     parser = (ExpressionParser) model.getExtension(ExpressionParser.ID);
85     if (parser != null) {
86       try {
87         // we do not use parser.parse() here because it searches for member names too. This
88
// makes a lot(!) of SQL queries - so we restrict ourselves to level, hierarchy, dimension.
89
expression = parser.lookupLevel(uniqueName);
90         if (expression == null)
91           expression = parser.lookupHierarchy(uniqueName);
92         if (expression == null)
93           expression = parser.lookupDimension(uniqueName);
94       } catch (InvalidSyntaxException e) {
95         // we do not throw an exception here. If the user
96
// has entered an invalid value, it will be ignored
97
logger.warn(null, e);
98       }
99     }
100   }
101
102   public void stopRendering() {
103     parser = null;
104     expression = null;
105   }
106
107   protected boolean isSuppressAllMember() {
108     return suppressAllMember;
109   }
110
111   protected void setSuppressAllMember(boolean suppressAllMember) {
112     this.suppressAllMember = suppressAllMember;
113   }
114
115   protected boolean isSuppressCalcMember() {
116     return suppressCalcMember;
117   }
118
119   protected void setSuppressCalcMember(boolean suppressCalcMember) {
120     this.suppressCalcMember = suppressCalcMember;
121   }
122
123   protected boolean isSuppressMeasures() {
124     return suppressMeasures;
125   }
126
127   protected void setSuppressMeasures(boolean suppressMeasures) {
128     this.suppressMeasures = suppressMeasures;
129   }
130
131 }
132
Popular Tags