001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2006-2007 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.olap.fun; 011 012import mondrian.calc.*; 013import mondrian.calc.impl.AbstractHierarchyCalc; 014import mondrian.mdx.ResolvedFunCall; 015import mondrian.olap.*; 016 017/** 018 * Definition of the <code><Level>.Hierarchy</code> MDX builtin function. 019 * 020 * @author jhyde 021 * @since Mar 23, 2006 022 */ 023public class LevelHierarchyFunDef extends FunDefBase { 024 static final LevelHierarchyFunDef instance = new LevelHierarchyFunDef(); 025 026 private LevelHierarchyFunDef() { 027 super("Hierarchy", "Returns a level's hierarchy.", "phl"); 028 } 029 030 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 031 final LevelCalc levelCalc = 032 compiler.compileLevel(call.getArg(0)); 033 return new CalcImpl(call, levelCalc); 034 } 035 036 public static class CalcImpl extends AbstractHierarchyCalc { 037 private final LevelCalc levelCalc; 038 039 public CalcImpl(Exp exp, LevelCalc levelCalc) { 040 super(exp, new Calc[] {levelCalc}); 041 this.levelCalc = levelCalc; 042 } 043 044 public Hierarchy evaluateHierarchy(Evaluator evaluator) { 045 Level level = levelCalc.evaluateLevel(evaluator); 046 return level.getHierarchy(); 047 } 048 } 049} 050 051// End LevelHierarchyFunDef.java