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.JexlPropertySet;
22
23
24
25
26 public class ReferenceSetExecutor implements JexlPropertySet {
27
28 private final ReferenceUberspect.ReferenceHandler handler;
29
30 private final JexlPropertySet setter;
31
32
33
34
35
36
37 public ReferenceSetExecutor(final ReferenceUberspect.ReferenceHandler referenceHandler, final JexlPropertySet jexlSet) {
38 if (referenceHandler == null || jexlSet == null) {
39 throw new IllegalArgumentException("handler and setter cant be null");
40 }
41 this.handler = referenceHandler;
42 this.setter = jexlSet;
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 Object invoke(final Object opt, final Object arg) throws Exception {
56 final Object obj = getReference(opt);
57 return setter.invoke(obj, arg);
58 }
59
60 @Override
61 public boolean isCacheable() {
62 return setter.isCacheable();
63 }
64
65 @Override
66 public boolean tryFailed(final Object rval) {
67 return setter.tryFailed(rval);
68 }
69
70 @Override
71 public Object tryInvoke(final Object opt, final Object key, final Object arg) throws JexlException.TryFailed {
72 final Object obj = getReference(opt);
73 return obj == opt? JexlEngine.TRY_FAILED : obj == null ? null : setter.tryInvoke(key, obj, arg);
74 }
75 }