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