use of lucee.runtime.type.FunctionValue in project Lucee by lucee.
the class _CreateComponent method call.
public static Object call(PageContext pc, Object[] objArr) throws PageException {
String path = Caster.toString(objArr[objArr.length - 1]);
// not store the index to make it faster
Component c = CreateObject.doComponent(pc, path);
// no init method
if (!(c.get(KeyConstants._init, null) instanceof UDF)) {
if (objArr.length > 1) {
Object arg1 = objArr[0];
if (arg1 instanceof FunctionValue) {
Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
EntityNew.setPropeties(pc, c, args, true);
} else if (Decision.isStruct(arg1)) {
Struct args = Caster.toStruct(arg1);
EntityNew.setPropeties(pc, c, args, true);
}
}
return c;
}
Object rtn;
// no arguments
if (objArr.length == 1) {
rtn = c.call(pc, KeyConstants._init, EMPTY);
} else // named arguments
if (objArr[0] instanceof FunctionValue) {
Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
rtn = c.callWithNamedValues(pc, KeyConstants._init, args);
} else // no name arguments
{
Object[] args = new Object[objArr.length - 1];
for (int i = 0; i < objArr.length - 1; i++) {
args[i] = objArr[i];
if (args[i] instanceof FunctionValue)
throw new ExpressionException("invalid argument defintion, when using named parameters to a function, every parameter must have a name.");
}
rtn = c.call(pc, KeyConstants._init, args);
}
if (rtn == null || (c.getPageSource() != null && c.getPageSource().getDialect() == CFMLEngine.DIALECT_LUCEE))
return c;
return rtn;
}
use of lucee.runtime.type.FunctionValue in project Lucee by lucee.
the class Query_ method call.
public static Query call(PageContext pc, Object[] arr) throws DatabaseException {
String[] names = new String[arr.length];
Array[] columns = new Array[arr.length];
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] instanceof FunctionValue) {
FunctionValue vf = (FunctionValue) arr[i];
if (vf.getValue() instanceof Array) {
names[count] = vf.getNameAsString();
columns[count] = (Array) vf.getValue();
count++;
} else
throw new DatabaseException("invalid argument for function query, only array as value are allowed", "example: query(column1:array(1,2,3))", null, null);
} else
throw new DatabaseException("invalid argument for function query, only named argument are allowed", "example: query(column1:array(1,2,3))", null, null);
}
Query query = new QueryImpl(names, columns, "query");
return query;
}
Aggregations