-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONataFunctionWrapper.cfc
More file actions
37 lines (33 loc) · 1.18 KB
/
JSONataFunctionWrapper.cfc
File metadata and controls
37 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
component displayname="JSONataFunctionWrapper" hint="Wraps a CFML closure with a method callable via Java reflection" {
variables.closure = "";
public JSONataFunctionWrapper function init(required any closure) {
variables.closure = arguments.closure;
return this;
}
/**
* Called by CFMLFunctionBridge via Java reflection.
* @input The current context value in the JSONata expression
* @args A Java List of arguments passed to the function
*/
public any function callClosure(any input, any args) {
if (!isNull(arguments.args) && isArray(arguments.args)) {
var argCount = arrayLen(arguments.args);
if (argCount eq 0) {
return variables.closure();
} else if (argCount eq 1) {
return variables.closure(arguments.args[1]);
} else if (argCount eq 2) {
return variables.closure(arguments.args[1], arguments.args[2]);
} else if (argCount eq 3) {
return variables.closure(arguments.args[1], arguments.args[2], arguments.args[3]);
} else {
var argStruct = {};
for (var i = 1; i <= argCount; i++) {
argStruct[i] = arguments.args[i];
}
return variables.closure(argumentCollection = argStruct);
}
}
return variables.closure();
}
}