forked from alibaba/QLExpress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQLSpringContext.java
More file actions
35 lines (27 loc) · 1.12 KB
/
QLSpringContext.java
File metadata and controls
35 lines (27 loc) · 1.12 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
package com.alibaba.qlexpress4.spring;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import com.alibaba.qlexpress4.runtime.Value;
import com.alibaba.qlexpress4.runtime.context.ExpressContext;
import com.alibaba.qlexpress4.runtime.data.DataValue;
import com.alibaba.qlexpress4.runtime.data.MapItemValue;
public class QLSpringContext implements ExpressContext {
private final Map<String, Object> context;
private final ApplicationContext applicationContext;
public QLSpringContext(Map<String, Object> context, ApplicationContext applicationContext) {
this.context = context;
this.applicationContext = applicationContext;
}
@Override
public Value get(Map<String, Object> attachments, String variableName) {
Object value = context.get(variableName);
if (value != null) {
return new MapItemValue(context, variableName);
}
Object bean = applicationContext.getBean(variableName);
if (bean != null) {
return new DataValue(bean);
}
return new MapItemValue(context, value);
}
}