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.type;
020
021import lucee.runtime.Component;
022import lucee.runtime.PageContext;
023import lucee.runtime.PageSource;
024import lucee.runtime.component.Member;
025import lucee.runtime.dump.Dumpable;
026import lucee.runtime.exp.PageException;
027import lucee.runtime.ext.function.Function;
028
029/**
030 * a user defined function
031 * 
032 */
033public interface UDF extends Function,Dumpable,Member,Cloneable {
034
035        public static final int RETURN_FORMAT_WDDX=0;
036        public static final int RETURN_FORMAT_JSON=1;
037        public static final int RETURN_FORMAT_PLAIN=2;
038        public static final int RETURN_FORMAT_SERIALIZE=3; // FUTURE change to RETURN_FORMAT_CFML
039        public static final int RETURN_FORMAT_XML=4;
040        
041
042    /**
043     * abstract method for the function Body
044     * @param pageContext
045     * @throws Throwable
046     */
047    public abstract Object implementation(PageContext pageContext)
048            throws Throwable;
049
050    /**
051     * return all function arguments of this UDF
052     * @return the arguments.
053     * @throws PageException
054     */
055    public abstract FunctionArgument[] getFunctionArguments();
056
057    /**
058     * @param pc
059     * @param index
060     * @return default value
061     * @throws PageException
062     */
063    public abstract Object getDefaultValue(PageContext pc, int index) throws PageException;
064    
065
066    // FUTURE public abstract Object getDefaultValue(PageContext pc, int index, Object defaultValue);
067
068    /**
069     * @return Returns the functionName.
070     */
071    public abstract String getFunctionName();
072
073    /**
074     * @return Returns the output.
075     */
076    public abstract boolean getOutput();
077
078    /**
079     * @return Returns the returnType.
080     */
081    public int getReturnType();
082
083    public int getReturnFormat(); // FUTURE mark as deprecated
084    // FUTURE public abstract int getReturnFormat(int defaultFormat);
085
086    /**
087     * returns null when not defined
088     * @return value of attribute securejson
089     */
090    public abstract Boolean getSecureJson();
091
092    /**
093     * returns null when not defined
094     * @return value of attribute verifyclient
095     */
096    public abstract Boolean getVerifyClient();
097    
098    /**
099     * @return Returns the returnType.
100     */
101    public abstract String getReturnTypeAsString();
102
103    public abstract String getDescription();
104    
105    /**
106     * call user defined Funcion with a hashmap of named values
107     * @param pageContext
108     * @param values named values
109     * @param doIncludePath 
110     * @return return value of the function
111     * @throws PageException
112     */
113    public abstract Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException;
114
115    /**
116     * call user defined Funcion with parameters as Object Array
117     * @param pageContext
118     * @param args parameters for the function
119     * @param doIncludePath 
120     * @return return value of the function
121     * @throws PageException
122     */
123    public abstract Object call(PageContext pageContext, Object[] args,boolean doIncludePath) throws PageException;
124
125    /**
126     * @return Returns the displayName.
127     */
128    public abstract String getDisplayName();
129
130    /**
131     * @return Returns the hint.
132     */
133    public abstract String getHint();
134
135
136    public abstract PageSource getPageSource();
137    
138        public abstract Struct getMetaData(PageContext pc) throws PageException; 
139        
140
141        public UDF duplicate();
142        
143        /**
144         * it is the component in whitch this udf is constructed, must not be the same as active udf
145         * @return owner component
146         * @deprecated 
147         */
148        public Component getOwnerComponent();
149
150        
151}