001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/fun/SimpleResolver.java#15 $
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) 2002-2002 Kana Software, Inc.
007    // Copyright (C) 2002-2006 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // jhyde, 3 March, 2002
012    */
013    package mondrian.olap.fun;
014    
015    import mondrian.olap.*;
016    
017    /**
018     * A <code>SimpleResolver</code> resolves a single, non-overloaded function.
019     *
020     * @author jhyde
021     * @since 3 March, 2002
022     * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/SimpleResolver.java#15 $
023     */
024    class SimpleResolver implements Resolver {
025        private  final FunDef funDef;
026    
027        SimpleResolver(FunDef funDef) {
028            this.funDef = funDef;
029        }
030    
031        public FunDef getFunDef() {
032            return funDef;
033        }
034    
035        public String getName() {
036            return funDef.getName();
037        }
038    
039        public String getDescription() {
040            return funDef.getDescription();
041        }
042    
043        public String getSignature() {
044            return funDef.getSignature();
045        }
046    
047        public Syntax getSyntax() {
048            return funDef.getSyntax();
049        }
050    
051        public String[] getReservedWords() {
052            return FunUtil.emptyStringArray;
053        }
054    
055        public FunDef resolve(
056                Exp[] args, Validator validator, int[] conversionCount) {
057            int[] parameterTypes = funDef.getParameterCategories();
058            if (parameterTypes.length != args.length) {
059                return null;
060            }
061            for (int i = 0; i < args.length; i++) {
062                if (!validator.canConvert(
063                        args[i], parameterTypes[i], conversionCount)) {
064                    return null;
065                }
066            }
067            return funDef;
068        }
069    
070        public boolean requiresExpression(int k) {
071            int[] parameterTypes = funDef.getParameterCategories();
072            return ((k >= parameterTypes.length) ||
073                   (parameterTypes[k] != Category.Set));
074        }
075    }
076    
077    // End SimpleResolver.java