1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.urimapping; |
35 |
|
|
36 |
|
import java.lang.reflect.Method; |
37 |
|
import java.lang.reflect.Modifier; |
38 |
|
|
39 |
|
import org.slf4j.Logger; |
40 |
|
import org.slf4j.LoggerFactory; |
41 |
|
import org.springframework.util.ClassUtils; |
42 |
|
import org.springframework.util.ReflectionUtils; |
43 |
|
|
44 |
|
import info.magnolia.cms.beans.config.VirtualURIMapping; |
45 |
|
import info.magnolia.module.blossom.annotation.VirtualURIMapper; |
46 |
|
import info.magnolia.module.blossom.support.AbstractBeanDetector; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@see |
52 |
|
@since |
53 |
|
|
|
|
| 86.5% |
Uncovered Elements: 5 (37) |
Complexity: 13 |
Complexity Density: 0.72 |
|
54 |
|
public class AnnotatedVirtualURIMappingExporter extends AbstractBeanDetector { |
55 |
|
|
56 |
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
57 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
58 |
96 |
@Override... |
59 |
|
protected boolean include(Class<?> beanType, String beanName) { |
60 |
96 |
beanType = ClassUtils.isCglibProxyClass(beanType) ? beanType.getSuperclass() : beanType; |
61 |
96 |
if (beanType.isAnnotationPresent(VirtualURIMapper.class)) { |
62 |
3 |
if (ClassUtils.isAssignable(VirtualURIMapping.class, beanType)) { |
63 |
1 |
if (logger.isWarnEnabled()) { |
64 |
1 |
logger.warn("Bean [" + beanName + "] annotated with VirtualUriMapper should not also implement VirtualURIMapping, will not have methods exposed"); |
65 |
|
} |
66 |
1 |
return false; |
67 |
|
} |
68 |
2 |
return true; |
69 |
|
} |
70 |
93 |
return false; |
71 |
|
} |
72 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
73 |
2 |
@Override... |
74 |
|
protected void onBeanDetection(final Object bean, final String beanName) { |
75 |
|
|
76 |
2 |
if (logger.isDebugEnabled()) { |
77 |
0 |
logger.debug("Detected VirtualURIMapper on bean [" + beanName + "] scanning methods to expose"); |
78 |
|
} |
79 |
|
|
80 |
2 |
final Class<?> beanType = bean.getClass(); |
81 |
2 |
ReflectionUtils.doWithMethods(beanType, new ReflectionUtils.MethodCallback() { |
82 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
83 |
80 |
@Override... |
84 |
|
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { |
85 |
80 |
if (isEligibleMethod(method) && method.equals(ClassUtils.getMostSpecificMethod(method, beanType))) { |
86 |
|
|
87 |
4 |
if (logger.isDebugEnabled()) { |
88 |
0 |
logger.debug("Exposing VirtualURIMapping for method [" + method + "] on bean [" + beanName + "]"); |
89 |
|
} |
90 |
|
|
91 |
4 |
BlossomVirtualURIMapping.addMapping(createMethodAdapter(method, bean)); |
92 |
|
} |
93 |
|
} |
94 |
|
}); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
80 |
protected boolean isEligibleMethod(Method method) {... |
98 |
80 |
return method.getParameterTypes().length > 0 && |
99 |
|
(method.getReturnType().equals(String.class) || method.getReturnType().equals(VirtualURIMapping.MappingResult.class)) && |
100 |
|
Modifier.isPublic(method.getModifiers()) && |
101 |
|
!Modifier.isStatic(method.getModifiers()); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
4 |
protected VirtualURIMappingAdapter createMethodAdapter(Method method, Object bean) {... |
105 |
4 |
return new VirtualURIMappingAdapter(bean, method); |
106 |
|
} |
107 |
|
} |