KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/LevelHierarchyFunDef.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.LevelCalc;
15 import mondrian.calc.impl.AbstractHierarchyCalc;
16 import mondrian.mdx.ResolvedFunCall;
17 import mondrian.olap.Exp;
18 import mondrian.olap.Hierarchy;
19 import mondrian.olap.Evaluator;
20 import mondrian.olap.Level;
21
22 /**
23  * Definition of the <code>&lt;Level&gt;.Hierarchy</code> MDX builtin function.
24  *
25  * @author jhyde
26  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/LevelHierarchyFunDef.java#1 $
27  * @since Mar 23, 2006
28  */

29 public class LevelHierarchyFunDef extends FunDefBase {
30     static final LevelHierarchyFunDef instance = new LevelHierarchyFunDef();
31
32     private LevelHierarchyFunDef() {
33         super("Hierarchy", "<Level>.Hierarchy",
34                 "Returns a level's hierarchy.", "phl");
35     }
36
37     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
38         final LevelCalc levelCalc =
39                 compiler.compileLevel(call.getArg(0));
40         return new CalcImpl(call, levelCalc);
41     }
42
43     public static class CalcImpl extends AbstractHierarchyCalc {
44         private final LevelCalc levelCalc;
45
46         public CalcImpl(Exp exp, LevelCalc levelCalc) {
47             super(exp, new Calc[] {levelCalc});
48             this.levelCalc = levelCalc;
49         }
50
51         public Hierarchy evaluateHierarchy(Evaluator evaluator) {
52             Level level = levelCalc.evaluateLevel(evaluator);
53             return level.getHierarchy();
54         }
55     }
56 }
57
58 // End LevelHierarchyFunDef.java
59
Popular Tags