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.dialog; |
35 |
|
|
36 |
|
import org.slf4j.Logger; |
37 |
|
import org.slf4j.LoggerFactory; |
38 |
|
import org.springframework.aop.support.AopUtils; |
39 |
|
import org.springframework.beans.factory.InitializingBean; |
40 |
|
import org.springframework.util.ClassUtils; |
41 |
|
import org.springframework.util.ReflectionUtils; |
42 |
|
|
43 |
|
import info.magnolia.config.registry.DefinitionProvider; |
44 |
|
import info.magnolia.module.blossom.annotation.DialogFactory; |
45 |
|
import info.magnolia.module.blossom.annotation.PreRegister; |
46 |
|
import info.magnolia.module.blossom.support.AbstractBeanDetector; |
47 |
|
import info.magnolia.module.blossom.support.MethodInvocationUtils; |
48 |
|
import info.magnolia.module.blossom.support.ParameterResolver; |
49 |
|
import info.magnolia.objectfactory.Components; |
50 |
|
import info.magnolia.ui.dialog.definition.DialogDefinition; |
51 |
|
import info.magnolia.ui.dialog.registry.DialogDefinitionRegistry; |
52 |
|
|
53 |
|
import java.lang.reflect.Method; |
54 |
|
import java.lang.reflect.Modifier; |
55 |
|
import java.util.ArrayList; |
56 |
|
import java.util.Collections; |
57 |
|
import java.util.List; |
58 |
|
import java.util.concurrent.atomic.AtomicReference; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@see |
65 |
|
@since |
66 |
|
|
|
|
| 86.7% |
Uncovered Elements: 8 (60) |
Complexity: 20 |
Complexity Density: 0.61 |
|
67 |
|
public class DialogExporter extends AbstractBeanDetector implements InitializingBean { |
68 |
|
|
69 |
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
70 |
|
|
71 |
|
private DialogDescriptionBuilder dialogDescriptionBuilder; |
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
73 |
|
public void setDialogDescriptionBuilder(DialogDescriptionBuilder dialogDescriptionBuilder) {... |
74 |
|
this.dialogDescriptionBuilder = dialogDescriptionBuilder; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
77 |
111 |
@Override... |
78 |
|
protected boolean include(Class<?> beanType, String beanName) { |
79 |
111 |
beanType = ClassUtils.isCglibProxyClass(beanType) ? beanType.getSuperclass() : beanType; |
80 |
111 |
return beanType.isAnnotationPresent(DialogFactory.class); |
81 |
|
} |
82 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
83 |
7 |
@Override... |
84 |
|
protected void onBeanDetection(Object bean, String beanName) { |
85 |
|
|
86 |
7 |
BlossomDialogDescription dialogDescription = dialogDescriptionBuilder.buildDescription(bean); |
87 |
|
|
88 |
7 |
dialogDescription = postProcessDialogFactoryDialog(dialogDescription); |
89 |
7 |
if (dialogDescription == null) { |
90 |
1 |
return; |
91 |
|
} |
92 |
|
|
93 |
6 |
Components.getComponent(DialogDefinitionRegistry.class).register(createDialogDefinitionProvider(dialogDescription)); |
94 |
|
|
95 |
6 |
if (logger.isDebugEnabled()) { |
96 |
0 |
logger.debug("Registered dialog [" + dialogDescription.getId() + "]"); |
97 |
|
} |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
2 |
protected DefinitionProvider<DialogDefinition> createDialogDefinitionProvider(BlossomDialogDescription dialogDescription) {... |
101 |
2 |
return new BlossomDialogDefinitionProvider(dialogDescription); |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
108 |
7 |
protected BlossomDialogDescription postProcessDialogFactoryDialog(final BlossomDialogDescription dialogDescription) {... |
109 |
|
|
110 |
7 |
Object factoryObject = dialogDescription.getFactoryMetaData().getFactoryObject(); |
111 |
|
|
112 |
7 |
final Class<?> factoryClass = AopUtils.getTargetClass(factoryObject); |
113 |
|
|
114 |
7 |
final List<Method> matchingMethods = new ArrayList<Method>(); |
115 |
|
|
116 |
7 |
ReflectionUtils.doWithMethods(factoryClass, new ReflectionUtils.MethodCallback() { |
117 |
|
|
|
|
| 72.7% |
Uncovered Elements: 3 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
118 |
90 |
@Override... |
119 |
|
public void doWith(Method method) { |
120 |
90 |
if (method.isAnnotationPresent(PreRegister.class) && method.equals(ClassUtils.getMostSpecificMethod(method, factoryClass))) { |
121 |
4 |
if (Modifier.isStatic(method.getModifiers())) { |
122 |
0 |
throw new IllegalStateException("PreRegister annotation is not supported on static methods"); |
123 |
|
} |
124 |
4 |
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(BlossomDialogDescription.class)) { |
125 |
4 |
matchingMethods.add(method); |
126 |
|
} |
127 |
|
} |
128 |
|
} |
129 |
|
}); |
130 |
7 |
Collections.reverse(matchingMethods); |
131 |
|
|
132 |
7 |
final AtomicReference<BlossomDialogDescription> reference = new AtomicReference<BlossomDialogDescription>(dialogDescription); |
133 |
7 |
for (Method matchingMethod : matchingMethods) { |
134 |
4 |
Object returnValue = MethodInvocationUtils.invoke(matchingMethod, factoryObject, new ParameterResolver() { |
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
135 |
4 |
@Override... |
136 |
|
public Object resolveParameter(Class<?> parameterType) { |
137 |
4 |
if (parameterType.isAssignableFrom(BlossomDialogDescription.class)) { |
138 |
4 |
return reference.get(); |
139 |
|
} |
140 |
0 |
return super.resolveParameter(parameterType); |
141 |
|
} |
142 |
|
}); |
143 |
4 |
if (returnValue == null && !matchingMethod.getReturnType().equals(Void.TYPE)) { |
144 |
1 |
return null; |
145 |
|
} |
146 |
3 |
if (returnValue instanceof BlossomDialogDescription) { |
147 |
2 |
reference.set((BlossomDialogDescription) returnValue); |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
6 |
return reference.get(); |
152 |
|
} |
153 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
154 |
8 |
@Override... |
155 |
|
public void afterPropertiesSet() throws Exception { |
156 |
8 |
if (dialogDescriptionBuilder == null) { |
157 |
8 |
dialogDescriptionBuilder = new DialogDescriptionBuilder(); |
158 |
|
} |
159 |
|
} |
160 |
|
} |