1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jexl3.internal.introspection;
19
20 import java.util.Map;
21
22
23
24
25
26 public final class MapGetExecutor extends AbstractExecutor.Get {
27
28 private static final java.lang.reflect.Method MAP_GET =
29 initMarker(Map.class, "get", Object.class);
30
31 private final Object property;
32
33
34
35
36
37
38
39
40
41 public static MapGetExecutor discover(final Introspector is, final Class<?> clazz, final Object identifier) {
42
43 if (Map.class.isAssignableFrom(clazz) && is.getMethod(clazz, "get", identifier) != null) {
44 return new MapGetExecutor(clazz, MAP_GET, identifier);
45 }
46 return null;
47 }
48
49
50
51
52
53
54
55 private MapGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Object key) {
56 super(clazz, method);
57 property = key;
58 }
59
60 @Override
61 public Object getTargetProperty() {
62 return property;
63 }
64
65 @Override
66 public Object invoke(final Object obj) {
67 @SuppressWarnings("unchecked")
68 final Map<Object, ?> map = (Map<Object, ?>) obj;
69 return map.get(property);
70 }
71
72 @Override
73 public Object tryInvoke(final Object obj, final Object key) {
74 if (obj != null
75 && method != null
76 && objectClass.equals(obj.getClass())
77 && ((property == null && key == null)
78 || (property != null && key != null && property.getClass().equals(key.getClass())))) {
79 @SuppressWarnings("unchecked")
80 final Map<Object, ?> map = (Map<Object, ?>) obj;
81 return map.get(key);
82 }
83 return TRY_FAILED;
84 }
85 }