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) 2002-2005 Julian Hyde
008// Copyright (C) 2005-2009 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.olap;
012
013import mondrian.olap.fun.FunInfo;
014import mondrian.olap.fun.Resolver;
015
016import java.util.List;
017
018/**
019 * List of all MDX functions.
020 *
021 * <p>A function table can resolve a function call, using a particular
022 * {@link Syntax} and set of arguments, to a
023 * function definition ({@link FunDef}).</p>
024 *
025 * @author jhyde, 3 March, 2002
026 */
027public interface FunTable {
028    /**
029     * Returns whether a string is a reserved word.
030     */
031    boolean isReserved(String s);
032
033    /**
034     * Returns whether a string is a property-style (postfix)
035     * operator. This is used during parsing to disambiguate
036     * functions from unquoted member names.
037     */
038    boolean isProperty(String s);
039
040    /**
041     * Returns a list of words ({@link String}) which may not be used as
042     * identifiers.
043     */
044    List<String> getReservedWords();
045
046    /**
047     * Returns a list of {@link mondrian.olap.fun.Resolver} objects.
048     */
049    List<Resolver> getResolvers();
050
051    /**
052     * Returns a list of resolvers for an operator with a given name and syntax.
053     * Never returns null; if there are no resolvers, returns the empty list.
054     *
055     * @param name Operator name
056     * @param syntax Operator syntax
057     * @return List of resolvers for the operator
058     */
059    List<Resolver> getResolvers(
060        String name,
061        Syntax syntax);
062
063    /**
064     * Returns a list of {@link mondrian.olap.fun.FunInfo} objects.
065     */
066    List<FunInfo> getFunInfoList();
067
068    /**
069     * This method is called from the constructor, to define the set of
070     * functions and reserved words recognized.
071     *
072     * <p>The implementing class calls {@link Builder} methods to declare
073     * functions and reserved words.
074     *
075     * <p>Derived class can override this method to add more functions. It must
076     * call the base method.
077     *
078     * @param builder Builder
079     */
080    void defineFunctions(Builder builder);
081
082    /**
083     * Builder that assists with the construction of a function table by
084     * providing callbacks to define functions.
085     *
086     * <p>An implementation of {@link mondrian.olap.FunTable} must register all
087     * of its functions and operators by making callbacks during its
088     * {@link mondrian.olap.FunTable#defineFunctions(mondrian.olap.FunTable.Builder)}
089     * method.
090     */
091    public interface Builder {
092        /**
093         * Defines a function.
094         *
095         * @param funDef Function definition
096         */
097        void define(FunDef funDef);
098
099        /**
100         * Defines a resolver that will resolve overloaded function calls to
101         * function definitions.
102         *
103         * @param resolver Function call resolver
104         */
105        void define(Resolver resolver);
106
107        /**
108         * Defines a function info that is not matchd by an actual function.
109         * The function will be implemented via implicit conversions, but
110         * we still want the function info to appear in the metadata.
111         *
112         * @param funInfo Function info
113         */
114        void define(FunInfo funInfo);
115
116        /**
117         * Defines a reserved word.
118         *
119         * @param keyword Reserved word
120         *
121         * @see mondrian.olap.FunTable#isReserved
122         */
123        void defineReserved(String keyword);
124    }
125}
126
127// End FunTable.java