1 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 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 | Popular Tags |