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 PageContext pc;
019        private Ref parent;
020        private Ref refName;
021    
022        /**
023         * @param pc
024         * @param parent
025         * @param name
026         * @param arguments
027         */
028        public UDFCall(PageContext pc, Ref parent, String name, Ref[] arguments) {
029            this.pc=pc;
030            this.parent=parent;
031            this.name=name;
032            this.arguments=arguments;
033        }
034        
035        /**
036         * @param pc
037         * @param parent
038         * @param refName
039         * @param arguments
040         */
041        public UDFCall(PageContext pc, Ref parent, Ref refName, Ref[] arguments) {
042            this.pc=pc;
043            this.parent=parent;
044            this.refName=refName;
045            this.arguments=arguments;
046        }
047    
048        /**
049             * @see railo.runtime.interpreter.ref.Ref#getValue()
050             */
051            public Object getValue() throws PageException {
052            return pc.getVariableUtil().callFunction(
053                    pc,
054                    parent.getValue(),
055                    getName(),
056                    RefUtil.getValue(arguments)
057            );
058            }
059    
060            private String getName() throws PageException {
061            if(name!=null)return name;
062            return Caster.toString(refName.getValue());
063        }
064    
065        /**
066             * @see railo.runtime.interpreter.ref.Ref#getTypeName()
067             */
068            public String getTypeName() {
069                    return "user defined function";
070            }
071    }