@Override public FunctionArgument[] getFunctionArguments() { if (args == null) { ArrayList<FunctionLibFunctionArg> src = flf.getArg(); args = new FunctionArgument[src.size()]; String def; int index = -1; FunctionLibFunctionArg arg; Iterator<FunctionLibFunctionArg> it = src.iterator(); while (it.hasNext()) { arg = it.next(); def = arg.getDefaultValue(); args[++index] = new FunctionArgumentImpl( KeyImpl.init(arg.getName()), arg.getTypeAsString(), arg.getType(), arg.getRequired(), def == null ? FunctionArgument.DEFAULT_TYPE_NULL : FunctionArgument.DEFAULT_TYPE_LITERAL, true, arg.getName(), arg.getDescription(), null); } } return args; }
@Override public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException { ArrayList<FunctionLibFunctionArg> flfas = flf.getArg(); Iterator<FunctionLibFunctionArg> it = flfas.iterator(); FunctionLibFunctionArg arg; Object val; List<Ref> refs = new ArrayList<Ref>(); while (it.hasNext()) { arg = it.next(); // match by name val = values.get(arg.getName(), null); // match by alias if (val == null) { String alias = arg.getAlias(); if (!StringUtil.isEmpty(alias, true)) { String[] aliases = lucee.runtime.type.util.ListUtil.trimItems( lucee.runtime.type.util.ListUtil.listToStringArray(alias, ',')); for (int x = 0; x < aliases.length; x++) { val = values.get(aliases[x], null); if (val != null) break; } } } if (val == null) { if (arg.getRequired()) { String[] names = flf.getMemberNames(); String n = ArrayUtil.isEmpty(names) ? "" : names[0]; throw new ExpressionException( "missing required argument [" + arg.getName() + "] for build in function call [" + n + "]"); } } else { refs.add( new Casting( arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), val))); } } BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()])); return call.getValue(pageContext); }
@Override public Object call(PageContext pageContext, Object[] args, boolean doIncludePath) throws PageException { ArrayList<FunctionLibFunctionArg> flfas = flf.getArg(); FunctionLibFunctionArg flfa; List<Ref> refs = new ArrayList<Ref>(); for (int i = 0; i < args.length; i++) { if (i >= flfas.size()) throw new ApplicationException( "too many Attributes in function call [" + flf.getName() + "]"); flfa = flfas.get(i); refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[i])); } BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()])); return call.getValue(pageContext); }