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.template; |
35 |
|
|
36 |
|
import java.lang.annotation.Annotation; |
37 |
|
import java.lang.reflect.Method; |
38 |
|
import java.lang.reflect.Modifier; |
39 |
|
import java.util.ArrayList; |
40 |
|
import java.util.Collection; |
41 |
|
import java.util.Collections; |
42 |
|
import java.util.HashSet; |
43 |
|
import java.util.List; |
44 |
|
import java.util.Map; |
45 |
|
import java.util.Set; |
46 |
|
import java.util.concurrent.atomic.AtomicReference; |
47 |
|
|
48 |
|
import org.apache.commons.lang.StringUtils; |
49 |
|
import org.slf4j.Logger; |
50 |
|
import org.slf4j.LoggerFactory; |
51 |
|
import org.springframework.aop.support.AopUtils; |
52 |
|
import org.springframework.beans.BeansException; |
53 |
|
import org.springframework.beans.factory.InitializingBean; |
54 |
|
import org.springframework.beans.factory.config.BeanPostProcessor; |
55 |
|
import org.springframework.context.ApplicationEvent; |
56 |
|
import org.springframework.context.ApplicationListener; |
57 |
|
import org.springframework.util.ClassUtils; |
58 |
|
import org.springframework.util.ReflectionUtils; |
59 |
|
import org.springframework.web.method.HandlerMethod; |
60 |
|
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping; |
61 |
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
62 |
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; |
63 |
|
|
64 |
|
import info.magnolia.config.registry.DefinitionProvider; |
65 |
|
import info.magnolia.module.blossom.annotation.Area; |
66 |
|
import info.magnolia.module.blossom.annotation.ComponentCategory; |
67 |
|
import info.magnolia.module.blossom.annotation.PreRegister; |
68 |
|
import info.magnolia.module.blossom.annotation.Template; |
69 |
|
import info.magnolia.module.blossom.dialog.BlossomDialogDefinitionProvider; |
70 |
|
import info.magnolia.module.blossom.dialog.BlossomDialogDescription; |
71 |
|
import info.magnolia.module.blossom.dialog.DialogDescriptionBuilder; |
72 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
73 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherAware; |
74 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent; |
75 |
|
import info.magnolia.module.blossom.support.MethodInvocationUtils; |
76 |
|
import info.magnolia.module.blossom.support.ParameterResolver; |
77 |
|
import info.magnolia.objectfactory.Components; |
78 |
|
import info.magnolia.rendering.template.AreaDefinition; |
79 |
|
import info.magnolia.rendering.template.TemplateDefinition; |
80 |
|
import info.magnolia.rendering.template.registry.TemplateDefinitionRegistry; |
81 |
|
import info.magnolia.ui.dialog.definition.DialogDefinition; |
82 |
|
import info.magnolia.ui.dialog.registry.DialogDefinitionRegistry; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@since |
88 |
|
|
|
|
| 77.2% |
Uncovered Elements: 81 (356) |
Complexity: 99 |
Complexity Density: 0.46 |
|
89 |
|
public class TemplateExporter implements BeanPostProcessor, InitializingBean, ApplicationListener, BlossomDispatcherAware { |
90 |
|
|
91 |
|
private static final String TEMPLATE_DIALOG_PREFIX = "blossom-template-dialog:"; |
92 |
|
private static final String AREA_DIALOG_PREFIX = "blossom-area-dialog:"; |
93 |
|
|
94 |
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
95 |
|
|
96 |
|
private BlossomDispatcher dispatcher; |
97 |
|
private TemplateDefinitionBuilder templateDefinitionBuilder; |
98 |
|
private DialogDescriptionBuilder dialogDescriptionBuilder; |
99 |
|
|
100 |
|
private DetectedHandlersMetaData detectedHandlers = new DetectedHandlersMetaData(); |
101 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
102 |
|
public void setTemplateDefinitionBuilder(TemplateDefinitionBuilder templateDefinitionBuilder) {... |
103 |
|
this.templateDefinitionBuilder = templateDefinitionBuilder; |
104 |
|
} |
105 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
106 |
|
public void setDialogDescriptionBuilder(DialogDescriptionBuilder dialogDescriptionBuilder) {... |
107 |
|
this.dialogDescriptionBuilder = dialogDescriptionBuilder; |
108 |
|
} |
109 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
110 |
|
@Override... |
111 |
|
public void setBlossomDispatcher(BlossomDispatcher dispatcher) { |
112 |
|
this.dispatcher = dispatcher; |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
60 |
@Override... |
116 |
|
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
117 |
60 |
return bean; |
118 |
|
} |
119 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
120 |
64 |
@Override... |
121 |
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
122 |
64 |
if (bean instanceof AbstractUrlHandlerMapping) { |
123 |
10 |
scanHandlerMapping((AbstractUrlHandlerMapping) bean); |
124 |
|
} |
125 |
64 |
if (bean instanceof RequestMappingInfoHandlerMapping) { |
126 |
0 |
scanHandlerMapping((RequestMappingInfoHandlerMapping) bean); |
127 |
|
} |
128 |
64 |
return bean; |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
131 |
10 |
protected void scanHandlerMapping(AbstractUrlHandlerMapping handlerMapping) {... |
132 |
10 |
for (Object object : handlerMapping.getHandlerMap().entrySet()) { |
133 |
|
|
134 |
13 |
Map.Entry entry = (Map.Entry) object; |
135 |
13 |
String handlerPath = (String) entry.getKey(); |
136 |
13 |
Object handler = entry.getValue(); |
137 |
|
|
138 |
13 |
postProcessHandler(handler, handlerPath); |
139 |
|
} |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
142 |
0 |
private void scanHandlerMapping(RequestMappingInfoHandlerMapping handlerMapping) {... |
143 |
|
|
144 |
0 |
Map<RequestMappingInfo,HandlerMethod> handlerMethods = handlerMapping.getHandlerMethods(); |
145 |
0 |
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()) { |
146 |
|
|
147 |
0 |
RequestMappingInfo requestMappingInfo = entry.getKey(); |
148 |
0 |
HandlerMethod handlerMethod = entry.getValue(); |
149 |
|
|
150 |
0 |
Set<String> patterns = requestMappingInfo.getPatternsCondition().getPatterns(); |
151 |
0 |
if (!patterns.isEmpty()) { |
152 |
0 |
String pattern = patterns.iterator().next(); |
153 |
0 |
postProcessHandler(handlerMethod.createWithResolvedBean().getBean(), pattern); |
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
158 |
13 |
protected void postProcessHandler(Object handler, String handlerPath) {... |
159 |
13 |
Class<?> handlerClass = AopUtils.getTargetClass(handler); |
160 |
13 |
if (handlerClass.isAnnotationPresent(Area.class)) { |
161 |
3 |
detectedHandlers.addArea(new HandlerMetaData(handler, handlerPath, handlerClass)); |
162 |
10 |
} else if (handlerClass.isAnnotationPresent(Template.class)) { |
163 |
10 |
detectedHandlers.addTemplate(new HandlerMetaData(handler, handlerPath, handlerClass)); |
164 |
10 |
String templateId = resolveTemplateId(handlerClass); |
165 |
10 |
if (isComponent(templateId)) { |
166 |
1 |
List<Class<? extends Annotation>> categories = findAllAnnotationsMetaAnnotatedWith(handlerClass, ComponentCategory.class); |
167 |
1 |
detectedHandlers.addCategories(templateId, categories); |
168 |
|
} |
169 |
|
} |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
172 |
13 |
@Override... |
173 |
|
public void onApplicationEvent(ApplicationEvent event) { |
174 |
13 |
if (event instanceof BlossomDispatcherInitializedEvent && event.getSource() == dispatcher) { |
175 |
7 |
exportTemplates(); |
176 |
|
} |
177 |
|
} |
178 |
|
|
|
|
| 85% |
Uncovered Elements: 6 (40) |
Complexity: 8 |
Complexity Density: 0.31 |
|
179 |
7 |
protected void exportTemplates() {... |
180 |
|
|
181 |
7 |
Set<String> registeredIds = new HashSet<>(); |
182 |
7 |
for (HandlerMetaData template : detectedHandlers.getTemplates()) { |
183 |
|
|
184 |
10 |
BlossomTemplateDefinition definition = templateDefinitionBuilder.buildTemplateDefinition(dispatcher, detectedHandlers, template); |
185 |
|
|
186 |
|
|
187 |
10 |
if (registeredIds.contains(definition.getId())) { |
188 |
0 |
continue; |
189 |
|
} |
190 |
10 |
registeredIds.add(definition.getId()); |
191 |
|
|
192 |
10 |
definition = postProcessTemplateDefinition(definition); |
193 |
10 |
if (definition == null) { |
194 |
1 |
continue; |
195 |
|
} |
196 |
|
|
197 |
9 |
Components.getComponent(TemplateDefinitionRegistry.class).register(createTemplateDefinitionProvider(definition)); |
198 |
|
|
199 |
9 |
if (logger.isDebugEnabled()) { |
200 |
0 |
logger.debug("Registered template [" + template.getHandlerClass() + "] with id [" + definition.getId() + "]"); |
201 |
|
} |
202 |
|
|
203 |
9 |
template.setTemplateDefinition(definition); |
204 |
|
|
205 |
9 |
if (StringUtils.isEmpty(definition.getDialog())) { |
206 |
9 |
registerTemplateDialog(definition); |
207 |
|
} |
208 |
|
|
209 |
9 |
registerDialogFactories(definition); |
210 |
|
|
211 |
9 |
registerAreaDialogs(definition.getAreas().values()); |
212 |
|
} |
213 |
|
|
214 |
7 |
if (logger.isInfoEnabled()) { |
215 |
7 |
StringBuilder sb = new StringBuilder(); |
216 |
7 |
for (HandlerMetaData template : detectedHandlers.getTemplates()) { |
217 |
10 |
if (template.getTemplateDefinition() != null) { |
218 |
9 |
if (sb.length() != 0) { |
219 |
3 |
sb.append(","); |
220 |
|
} |
221 |
9 |
sb.append(template.getTemplateDefinition().getId()); |
222 |
|
} |
223 |
|
} |
224 |
7 |
logger.info("Registered templates [" + sb.toString() + "]"); |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
7 |
detectedHandlers = null; |
229 |
|
} |
230 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
231 |
9 |
protected void registerDialogFactories(BlossomTemplateDefinition templateDefinition) {... |
232 |
|
|
233 |
9 |
List<BlossomDialogDescription> dialogDescriptions = dialogDescriptionBuilder.buildDescriptions(templateDefinition.getHandler()); |
234 |
|
|
235 |
9 |
for (BlossomDialogDescription dialogDescription : dialogDescriptions) { |
236 |
|
|
237 |
2 |
dialogDescription = postProcessDialogFactoryDialog(templateDefinition, dialogDescription); |
238 |
2 |
if (dialogDescription == null) { |
239 |
0 |
continue; |
240 |
|
} |
241 |
|
|
242 |
2 |
Components.getComponent(DialogDefinitionRegistry.class).register(createDialogDefinitionProvider(dialogDescription)); |
243 |
|
|
244 |
2 |
if (logger.isDebugEnabled()) { |
245 |
0 |
logger.debug("Registered dialog factory within template [" + templateDefinition.getId() + "] with id [" + dialogDescription.getId() + "]"); |
246 |
|
} |
247 |
|
} |
248 |
|
} |
249 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
250 |
9 |
protected void registerTemplateDialog(BlossomTemplateDefinition templateDefinition) {... |
251 |
|
|
252 |
9 |
String templateId = templateDefinition.getId(); |
253 |
|
|
254 |
9 |
String dialogId = TEMPLATE_DIALOG_PREFIX + AopUtils.getTargetClass(templateDefinition.getHandler()).getName(); |
255 |
|
|
256 |
9 |
BlossomDialogDescription dialogDescription = dialogDescriptionBuilder.buildDescription(dialogId, templateDefinition.getTitle(), templateDefinition.getHandler()); |
257 |
|
|
258 |
9 |
if (dialogDescription.getFactoryMetaData().isEmpty()) { |
259 |
6 |
return; |
260 |
|
} |
261 |
|
|
262 |
3 |
dialogDescription = postProcessTemplateDialog(templateDefinition, dialogDescription); |
263 |
3 |
if (dialogDescription == null) { |
264 |
0 |
return; |
265 |
|
} |
266 |
|
|
267 |
3 |
Components.getComponent(DialogDefinitionRegistry.class).register(createDialogDefinitionProvider(dialogDescription)); |
268 |
|
|
269 |
3 |
templateDefinition.setDialog(dialogId); |
270 |
|
|
271 |
3 |
if (logger.isDebugEnabled()) { |
272 |
0 |
logger.debug("Registered dialog for template [" + templateId + "] with id [" + dialogId + "]"); |
273 |
|
} |
274 |
|
} |
275 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
276 |
12 |
protected void registerAreaDialogs(Collection<AreaDefinition> areas) {... |
277 |
12 |
for (AreaDefinition areaDefinition : areas) { |
278 |
3 |
if (StringUtils.isEmpty(areaDefinition.getDialog())) { |
279 |
3 |
registerAreaDialog((BlossomAreaDefinition) areaDefinition); |
280 |
|
} |
281 |
3 |
registerAreaDialogs(areaDefinition.getAreas().values()); |
282 |
|
} |
283 |
|
} |
284 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
285 |
3 |
protected void registerAreaDialog(BlossomAreaDefinition areaDefinition) {... |
286 |
|
|
287 |
3 |
String areaName = areaDefinition.getName(); |
288 |
|
|
289 |
3 |
String dialogId = AREA_DIALOG_PREFIX + AopUtils.getTargetClass(areaDefinition.getHandler()).getName(); |
290 |
|
|
291 |
3 |
BlossomDialogDescription dialogDescription = dialogDescriptionBuilder.buildDescription(dialogId, areaDefinition.getTitle(), areaDefinition.getHandler()); |
292 |
|
|
293 |
3 |
if (dialogDescription.getFactoryMetaData().isEmpty()) { |
294 |
2 |
return; |
295 |
|
} |
296 |
|
|
297 |
1 |
dialogDescription = postProcessAreaDialog(areaDefinition, dialogDescription); |
298 |
1 |
if (dialogDescription == null) { |
299 |
0 |
return; |
300 |
|
} |
301 |
|
|
302 |
1 |
Components.getComponent(DialogDefinitionRegistry.class).register(createDialogDefinitionProvider(dialogDescription)); |
303 |
|
|
304 |
1 |
areaDefinition.setDialog(dialogId); |
305 |
|
|
306 |
1 |
if (logger.isDebugEnabled()) { |
307 |
0 |
logger.debug("Registered dialog for area [" + areaName + "] with id [" + dialogId + "]"); |
308 |
|
} |
309 |
|
} |
310 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
311 |
7 |
@Override... |
312 |
|
public void afterPropertiesSet() throws Exception { |
313 |
7 |
if (templateDefinitionBuilder == null) { |
314 |
7 |
templateDefinitionBuilder = new TemplateDefinitionBuilder(); |
315 |
|
} |
316 |
7 |
if (dialogDescriptionBuilder == null) { |
317 |
7 |
dialogDescriptionBuilder = new DialogDescriptionBuilder(); |
318 |
|
} |
319 |
|
} |
320 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
321 |
9 |
protected DefinitionProvider<TemplateDefinition> createTemplateDefinitionProvider(BlossomTemplateDefinition definition) {... |
322 |
9 |
return new BlossomTemplateDefinitionProvider(definition); |
323 |
|
} |
324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
325 |
6 |
protected DefinitionProvider<DialogDefinition> createDialogDefinitionProvider(BlossomDialogDescription dialogDescription) {... |
326 |
6 |
return new BlossomDialogDefinitionProvider(dialogDescription); |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.29 |
|
333 |
10 |
protected BlossomTemplateDefinition postProcessTemplateDefinition(final BlossomTemplateDefinition templateDefinition) {... |
334 |
|
|
335 |
10 |
templateDefinition.setAreas(postProcessAreaDefinitions(templateDefinition, templateDefinition.getAreas())); |
336 |
|
|
337 |
10 |
Object handler = templateDefinition.getHandler(); |
338 |
|
|
339 |
10 |
final Class<?> factoryClass = AopUtils.getTargetClass(handler); |
340 |
|
|
341 |
10 |
final List<Method> matchingMethods = new ArrayList<Method>(); |
342 |
|
|
343 |
10 |
ReflectionUtils.doWithMethods(factoryClass, new ReflectionUtils.MethodCallback() { |
344 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
345 |
144 |
@Override... |
346 |
|
public void doWith(Method method) { |
347 |
144 |
if (method.isAnnotationPresent(PreRegister.class) && method.equals(ClassUtils.getMostSpecificMethod(method, factoryClass))) { |
348 |
3 |
if (Modifier.isStatic(method.getModifiers())) { |
349 |
0 |
throw new IllegalStateException("PreRegister annotation is not supported on static methods"); |
350 |
|
} |
351 |
3 |
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(BlossomTemplateDefinition.class)) { |
352 |
2 |
matchingMethods.add(method); |
353 |
|
} |
354 |
|
} |
355 |
|
} |
356 |
|
}); |
357 |
10 |
Collections.reverse(matchingMethods); |
358 |
|
|
359 |
10 |
final AtomicReference<BlossomTemplateDefinition> reference = new AtomicReference<BlossomTemplateDefinition>(templateDefinition); |
360 |
10 |
for (Method matchingMethod : matchingMethods) { |
361 |
2 |
Object returnValue = MethodInvocationUtils.invoke(matchingMethod, handler, new ParameterResolver() { |
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
362 |
2 |
@Override... |
363 |
|
public Object resolveParameter(Class<?> parameterType) { |
364 |
2 |
if (parameterType.isAssignableFrom(BlossomTemplateDefinition.class)) { |
365 |
2 |
return reference.get(); |
366 |
|
} |
367 |
0 |
return super.resolveParameter(parameterType); |
368 |
|
} |
369 |
|
}); |
370 |
2 |
if (returnValue == null && !matchingMethod.getReturnType().equals(Void.TYPE)) { |
371 |
1 |
return null; |
372 |
|
} |
373 |
1 |
if (returnValue instanceof BlossomTemplateDefinition) { |
374 |
0 |
reference.set((BlossomTemplateDefinition) returnValue); |
375 |
|
} |
376 |
|
} |
377 |
|
|
378 |
9 |
return reference.get(); |
379 |
|
} |
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
384 |
13 |
protected Map<String, AreaDefinition> postProcessAreaDefinitions(BlossomTemplateDefinition templateDefinition, Map<String, AreaDefinition> areas) {... |
385 |
|
|
386 |
13 |
for (String areaName : areas.keySet()) { |
387 |
|
|
388 |
3 |
BlossomAreaDefinition areaDefinition = (BlossomAreaDefinition) areas.get(areaName); |
389 |
3 |
areaDefinition.setAreas(postProcessAreaDefinitions(templateDefinition, areaDefinition.getAreas())); |
390 |
|
|
391 |
3 |
areaDefinition = postProcessAreaDefinition(templateDefinition, areaDefinition); |
392 |
3 |
if (areaDefinition == null) { |
393 |
0 |
areas.remove(areaName); |
394 |
|
} else { |
395 |
3 |
areas.put(areaName, areaDefinition); |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
13 |
return areas; |
400 |
|
} |
401 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
402 |
3 |
protected BlossomAreaDefinition postProcessAreaDefinition(final BlossomTemplateDefinition templateDefinition, BlossomAreaDefinition areaDefinition) {... |
403 |
|
|
404 |
3 |
Object handler = areaDefinition.getHandler(); |
405 |
|
|
406 |
3 |
final Class<?> factoryClass = AopUtils.getTargetClass(handler); |
407 |
|
|
408 |
3 |
final List<Method> matchingMethods = new ArrayList<Method>(); |
409 |
|
|
410 |
3 |
ReflectionUtils.doWithMethods(factoryClass, new ReflectionUtils.MethodCallback() { |
411 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
412 |
44 |
@Override... |
413 |
|
public void doWith(Method method) { |
414 |
44 |
if (method.isAnnotationPresent(PreRegister.class) && method.equals(ClassUtils.getMostSpecificMethod(method, factoryClass))) { |
415 |
4 |
if (Modifier.isStatic(method.getModifiers())) { |
416 |
0 |
throw new IllegalStateException("PreRegister annotation is not supported on static methods"); |
417 |
|
} |
418 |
4 |
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(BlossomAreaDefinition.class)) { |
419 |
2 |
matchingMethods.add(method); |
420 |
|
} |
421 |
|
} |
422 |
|
} |
423 |
|
}); |
424 |
3 |
Collections.reverse(matchingMethods); |
425 |
|
|
426 |
3 |
final AtomicReference<BlossomAreaDefinition> reference = new AtomicReference<BlossomAreaDefinition>(areaDefinition); |
427 |
3 |
for (Method matchingMethod : matchingMethods) { |
428 |
2 |
Object returnValue = MethodInvocationUtils.invoke(matchingMethod, handler, new ParameterResolver() { |
|
|
| 33.3% |
Uncovered Elements: 6 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
429 |
2 |
@Override... |
430 |
|
public Object resolveParameter(Class<?> parameterType) { |
431 |
2 |
if (parameterType.isAssignableFrom(BlossomAreaDefinition.class)) { |
432 |
2 |
return reference.get(); |
433 |
|
} |
434 |
0 |
if (parameterType.isAssignableFrom(BlossomTemplateDefinition.class)) { |
435 |
0 |
return templateDefinition; |
436 |
|
} |
437 |
0 |
return super.resolveParameter(parameterType); |
438 |
|
} |
439 |
|
}); |
440 |
2 |
if (returnValue == null && !matchingMethod.getReturnType().equals(Void.TYPE)) { |
441 |
0 |
return null; |
442 |
|
} |
443 |
2 |
if (returnValue instanceof BlossomAreaDefinition) { |
444 |
0 |
reference.set((BlossomAreaDefinition) returnValue); |
445 |
|
} |
446 |
|
} |
447 |
|
|
448 |
3 |
return reference.get(); |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
455 |
2 |
protected BlossomDialogDescription postProcessDialogFactoryDialog(BlossomTemplateDefinition templateDefinition, BlossomDialogDescription dialogDescription) {... |
456 |
2 |
return dialogDescription; |
457 |
|
} |
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
463 |
3 |
protected BlossomDialogDescription postProcessTemplateDialog(final BlossomTemplateDefinition templateDefinition, final BlossomDialogDescription dialogDescription) {... |
464 |
3 |
Object factoryObject = dialogDescription.getFactoryMetaData().getFactoryObject(); |
465 |
|
|
466 |
3 |
final Class<?> factoryClass = AopUtils.getTargetClass(factoryObject); |
467 |
|
|
468 |
3 |
final List<Method> matchingMethods = new ArrayList<Method>(); |
469 |
|
|
470 |
3 |
ReflectionUtils.doWithMethods(factoryClass, new ReflectionUtils.MethodCallback() { |
471 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
472 |
46 |
@Override... |
473 |
|
public void doWith(Method method) { |
474 |
46 |
if (method.isAnnotationPresent(PreRegister.class) && method.equals(ClassUtils.getMostSpecificMethod(method, factoryClass))) { |
475 |
2 |
if (Modifier.isStatic(method.getModifiers())) { |
476 |
0 |
throw new IllegalStateException("PreRegister annotation is not supported on static methods"); |
477 |
|
} |
478 |
2 |
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(BlossomDialogDescription.class)) { |
479 |
1 |
matchingMethods.add(method); |
480 |
|
} |
481 |
|
} |
482 |
|
} |
483 |
|
}); |
484 |
3 |
Collections.reverse(matchingMethods); |
485 |
|
|
486 |
3 |
final AtomicReference<BlossomDialogDescription> reference = new AtomicReference<BlossomDialogDescription>(dialogDescription); |
487 |
3 |
for (Method matchingMethod : matchingMethods) { |
488 |
1 |
Object returnValue = MethodInvocationUtils.invoke(matchingMethod, factoryObject, new ParameterResolver() { |
|
|
| 33.3% |
Uncovered Elements: 6 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
489 |
1 |
@Override... |
490 |
|
public Object resolveParameter(Class<?> parameterType) { |
491 |
1 |
if (parameterType.isAssignableFrom(BlossomDialogDescription.class)) { |
492 |
1 |
return reference.get(); |
493 |
|
} |
494 |
0 |
if (parameterType.isAssignableFrom(BlossomTemplateDefinition.class)) { |
495 |
0 |
return templateDefinition; |
496 |
|
} |
497 |
0 |
return super.resolveParameter(parameterType); |
498 |
|
} |
499 |
|
}); |
500 |
1 |
if (returnValue == null && !matchingMethod.getReturnType().equals(Void.TYPE)) { |
501 |
0 |
return null; |
502 |
|
} |
503 |
1 |
if (returnValue instanceof BlossomDialogDescription) { |
504 |
0 |
reference.set((BlossomDialogDescription) returnValue); |
505 |
|
} |
506 |
|
} |
507 |
|
|
508 |
3 |
return reference.get(); |
509 |
|
} |
510 |
|
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
515 |
1 |
protected BlossomDialogDescription postProcessAreaDialog(final BlossomAreaDefinition areaDefinition, final BlossomDialogDescription dialogDescription) {... |
516 |
|
|
517 |
1 |
Object factoryObject = dialogDescription.getFactoryMetaData().getFactoryObject(); |
518 |
|
|
519 |
1 |
final Class<?> factoryClass = AopUtils.getTargetClass(factoryObject); |
520 |
|
|
521 |
1 |
final List<Method> matchingMethods = new ArrayList<Method>(); |
522 |
|
|
523 |
1 |
ReflectionUtils.doWithMethods(factoryClass, new ReflectionUtils.MethodCallback() { |
524 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
525 |
18 |
@Override... |
526 |
|
public void doWith(Method method) { |
527 |
18 |
if (method.isAnnotationPresent(PreRegister.class) && method.equals(ClassUtils.getMostSpecificMethod(method, factoryClass))) { |
528 |
4 |
if (Modifier.isStatic(method.getModifiers())) { |
529 |
0 |
throw new IllegalStateException("PreRegister annotation is not supported on static methods"); |
530 |
|
} |
531 |
4 |
if (method.getParameterTypes().length >= 1 && method.getParameterTypes()[0].isAssignableFrom(BlossomDialogDescription.class)) { |
532 |
2 |
matchingMethods.add(method); |
533 |
|
} |
534 |
|
} |
535 |
|
} |
536 |
|
}); |
537 |
1 |
Collections.reverse(matchingMethods); |
538 |
|
|
539 |
1 |
final AtomicReference<BlossomDialogDescription> reference = new AtomicReference<BlossomDialogDescription>(dialogDescription); |
540 |
1 |
for (Method matchingMethod : matchingMethods) { |
541 |
2 |
Object returnValue = MethodInvocationUtils.invoke(matchingMethod, factoryObject, new ParameterResolver() { |
|
|
| 33.3% |
Uncovered Elements: 6 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
542 |
2 |
@Override... |
543 |
|
public Object resolveParameter(Class<?> parameterType) { |
544 |
2 |
if (parameterType.isAssignableFrom(BlossomDialogDescription.class)) { |
545 |
2 |
return reference.get(); |
546 |
|
} |
547 |
0 |
if (parameterType.isAssignableFrom(BlossomAreaDefinition.class)) { |
548 |
0 |
return areaDefinition; |
549 |
|
} |
550 |
0 |
return super.resolveParameter(parameterType); |
551 |
|
} |
552 |
|
}); |
553 |
2 |
if (returnValue == null && !matchingMethod.getReturnType().equals(Void.TYPE)) { |
554 |
0 |
return null; |
555 |
|
} |
556 |
2 |
if (returnValue instanceof BlossomDialogDescription) { |
557 |
0 |
reference.set((BlossomDialogDescription) returnValue); |
558 |
|
} |
559 |
|
} |
560 |
|
|
561 |
1 |
return reference.get(); |
562 |
|
} |
563 |
|
|
564 |
|
|
565 |
|
|
566 |
|
|
567 |
|
@param |
568 |
|
@return |
569 |
|
@throws |
570 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
571 |
10 |
private String resolveTemplateId(Class<?> handlerClass) {... |
572 |
10 |
Template annotation = handlerClass.getAnnotation(Template.class); |
573 |
10 |
if (annotation == null) { |
574 |
0 |
throw new IllegalArgumentException("Could not resolve template id, @Template is not present on class [" + handlerClass.getName() + "]"); |
575 |
|
} |
576 |
10 |
return annotation.id(); |
577 |
|
} |
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
@param |
583 |
|
@param |
584 |
|
@return |
585 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
586 |
1 |
private List<Class<? extends Annotation>> findAllAnnotationsMetaAnnotatedWith(Class<?> clazz, Class<? extends Annotation> targetAnnotationType) {... |
587 |
1 |
List<Class<? extends Annotation>> annotationsWithMetaAnnotations = new ArrayList<Class<? extends Annotation>>(); |
588 |
1 |
Annotation[] annotations = clazz.getAnnotations(); |
589 |
1 |
for (Annotation annotation : annotations) { |
590 |
3 |
Class<? extends Annotation> annotationType = annotation.annotationType(); |
591 |
3 |
Annotation[] metaAnnotations = annotationType.getAnnotations(); |
592 |
3 |
for (Annotation metaAnnotation : metaAnnotations) { |
593 |
9 |
Class<? extends Annotation> metaAnnotationType = metaAnnotation.annotationType(); |
594 |
9 |
if (metaAnnotationType.equals(targetAnnotationType)) { |
595 |
1 |
annotationsWithMetaAnnotations.add(annotationType); |
596 |
|
} |
597 |
|
} |
598 |
|
} |
599 |
1 |
return annotationsWithMetaAnnotations; |
600 |
|
} |
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
@param |
606 |
|
@return |
607 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
608 |
10 |
private boolean isComponent(String templateId) {... |
609 |
10 |
String path = StringUtils.substringAfter(templateId, ":"); |
610 |
10 |
path = StringUtils.removeStart(path, "/"); |
611 |
10 |
return path.startsWith("components/"); |
612 |
|
} |
613 |
|
} |