1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.velocity.introspection; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.apache.velocity.runtime.RuntimeServices; |
28 |
|
import org.apache.velocity.util.ClassUtils; |
29 |
|
import org.apache.velocity.util.RuntimeServicesAware; |
30 |
|
import org.apache.velocity.util.introspection.Info; |
31 |
|
import org.apache.velocity.util.introspection.Uberspect; |
32 |
|
import org.apache.velocity.util.introspection.UberspectImpl; |
33 |
|
import org.apache.velocity.util.introspection.UberspectLoggable; |
34 |
|
import org.apache.velocity.util.introspection.VelMethod; |
35 |
|
import org.apache.velocity.util.introspection.VelPropertyGet; |
36 |
|
import org.apache.velocity.util.introspection.VelPropertySet; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@since |
61 |
|
@see |
62 |
|
@version |
63 |
|
@deprecated |
64 |
|
|
65 |
|
|
66 |
|
@Deprecated |
|
|
| 64.4% |
Uncovered Elements: 31 (87) |
Complexity: 25 |
Complexity Density: 0.44 |
|
67 |
|
public class LinkingUberspector extends UberspectImpl implements Uberspect, RuntimeServicesAware, UberspectLoggable |
68 |
|
{ |
69 |
|
|
70 |
|
public static final String UBERSPECT_ARRAY_CLASSNAMES = "runtime.introspector.uberspect.arrayClasses"; |
71 |
|
|
72 |
|
|
73 |
|
private RuntimeServices runtime; |
74 |
|
|
75 |
|
|
76 |
|
private List<Uberspect> uberspectors; |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
6 |
@Override... |
79 |
|
public void setRuntimeServices(RuntimeServices rs) |
80 |
|
{ |
81 |
6 |
this.runtime = rs; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@inheritDoc |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@see |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
92 |
6 |
@Override... |
93 |
|
public void init() |
94 |
|
{ |
95 |
6 |
this.log.debug("Initializing the linking uberspector."); |
96 |
|
|
97 |
6 |
String[] arrayClassnames = this.runtime.getConfiguration().getStringArray(UBERSPECT_ARRAY_CLASSNAMES); |
98 |
6 |
this.uberspectors = new ArrayList<Uberspect>(arrayClassnames.length); |
99 |
6 |
for (String classname : arrayClassnames) { |
100 |
13 |
initializeUberspector(classname); |
101 |
|
} |
102 |
|
|
103 |
6 |
if (this.uberspectors.isEmpty()) { |
104 |
1 |
this.log.error("No uberspectors defined! " |
105 |
|
+ "This uberspector is just a placeholder that relies on at least one real uberspector " |
106 |
|
+ "to actually allow method calls. Using SecureUberspector instead as a fallback."); |
107 |
1 |
initializeUberspector(SecureUberspector.class.getCanonicalName()); |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 7 |
Complexity Density: 0.58 |
|
117 |
14 |
protected void initializeUberspector(String classname)... |
118 |
|
{ |
119 |
|
|
120 |
14 |
if (!StringUtils.isEmpty(classname) && !classname.equals(this.getClass().getCanonicalName())) { |
121 |
13 |
Uberspect u = instantiateUberspector(classname); |
122 |
13 |
if (u == null) { |
123 |
3 |
return; |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
10 |
if (u instanceof UberspectLoggable) { |
128 |
10 |
((UberspectLoggable) u).setLog(this.log); |
129 |
|
} |
130 |
10 |
if (u instanceof RuntimeServicesAware) { |
131 |
2 |
((RuntimeServicesAware) u).setRuntimeServices(this.runtime); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
10 |
try { |
136 |
10 |
u.init(); |
137 |
|
|
138 |
10 |
this.uberspectors.add(u); |
139 |
|
} catch (Exception e) { |
140 |
0 |
this.log.warn(e.getMessage()); |
141 |
|
|
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
@param |
150 |
|
@return |
151 |
|
@link |
152 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 7 |
Complexity Density: 0.58 |
|
153 |
13 |
protected Uberspect instantiateUberspector(String classname)... |
154 |
|
{ |
155 |
13 |
Object o = null; |
156 |
13 |
try { |
157 |
13 |
o = ClassUtils.getNewInstance(classname); |
158 |
|
} catch (ClassNotFoundException e) { |
159 |
0 |
this.log.warn(String.format("The specified uberspector [%s]" |
160 |
|
+ " does not exist or is not accessible to the current classloader.", classname)); |
161 |
|
} catch (IllegalAccessException e) { |
162 |
1 |
this.log.warn(String.format("The specified uberspector [%s] does not have a public default constructor.", |
163 |
|
classname)); |
164 |
|
} catch (InstantiationException e) { |
165 |
1 |
this.log.warn(String.format("The specified uberspector [%s] cannot be instantiated.", classname)); |
166 |
|
} catch (ExceptionInInitializerError e) { |
167 |
0 |
this.log.warn(String.format("Exception while instantiating the Uberspector [%s]: %s", classname, e |
168 |
|
.getMessage())); |
169 |
|
} |
170 |
|
|
171 |
13 |
if (!(o instanceof Uberspect)) { |
172 |
3 |
if (o != null) { |
173 |
1 |
this.log.warn("The specified class for Uberspect [" + classname + "] does not implement " |
174 |
|
+ Uberspect.class.getName()); |
175 |
|
} |
176 |
3 |
return null; |
177 |
|
} |
178 |
10 |
return (Uberspect) o; |
179 |
|
} |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
181 |
0 |
@SuppressWarnings("unchecked")... |
182 |
|
@Override |
183 |
|
public Iterator getIterator(Object obj, Info i) throws Exception |
184 |
|
{ |
185 |
0 |
Iterator it; |
186 |
0 |
for (Uberspect u : this.uberspectors) { |
187 |
0 |
it = u.getIterator(obj, i); |
188 |
0 |
if (it != null) { |
189 |
0 |
return it; |
190 |
|
} |
191 |
|
} |
192 |
0 |
return null; |
193 |
|
} |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
195 |
9 |
@Override... |
196 |
|
public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception |
197 |
|
{ |
198 |
9 |
VelMethod method; |
199 |
9 |
for (Uberspect u : this.uberspectors) { |
200 |
12 |
method = u.getMethod(obj, methodName, args, i); |
201 |
12 |
if (method != null) { |
202 |
6 |
return method; |
203 |
|
} |
204 |
|
} |
205 |
3 |
return null; |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
208 |
0 |
@Override... |
209 |
|
public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception |
210 |
|
{ |
211 |
0 |
VelPropertyGet getter; |
212 |
0 |
for (Uberspect u : this.uberspectors) { |
213 |
0 |
getter = u.getPropertyGet(obj, identifier, i); |
214 |
0 |
if (getter != null) { |
215 |
0 |
return getter; |
216 |
|
} |
217 |
|
} |
218 |
0 |
return null; |
219 |
|
} |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
221 |
0 |
@Override... |
222 |
|
public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception |
223 |
|
{ |
224 |
0 |
VelPropertySet setter; |
225 |
0 |
for (Uberspect u : this.uberspectors) { |
226 |
0 |
setter = u.getPropertySet(obj, identifier, arg, i); |
227 |
0 |
if (setter != null) { |
228 |
0 |
return setter; |
229 |
|
} |
230 |
|
} |
231 |
0 |
return null; |
232 |
|
} |
233 |
|
} |