| 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 org.apache.commons.lang3.StringUtils; |
| 23 |
|
import org.apache.velocity.runtime.RuntimeServices; |
| 24 |
|
import org.apache.velocity.util.ClassUtils; |
| 25 |
|
import org.apache.velocity.util.RuntimeServicesAware; |
| 26 |
|
import org.apache.velocity.util.introspection.Uberspect; |
| 27 |
|
import org.apache.velocity.util.introspection.UberspectLoggable; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@since |
| 56 |
|
@see |
| 57 |
|
@version |
| 58 |
|
@deprecated |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@Deprecated |
| |
|
| 93.1% |
Uncovered Elements: 4 (58) |
Complexity: 19 |
Complexity Density: 0.53 |
|
| 62 |
|
public class ChainingUberspector extends AbstractChainableUberspector implements Uberspect, RuntimeServicesAware, |
| 63 |
|
UberspectLoggable |
| 64 |
|
{ |
| 65 |
|
|
| 66 |
|
public static final String UBERSPECT_CHAIN_CLASSNAMES = "runtime.introspector.uberspect.chainClasses"; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
private RuntimeServices runtime; |
| 70 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 71 |
17 |
@Override... |
| 72 |
|
public void setRuntimeServices(RuntimeServices rs) |
| 73 |
|
{ |
| 74 |
17 |
this.runtime = rs; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
@inheritDoc |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@see |
| 84 |
|
|
| |
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 85 |
17 |
@Override... |
| 86 |
|
public void init() |
| 87 |
|
{ |
| 88 |
17 |
this.log.debug("Initializing the chaining uberspector."); |
| 89 |
|
|
| 90 |
|
|
| 91 |
17 |
String[] chainClassnames = this.runtime.getConfiguration().getStringArray(UBERSPECT_CHAIN_CLASSNAMES); |
| 92 |
17 |
for (String classname : chainClassnames) { |
| 93 |
34 |
initializeUberspector(classname); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
17 |
if (this.inner == null) { |
| 97 |
1 |
this.log.error("No chained uberspectors defined! " |
| 98 |
|
+ "This uberspector is just a placeholder that relies on a real uberspector " |
| 99 |
|
+ "to actually allow method calls. Using SecureUberspect instead as a fallback."); |
| 100 |
1 |
initializeUberspector(SecureUberspector.class.getCanonicalName()); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
17 |
try { |
| 104 |
17 |
this.inner.init(); |
| 105 |
|
} catch (Exception e) { |
| 106 |
0 |
this.log.warn(e.getMessage()); |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
@link |
| 113 |
|
|
| 114 |
|
@param |
| 115 |
|
|
| |
|
| 96% |
Uncovered Elements: 1 (25) |
Complexity: 8 |
Complexity Density: 0.62 |
|
| 116 |
35 |
protected void initializeUberspector(String classname)... |
| 117 |
|
{ |
| 118 |
|
|
| 119 |
35 |
if (!StringUtils.isEmpty(classname) && !classname.equals(this.getClass().getCanonicalName())) { |
| 120 |
34 |
Uberspect u = instantiateUberspector(classname); |
| 121 |
34 |
if (u == null) { |
| 122 |
3 |
return; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
31 |
if (u instanceof UberspectLoggable) { |
| 127 |
31 |
((UberspectLoggable) u).setLog(this.log); |
| 128 |
|
} |
| 129 |
31 |
if (u instanceof RuntimeServicesAware) { |
| 130 |
11 |
((RuntimeServicesAware) u).setRuntimeServices(this.runtime); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
31 |
if (u instanceof ChainableUberspector) { |
| 135 |
5 |
((ChainableUberspector) u).wrap(this.inner); |
| 136 |
26 |
} else if (u instanceof org.apache.velocity.util.introspection.ChainableUberspector) { |
| 137 |
10 |
((org.apache.velocity.util.introspection.ChainableUberspector) u).wrap(this.inner); |
| 138 |
|
} |
| 139 |
31 |
this.inner = u; |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
@param |
| 147 |
|
@return |
| 148 |
|
@link |
| 149 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 7 |
Complexity Density: 0.58 |
|
| 150 |
34 |
protected Uberspect instantiateUberspector(String classname)... |
| 151 |
|
{ |
| 152 |
34 |
Object o = null; |
| 153 |
34 |
try { |
| 154 |
34 |
o = ClassUtils.getNewInstance(classname); |
| 155 |
|
} catch (ClassNotFoundException cnfe) { |
| 156 |
0 |
this.log.warn(String.format("The specified uberspector [%s]" |
| 157 |
|
+ " does not exist or is not accessible to the current classloader.", classname)); |
| 158 |
|
} catch (IllegalAccessException e) { |
| 159 |
1 |
this.log.warn(String.format("The specified uberspector [%s] does not have a public default constructor.", |
| 160 |
|
classname)); |
| 161 |
|
} catch (InstantiationException e) { |
| 162 |
1 |
this.log.warn(String.format("The specified uberspector [%s] cannot be instantiated.", classname)); |
| 163 |
|
} catch (ExceptionInInitializerError e) { |
| 164 |
0 |
this.log.warn(String.format("Exception while instantiating the Uberspector [%s]: %s", classname, e |
| 165 |
|
.getMessage())); |
| 166 |
|
} |
| 167 |
|
|
| 168 |
34 |
if (!(o instanceof Uberspect)) { |
| 169 |
3 |
if (o != null) { |
| 170 |
1 |
this.log.warn("The specified class for Uberspect [" + classname + "] does not implement " |
| 171 |
|
+ Uberspect.class.getName()); |
| 172 |
|
} |
| 173 |
3 |
return null; |
| 174 |
|
} |
| 175 |
31 |
return (Uberspect) o; |
| 176 |
|
} |
| 177 |
|
} |