1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl2.introspection;
18
19 import org.apache.commons.jexl2.JexlInfo;
20 import org.apache.commons.logging.Log;
21
22
23
24
25
26 public class SandboxUberspectImpl extends UberspectImpl {
27
28 protected final Sandbox sandbox;
29
30
31
32
33
34
35 public SandboxUberspectImpl(Log runtimeLogger, Sandbox theSandbox) {
36 super(runtimeLogger);
37 if (theSandbox == null) {
38 throw new NullPointerException("sandbox can not be null");
39 }
40 this.sandbox = theSandbox;
41 }
42
43
44
45
46 @Override
47 public void setLoader(ClassLoader cloader) {
48 base().setLoader(cloader);
49 }
50
51
52
53
54 @Override
55 public JexlMethod getConstructorMethod(Object ctorHandle, Object[] args, JexlInfo info) {
56 final String className;
57 if (ctorHandle instanceof Class<?>) {
58 Class<?> clazz = (Class<?>) ctorHandle;
59 className = clazz.getName();
60 } else if (ctorHandle != null) {
61 className = ctorHandle.toString();
62 } else {
63 return null;
64 }
65 if (sandbox.execute(className, "") != null) {
66 return super.getConstructorMethod(className, args, info);
67 }
68 return null;
69 }
70
71
72
73
74 @Override
75 public JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfo info) {
76 if (obj != null && method != null) {
77 String actual = sandbox.execute(obj.getClass().getName(), method);
78 if (actual != null) {
79 return getMethodExecutor(obj, actual, args);
80 }
81 }
82 return null;
83 }
84
85
86
87
88 @Override
89 public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfo info) {
90 if (obj != null && identifier != null) {
91 String actual = sandbox.read(obj.getClass().getName(), identifier.toString());
92 if (actual != null) {
93 return super.getPropertyGet(obj, actual, info);
94 }
95 }
96 return null;
97 }
98
99
100
101
102 @Override
103 public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg, JexlInfo info) {
104 if (obj != null && identifier != null) {
105 String actual = sandbox.write(obj.getClass().getName(), identifier.toString());
106 if (actual != null) {
107 return super.getPropertySet(obj, actual, arg, info);
108 }
109 }
110 return null;
111
112 }
113 }