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-2011 Pentaho and others 009// All Rights Reserved. 010*/ 011package mondrian.olap.fun; 012 013import mondrian.olap.*; 014 015import java.util.List; 016 017/** 018 * A <code>SimpleResolver</code> resolves a single, non-overloaded function. 019 * 020 * @author jhyde 021 * @since 3 March, 2002 022 */ 023class SimpleResolver implements Resolver { 024 private final FunDef funDef; 025 026 SimpleResolver(FunDef funDef) { 027 this.funDef = funDef; 028 } 029 030 public FunDef getFunDef() { 031 return funDef; 032 } 033 034 public String getName() { 035 return funDef.getName(); 036 } 037 038 public String getDescription() { 039 return funDef.getDescription(); 040 } 041 042 public String getSignature() { 043 return funDef.getSignature(); 044 } 045 046 public Syntax getSyntax() { 047 return funDef.getSyntax(); 048 } 049 050 public String[] getReservedWords() { 051 return FunUtil.emptyStringArray; 052 } 053 054 public FunDef resolve( 055 Exp[] args, 056 Validator validator, 057 List<Conversion> conversions) 058 { 059 int[] parameterTypes = funDef.getParameterCategories(); 060 if (parameterTypes.length != args.length) { 061 return null; 062 } 063 for (int i = 0; i < args.length; i++) { 064 if (!validator.canConvert( 065 i, args[i], parameterTypes[i], conversions)) 066 { 067 return null; 068 } 069 } 070 return funDef; 071 } 072 073 public boolean requiresExpression(int k) { 074 int[] parameterTypes = funDef.getParameterCategories(); 075 return (k >= parameterTypes.length) 076 || (parameterTypes[k] != Category.Set); 077 } 078} 079 080// End SimpleResolver.java