001    package railo.commons.io.res.util;
002    
003    import railo.commons.lang.CFTypes;
004    import railo.runtime.exp.ExpressionException;
005    import railo.runtime.type.FunctionArgument;
006    import railo.runtime.type.UDF;
007    
008    public abstract class UDFFilterSupport {
009    
010            protected UDF udf;
011            protected Object[] args=new Object[1];
012            
013            public UDFFilterSupport(UDF udf) throws ExpressionException{
014                    this.udf=udf;
015                    
016                    // check UDF return type
017                    int type = udf.getReturnType();
018                    if(type!=CFTypes.TYPE_BOOLEAN && type!=CFTypes.TYPE_ANY)
019                            throw new ExpressionException("invalid return type ["+udf.getReturnTypeAsString()+"] for UDF Filter, valid return types are [boolean,any]");
020                    
021                    // check UDF arguments
022                    FunctionArgument[] args = udf.getFunctionArguments();
023                    if(args.length>1)
024                            throw new ExpressionException("UDF filter has to many arguments ["+args.length+"], should have at maximum 1 argument");
025                    
026                    if(args.length==1){
027                            type=args[0].getType();
028                            if(type!=CFTypes.TYPE_STRING && type!=CFTypes.TYPE_ANY)
029                                    throw new ExpressionException("invalid type ["+args[0].getTypeAsString()+"] for first argument of UDF Filter, valid return types are [string,any]");
030                    }
031                    
032                    
033            }
034            
035        /**
036             *
037             * @see java.lang.Object#toString()
038             */
039            public String toString() {
040                    return "UDFFilter:"+udf;
041            }
042    }