forked from camunda-consulting/camunda-7-code-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DmnDecisionChaniningFunctionMapper.java
63 lines (55 loc) · 1.92 KB
/
DmnDecisionChaniningFunctionMapper.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.camunda.consulting;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.camunda.bpm.engine.impl.util.ReflectUtil;
import org.camunda.bpm.engine.variable.context.VariableContext;
import org.camunda.bpm.engine.impl.javax.el.FunctionMapper;
/**
* A FunctionMapper which resolves our DMN chaining function for Expression
* Language.
*
* <p>
* Lazy loading: This implementation supports lazy loading: the Java Methods are
* loaded upon the first request.
* </p>
*
* <p>
* Caching: once the methods are loaded, they are cached in a Map for efficient
* retrieval.
* </p>
*
*/
public class DmnDecisionChaniningFunctionMapper extends FunctionMapper {
public static Map<String, Method> functionCache = null;
public Method resolveFunction(String prefix, String localName) {
// methods are used un-prefixed
ensureSpinFunctionMapInitialized();
return functionCache.get(localName);
}
protected void ensureSpinFunctionMapInitialized() {
if (functionCache == null) {
synchronized (DmnDecisionChaniningFunctionMapper.class) {
if (functionCache == null) {
functionCache = new HashMap<String, Method>();
createMethodBindings();
}
}
}
}
protected void createMethodBindings() {
// do manually because of https://app.camunda.com/jira/browse/CAM-5429
// functionCache.put("dmnEvaluate",
// ReflectUtil.getMethod(DecisionTableEvaluator.class, "evaluate",
// String.class, VariableContext.class));
// functionCache.put("dmn",
// ReflectUtil.getMethod(DecisionTableEvaluator.class, "singleResult",
// String.class, VariableContext.class));
try {
Method methodSingleResult = DecisionTableEvaluator.class.getMethod("singleResult", String.class, VariableContext.class);
functionCache.put("dmn", methodSingleResult);
} catch (Exception ex) {
throw new RuntimeException("Could not create DMN function. Check nested exception for details", ex);
}
}
}