001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/Validator.java#7 $
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) 2005-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;
011    
012    import mondrian.olap.fun.ParameterFunDef;
013    import mondrian.olap.type.Type;
014    import mondrian.mdx.ParameterExpr;
015    
016    /**
017     * Provides context necessary to resolve identifiers to objects, function
018     * calls to specific functions.
019     *
020     * <p>An expression calls {@link #validate} on each of its children,
021     * which in turn calls {@link Exp#accept}.
022     *
023     * @author jhyde
024     * @version $Id: //open/mondrian/src/main/mondrian/olap/Validator.java#7 $
025     */
026    public interface Validator {
027        /**
028         * Returns the {@link Query} which is being validated.
029         */
030        Query getQuery();
031    
032        /**
033         * Validates an expression, and returns the expression it resolves to.
034         *
035         * @param exp Expression to validate
036         * @param scalar Whether the context requires that the expression is
037         *   evaluated to a value, as opposed to a tuple
038         */
039        Exp validate(Exp exp, boolean scalar);
040    
041        /**
042         * Validates a usage of a parameter.
043         *
044         * <p>It must resolve to the same object (although sub-objects may change).
045         */
046        void validate(ParameterExpr parameterExpr);
047    
048        /**
049         * Validates a child member property.
050         *
051         * <p>It must resolve to the same object (although sub-objects may change).
052         */
053        void validate(MemberProperty memberProperty);
054    
055        /**
056         * Validates an axis.
057         *
058         * It must resolve to the same object (although sub-objects may change).
059         */
060        void validate(QueryAxis axis);
061    
062        /**
063         * Validates a formula.
064         *
065         * It must resolve to the same object (although sub-objects may change).
066         */
067        void validate(Formula formula);
068    
069        /**
070         * Returns whether the current context requires an expression.
071         */
072        boolean requiresExpression();
073    
074        /**
075         * Returns whether we can convert an argument to a parameter type.
076         *
077         * @param fromExp argument type
078         * @param to   parameter type
079         * @param conversionCount in/out count of number of conversions performed;
080         *             is incremented if the conversion is non-trivial (for
081         *             example, converting a member to a level).
082         */
083        boolean canConvert(Exp fromExp, int to, int[] conversionCount);
084    
085        /**
086         * Returns the table of function and operator definitions.
087         */
088        FunTable getFunTable();
089    
090        /**
091         * Creates or retrieves the parameter corresponding to a "Parameter" or
092         * "ParamRef" function call.
093         */
094        Parameter createOrLookupParam(
095            boolean definition,
096            String name,
097            Type type,
098            Exp defaultExp,
099            String description);
100    }
101    
102    // End Validator.java