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