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.content2bean; |
35 |
|
|
36 |
|
import java.beans.Introspector; |
37 |
|
import java.util.Map; |
38 |
|
|
39 |
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; |
40 |
|
import org.springframework.util.ClassUtils; |
41 |
|
|
42 |
|
import info.magnolia.content2bean.Content2BeanException; |
43 |
|
import info.magnolia.content2bean.TransformationState; |
44 |
|
import info.magnolia.content2bean.TypeDescriptor; |
45 |
|
import info.magnolia.content2bean.TypeMapping; |
46 |
|
import info.magnolia.content2bean.impl.Content2BeanTransformerImpl; |
47 |
|
import info.magnolia.objectfactory.ComponentProvider; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@since |
61 |
|
@deprecated |
62 |
|
|
63 |
|
@Deprecated |
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 11 |
Complexity Density: 0.73 |
|
64 |
|
public class SpringContent2BeanTransformer extends Content2BeanTransformerImpl { |
65 |
|
|
66 |
|
private TypeDescriptor defaultType; |
67 |
|
private Class<?> defaultClass; |
68 |
|
|
69 |
|
private String topLevelBeanName; |
70 |
|
private AutowireCapableBeanFactory autowireCapableBeanFactory; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
1 |
public SpringContent2BeanTransformer(AutowireCapableBeanFactory autowireCapableBeanFactory) {... |
73 |
1 |
this.autowireCapableBeanFactory = autowireCapableBeanFactory; |
74 |
|
} |
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
76 |
|
public void setDefaultClass(Class<?> defaultClass) {... |
77 |
|
this.defaultClass = defaultClass; |
78 |
|
} |
79 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
80 |
|
public void setTopLevelBeanName(String topLevelBeanName) {... |
81 |
|
this.topLevelBeanName = topLevelBeanName; |
82 |
|
} |
83 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 5 |
Complexity Density: 1.67 |
|
84 |
2 |
@Override... |
85 |
|
protected TypeDescriptor onResolveType(TypeMapping typeMapping, TransformationState state, TypeDescriptor resolvedType, ComponentProvider componentProvider) { |
86 |
2 |
if (resolvedType == null && defaultType == null && defaultClass != null) { |
87 |
0 |
defaultType = typeMapping.getTypeDescriptor(defaultClass); |
88 |
|
} |
89 |
2 |
return resolvedType == null ? defaultType : resolvedType; |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
92 |
2 |
@Override... |
93 |
|
public Object newBeanInstance(TransformationState state, Map properties, ComponentProvider componentProvider) throws Content2BeanException { |
94 |
|
|
95 |
|
|
96 |
2 |
Object bean = super.newBeanInstance(state, properties, componentProvider); |
97 |
|
|
98 |
|
|
99 |
2 |
this.autowireCapableBeanFactory.autowireBean(bean); |
100 |
|
|
101 |
|
|
102 |
2 |
return bean; |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
105 |
2 |
@Override... |
106 |
|
public void initBean(TransformationState state, Map properties) throws Content2BeanException { |
107 |
|
|
108 |
2 |
Object bean = state.getCurrentBean(); |
109 |
|
|
110 |
|
|
111 |
2 |
String beanName = resolveBeanName(state, bean); |
112 |
|
|
113 |
|
|
114 |
2 |
bean = this.autowireCapableBeanFactory.initializeBean(state.getCurrentBean(), beanName); |
115 |
|
|
116 |
2 |
state.setCurrentBean(bean); |
117 |
|
} |
118 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
119 |
2 |
protected String resolveBeanName(TransformationState state, Object bean) {... |
120 |
|
|
121 |
|
|
122 |
2 |
if (state.getLevel() == 1 && topLevelBeanName != null) { |
123 |
0 |
return topLevelBeanName; |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
2 |
String shortClassName = ClassUtils.getShortName(bean.getClass()); |
128 |
2 |
return Introspector.decapitalize(shortClassName); |
129 |
|
} |
130 |
|
} |