1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.jexl342;
18
19 import org.apache.commons.jexl3.JexlEngine;
20 import org.apache.commons.jexl3.JexlException;
21 import org.apache.commons.jexl3.introspection.JexlMethod;
22
23
24
25
26 public class ReferenceMethodExecutor implements JexlMethod {
27
28 private final ReferenceUberspect.ReferenceHandler handler;
29
30 private final JexlMethod method;
31
32
33
34
35
36
37 public ReferenceMethodExecutor(final ReferenceUberspect.ReferenceHandler referenceHandler, final JexlMethod jexlMethod) {
38 if (referenceHandler == null || jexlMethod == null) {
39 throw new IllegalArgumentException("handler and method cant be null");
40 }
41 this.method = jexlMethod;
42 this.handler = referenceHandler;
43 }
44
45
46
47
48
49
50 protected Object getReference(final Object opt) {
51 return handler.callGet(opt);
52 }
53
54 @Override
55 public Class<?> getReturnType() {
56 return method != null ? method.getReturnType() : null;
57 }
58
59 @Override
60 public Object invoke(final Object ref, final Object... args) throws Exception {
61 final Object obj = getReference(ref);
62 return obj == null ? null : method.invoke(obj, args);
63 }
64
65 @Override
66 public boolean isCacheable() {
67 return method != null && method.isCacheable();
68 }
69
70 @Override
71 public boolean tryFailed(final Object rval) {
72 return method == null || method.tryFailed(rval);
73 }
74
75 @Override
76 public Object tryInvoke(final String name, final Object ref, final Object... args) throws JexlException.TryFailed {
77 final Object obj = getReference(ref);
78 if (method == null) {
79 return obj == null ? null : JexlEngine.TRY_FAILED;
80 }
81 if (obj == ref) {
82 return JexlEngine.TRY_FAILED;
83 }
84 return method.tryInvoke(name, obj, args);
85 }
86 }