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) 2008-2009 Pentaho and others
008// All Rights Reserved.
009*/
010package mondrian.olap.fun;
011
012import mondrian.olap.FunDef;
013import mondrian.olap.FunTable;
014
015import java.util.HashSet;
016import java.util.Set;
017
018/**
019 * Interface to build a customized function table, selecting functions from the
020 * set of supported functions in an instance of {@link BuiltinFunTable}.
021 *
022 * @author Rushan Chen
023 */
024public class CustomizedFunctionTable extends FunTableImpl {
025
026    Set<String> supportedBuiltinFunctions;
027    Set<FunDef> specialFunctions;
028
029    public CustomizedFunctionTable(Set<String> builtinFunctions) {
030        supportedBuiltinFunctions = builtinFunctions;
031        this.specialFunctions = new HashSet<FunDef>();
032    }
033
034    public CustomizedFunctionTable(
035        Set<String> builtinFunctions,
036        Set<FunDef> specialFunctions)
037    {
038        this.supportedBuiltinFunctions = builtinFunctions;
039        this.specialFunctions = specialFunctions;
040    }
041
042    public void defineFunctions(Builder builder) {
043        final FunTable builtinFunTable = BuiltinFunTable.instance();
044
045        // Includes all the keywords form builtin function table
046        for (String reservedWord : builtinFunTable.getReservedWords()) {
047            builder.defineReserved(reservedWord);
048        }
049
050        // Add supported builtin functions
051        for (Resolver resolver : builtinFunTable.getResolvers()) {
052            if (supportedBuiltinFunctions.contains(resolver.getName())) {
053                builder.define(resolver);
054            }
055        }
056
057        // Add special function definitions
058        for (FunDef funDef : specialFunctions) {
059            builder.define(funDef);
060        }
061    }
062}
063
064// End CustomizedFunctionTable.java