KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > DimensionCurrentMemberFunDef


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/DimensionCurrentMemberFunDef.java#1 $
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) 2006-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.olap.fun;
11
12 import mondrian.calc.Calc;
13 import mondrian.calc.ExpCompiler;
14 import mondrian.calc.DimensionCalc;
15 import mondrian.calc.impl.AbstractMemberCalc;
16 import mondrian.mdx.ResolvedFunCall;
17 import mondrian.olap.Exp;
18 import mondrian.olap.Member;
19 import mondrian.olap.Evaluator;
20 import mondrian.olap.Dimension;
21
22 /**
23  * Definition of the <code>&lt;Dimension&gt;.CurrentMember</code> MDX builtin function.
24  *
25  * @author jhyde
26  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/DimensionCurrentMemberFunDef.java#1 $
27  * @since Mar 23, 2006
28  */

29 public class DimensionCurrentMemberFunDef extends FunDefBase {
30     static final DimensionCurrentMemberFunDef instance =
31             new DimensionCurrentMemberFunDef();
32
33     private DimensionCurrentMemberFunDef() {
34         super("CurrentMember", "<Dimension>.CurrentMember",
35                 "Returns the current member along a dimension during an iteration.",
36                 "pmd");
37     }
38
39     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
40         final DimensionCalc dimensionCalc =
41                 compiler.compileDimension(call.getArg(0));
42         return new CalcImpl(call, dimensionCalc);
43     }
44
45     public static class CalcImpl extends AbstractMemberCalc {
46         private final DimensionCalc dimensionCalc;
47
48         public CalcImpl(Exp exp, DimensionCalc dimensionCalc) {
49             super(exp, new Calc[] {dimensionCalc});
50             this.dimensionCalc = dimensionCalc;
51         }
52
53         protected String JavaDoc getName() {
54             return "CurrentMember";
55         }
56
57         public Member evaluateMember(Evaluator evaluator) {
58             Dimension dimension =
59                     dimensionCalc.evaluateDimension(evaluator);
60             return evaluator.getContext(dimension);
61         }
62
63         public boolean dependsOn(Dimension dimension) {
64             return dimensionCalc.getType().usesDimension(dimension, true) ;
65         }
66     }
67 }
68
69 // End DimensionCurrentMemberFunDef.java
70
Popular Tags