1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3;
18
19 import java.util.Collections;
20 import java.util.Map;
21
22 import org.apache.commons.jexl3.annotations.NoJexl;
23
24
25
26
27 public class JexlEvalContext implements
28 JexlContext,
29 JexlContext.NamespaceResolver,
30 JexlContext.OptionsHandle {
31
32 private static final Map<String,Object> EMPTY_MAP = Collections.<String,Object>emptyMap();
33
34 private final JexlContext vars;
35
36 private final JexlContext.NamespaceResolver ns;
37
38 private final JexlOptions options = new JexlOptions();
39
40
41
42
43 @NoJexl
44 public JexlEvalContext() {
45 this(EMPTY_MAP);
46 }
47
48
49
50
51
52 @NoJexl
53 public JexlEvalContext(final JexlContext context) {
54 this(context, context instanceof JexlContext.NamespaceResolver? (JexlContext.NamespaceResolver) context : null);
55 }
56
57
58
59
60
61
62 @NoJexl
63 public JexlEvalContext(final JexlContext context, final JexlContext.NamespaceResolver namespace) {
64 this.vars = context != null ? context : JexlEngine.EMPTY_CONTEXT;
65 this.ns = namespace != null ? namespace : JexlEngine.EMPTY_NS;
66 }
67
68
69
70
71
72
73
74 @NoJexl
75 public JexlEvalContext(final Map<String, Object> map) {
76 this.vars = map == EMPTY_MAP ? new MapContext() : new MapContext(map);
77 this.ns = null;
78 }
79
80 @Override
81 @NoJexl
82 public Object get(final String name) {
83 return vars.get(name);
84 }
85
86 @Override
87 @NoJexl
88 public JexlOptions getEngineOptions() {
89 return options;
90 }
91
92 @Override
93 @NoJexl
94 public boolean has(final String name) {
95 return vars.has(name);
96 }
97
98 @Override
99 @NoJexl
100 public Object resolveNamespace(final String name) {
101 return ns != null ? ns.resolveNamespace(name) : null;
102 }
103
104 @Override
105 @NoJexl
106 public void set(final String name, final Object value) {
107 vars.set(name, value);
108 }
109
110 }