001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/fun/IsEmptyFunDef.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.olap.FunDef;
013    import mondrian.olap.Evaluator;
014    import mondrian.olap.Util;
015    import mondrian.calc.Calc;
016    import mondrian.calc.ExpCompiler;
017    import mondrian.calc.impl.AbstractBooleanCalc;
018    import mondrian.mdx.ResolvedFunCall;
019    
020    /**
021     * Definition of the <code>IsEmpty</code> MDX function.
022     *
023     * @author jhyde
024     * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/IsEmptyFunDef.java#2 $
025     * @since Mar 23, 2006
026     */
027    class IsEmptyFunDef extends FunDefBase {
028        static final ReflectiveMultiResolver FunctionResolver = new ReflectiveMultiResolver(
029                "IsEmpty",
030                "IsEmpty(<Value Expression>)",
031                "Determines if an expression evaluates to the empty cell value.",
032                new String[] {"fbS", "fbn"},
033                IsEmptyFunDef.class);
034    
035        static final ReflectiveMultiResolver PostfixResolver = new ReflectiveMultiResolver(
036                "IS EMPTY",
037                "<Value Expression> IS EMPTY",
038                "Determines if an expression evaluates to the empty cell value.",
039                new String[] {"Qbm", "Qbt"},
040                IsEmptyFunDef.class);
041    
042        public IsEmptyFunDef(FunDef dummyFunDef) {
043            super(dummyFunDef);
044        }
045    
046        public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
047            final Calc calc = compiler.compileScalar(call.getArg(0), true);
048            return new AbstractBooleanCalc(call, new Calc[] {calc}) {
049                public boolean evaluateBoolean(Evaluator evaluator) {
050                    Object o = calc.evaluate(evaluator);
051                    return o == null;
052                }
053            };
054        }
055    }
056    
057    // End IsEmptyFunDef.java