1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.instance.internal.input; |
21 |
|
|
22 |
|
import java.lang.reflect.ParameterizedType; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
|
27 |
|
import org.xwiki.component.phase.InitializationException; |
28 |
|
import org.xwiki.component.util.ReflectionUtils; |
29 |
|
import org.xwiki.filter.FilterException; |
30 |
|
import org.xwiki.filter.descriptor.DefaultFilterStreamBeanDescriptor; |
31 |
|
import org.xwiki.filter.instance.input.AbstractEntityEventGenerator; |
32 |
|
import org.xwiki.filter.instance.input.BeanEntityEventGenerator; |
33 |
|
import org.xwiki.filter.instance.input.EntityEventGenerator; |
34 |
|
import org.xwiki.properties.BeanManager; |
35 |
|
|
36 |
|
|
37 |
|
@param |
38 |
|
@param@link |
39 |
|
@param |
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 66.7% |
Uncovered Elements: 10 (30) |
Complexity: 10 |
Complexity Density: 0.53 |
|
43 |
|
public abstract class AbstractBeanEntityEventGenerator<E, F, P> extends AbstractEntityEventGenerator<E, F> |
44 |
|
implements BeanEntityEventGenerator<E, P> |
45 |
|
{ |
46 |
|
@Inject |
47 |
|
private BeanManager beanManager; |
48 |
|
|
49 |
|
private String name; |
50 |
|
|
51 |
|
private String description; |
52 |
|
|
53 |
|
private Class<P> propertiesType; |
54 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
55 |
476 |
@Override... |
56 |
|
public void initialize() throws InitializationException |
57 |
|
{ |
58 |
476 |
super.initialize(); |
59 |
|
|
60 |
|
|
61 |
476 |
ParameterizedType genericType = |
62 |
|
(ParameterizedType) ReflectionUtils.resolveType(AbstractBeanEntityEventGenerator.class, getClass()); |
63 |
476 |
this.propertiesType = ReflectionUtils.getTypeClass(genericType.getActualTypeArguments()[2]); |
64 |
|
|
65 |
|
|
66 |
476 |
DefaultFilterStreamBeanDescriptor descriptor = |
67 |
|
new DefaultFilterStreamBeanDescriptor(getName(), getDescription(), this.beanManager |
68 |
476 |
.getBeanDescriptor(!this.propertiesType.isInterface() ? this.propertiesType : Object.class)); |
69 |
|
|
70 |
476 |
setDescriptor(descriptor); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
public void setName(String name)... |
77 |
|
{ |
78 |
0 |
this.name = name; |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
@return |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
476 |
public String getName()... |
85 |
|
{ |
86 |
476 |
return this.name; |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0 |
public void setDescription(String description)... |
93 |
|
{ |
94 |
0 |
this.description = description; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
@return |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
476 |
public String getDescription()... |
101 |
|
{ |
102 |
476 |
return this.description; |
103 |
|
} |
104 |
|
|
|
|
| 50% |
Uncovered Elements: 5 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
105 |
29737 |
@Override... |
106 |
|
protected void write(E entity, Object filter, F internalFilter, Map<String, Object> properties) |
107 |
|
throws FilterException |
108 |
|
{ |
109 |
29737 |
P propertiesBean; |
110 |
|
|
111 |
29737 |
if (this.propertiesType.isInstance(properties)) { |
112 |
29737 |
propertiesBean = (P) properties; |
113 |
|
} else { |
114 |
0 |
try { |
115 |
0 |
propertiesBean = this.propertiesType.newInstance(); |
116 |
|
|
117 |
0 |
this.beanManager.populate(propertiesBean, properties); |
118 |
|
} catch (Exception e) { |
119 |
0 |
throw new FilterException("Failed to convert properties to Java bean", e); |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
29737 |
write(entity, filter, internalFilter, propertiesBean); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
126 |
7593 |
@Override... |
127 |
|
public void write(E entity, Object filter, P properties) throws FilterException |
128 |
|
{ |
129 |
7593 |
F internalFilter = this.filterDescriptorManager.createFilterProxy(filter, this.filterType); |
130 |
|
|
131 |
7593 |
write(entity, filter, internalFilter, properties); |
132 |
|
} |
133 |
|
|
134 |
|
protected abstract void write(E entity, Object filter, F internalFilter, P properties) throws FilterException; |
135 |
|
} |