001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/fun/IsNullFunDef.java#2 $
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-2006 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.AbstractBooleanCalc;
016    import mondrian.mdx.ResolvedFunCall;
017    import mondrian.olap.Evaluator;
018    import mondrian.olap.FunDef;
019    import mondrian.olap.Member;
020    import mondrian.olap.Literal;
021    
022    /**
023     * Definition of the <code>IS NULL</code> MDX function.
024     *
025     * @author medstat
026     * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/IsNullFunDef.java#2 $
027     * @since Aug 21, 2006
028     */
029    class IsNullFunDef extends FunDefBase {
030        /**
031         * Resolves calls to the <code>IS NULL</code> postfix operator.
032         */
033        static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver(
034                "IS NULL",
035                "<Expression> IS NULL",
036                "Returns whether an object is null",
037                new String[]{"Qbm", "Qbl", "Qbh", "Qbd"},
038                IsNullFunDef.class);
039    
040        public IsNullFunDef(FunDef dummyFunDef) {
041            super(dummyFunDef);
042        }
043    
044        public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
045            assert call.getArgCount() == 1;
046            final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
047            return new AbstractBooleanCalc(call, new Calc[]{memberCalc}) {
048                public boolean evaluateBoolean(Evaluator evaluator) {
049                    Member member = memberCalc.evaluateMember(evaluator);
050                    return member.isNull();
051                }
052            };
053        }
054    }
055    
056    // End IsNullFunDef.java