001    package railo.runtime.interpreter.ref.func;
002    
003    import railo.runtime.PageContext;
004    import railo.runtime.exp.PageException;
005    import railo.runtime.interpreter.ref.Ref;
006    import railo.runtime.interpreter.ref.RefSupport;
007    import railo.runtime.interpreter.ref.util.RefUtil;
008    import railo.runtime.op.Caster;
009    
010    /**
011     * call of a User defined Function
012     */
013    public final class UDFCall extends RefSupport implements Ref {
014    
015            
016            private Ref[] arguments;
017        private String name;
018        private Ref parent;
019        private Ref refName;
020    
021        /**
022         * @param pc
023         * @param parent
024         * @param name
025         * @param arguments
026         */
027        public UDFCall(Ref parent, String name, Ref[] arguments) {
028            this.parent=parent;
029            this.name=name;
030            this.arguments=arguments;
031        }
032        
033        /**
034         * @param pc
035         * @param parent
036         * @param refName
037         * @param arguments
038         */
039        public UDFCall(Ref parent, Ref refName, Ref[] arguments) {
040            this.parent=parent;
041            this.refName=refName;
042            this.arguments=arguments;
043        }
044    
045        @Override
046            public Object getValue(PageContext pc) throws PageException {
047            return pc.getVariableUtil().callFunction(
048                    pc,
049                    parent.getValue(pc),
050                    getName(pc),
051                    RefUtil.getValue(pc,arguments)
052            );
053            }
054    
055            private String getName(PageContext pc) throws PageException {
056            if(name!=null)return name;
057            return Caster.toString(refName.getValue(pc));
058        }
059    
060            @Override
061        public String getTypeName() {
062                    return "user defined function";
063            }
064    }