1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine.expression;
17
18 import java.util.List;
19
20 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
21 import org.kuali.rice.krms.api.engine.expression.ComparisonOperatorService;
22 import org.kuali.rice.krms.framework.engine.Function;
23
24
25
26
27
28
29
30 public final class FunctionExpression implements Expression<Object> {
31
32 private final Function function;
33 private final String [] parameterTypes;
34 private final List<Expression<? extends Object>> parameters;
35 private final ComparisonOperatorService comparisonOperatorService;
36
37
38
39
40
41
42
43
44
45 public FunctionExpression(Function function, String[] parameterTypes,
46 List<Expression<? extends Object>> parameters,
47 ComparisonOperatorService comparisonOperatorService) {
48 this.function = function;
49 this.parameterTypes = parameterTypes;
50 this.parameters = parameters;
51 this.comparisonOperatorService = comparisonOperatorService;
52 }
53
54 @Override
55 public Object invoke(ExecutionEnvironment environment) {
56 Object[] argumentValues = new Object[parameters.size()];
57
58 int argValIndex = 0;
59
60 for (Expression<? extends Object> argument : parameters) {
61 Object argumentValue = argument.invoke(environment);
62 String expectedArgumentType = parameterTypes[argValIndex];
63
64 argumentValue = ComparisonOperatorServiceUtils.coerceIfNeeded(argumentValue, expectedArgumentType, comparisonOperatorService);
65
66 argumentValues[argValIndex] = argumentValue;
67 argValIndex += 1;
68 }
69
70 return function.invoke(argumentValues);
71 }
72
73
74 }