001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/fun/MemberHierarchyFunDef.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.MemberCalc;
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.Member;
021    
022    /**
023     * Definition of the <code>&lt;Member&gt;.Hierarchy</code> MDX builtin function.
024     *
025     * @author jhyde
026     * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/MemberHierarchyFunDef.java#3 $
027     * @since Mar 23, 2006
028     */
029    public class MemberHierarchyFunDef extends FunDefBase {
030        static final MemberHierarchyFunDef instance = new MemberHierarchyFunDef();
031    
032        private MemberHierarchyFunDef() {
033            super("Hierarchy", "Returns a member's hierarchy.", "phm");
034        }
035    
036        public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
037            final MemberCalc memberCalc =
038                    compiler.compileMember(call.getArg(0));
039            return new CalcImpl(call, memberCalc);
040        }
041    
042        public static class CalcImpl extends AbstractHierarchyCalc {
043            private final MemberCalc memberCalc;
044    
045            public CalcImpl(Exp exp, MemberCalc memberCalc) {
046                super(exp, new Calc[] {memberCalc});
047                this.memberCalc = memberCalc;
048            }
049    
050            public Hierarchy evaluateHierarchy(Evaluator evaluator) {
051                Member member = memberCalc.evaluateMember(evaluator);
052                return member.getHierarchy();
053            }
054        }
055    }
056    
057    // End MemberHierarchyFunDef.java