001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.interpreter.ref.func; 020 021import lucee.runtime.PageContext; 022import lucee.runtime.exp.PageException; 023import lucee.runtime.interpreter.ref.Ref; 024import lucee.runtime.interpreter.ref.RefSupport; 025import lucee.runtime.interpreter.ref.util.RefUtil; 026import lucee.runtime.op.Caster; 027 028/** 029 * call of a User defined Function 030 */ 031public final class UDFCall extends RefSupport implements Ref { 032 033 034 private Ref[] arguments; 035 private String name; 036 private Ref parent; 037 private Ref refName; 038 039 /** 040 * @param pc 041 * @param parent 042 * @param name 043 * @param arguments 044 */ 045 public UDFCall(Ref parent, String name, Ref[] arguments) { 046 this.parent=parent; 047 this.name=name; 048 this.arguments=arguments; 049 } 050 051 /** 052 * @param pc 053 * @param parent 054 * @param refName 055 * @param arguments 056 */ 057 public UDFCall(Ref parent, Ref refName, Ref[] arguments) { 058 this.parent=parent; 059 this.refName=refName; 060 this.arguments=arguments; 061 } 062 063 @Override 064 public Object getValue(PageContext pc) throws PageException { 065 return pc.getVariableUtil().callFunction( 066 pc, 067 parent.getValue(pc), 068 getName(pc), 069 RefUtil.getValue(pc,arguments) 070 ); 071 } 072 073 private String getName(PageContext pc) throws PageException { 074 if(name!=null)return name; 075 return Caster.toString(refName.getValue(pc)); 076 } 077 078 @Override 079 public String getTypeName() { 080 return "user defined function"; 081 } 082}