1 | package fr.sii.ogham.spring.template.freemarker; | |
2 | ||
3 | import org.springframework.context.ApplicationContext; | |
4 | ||
5 | import freemarker.ext.beans.BeanModel; | |
6 | import freemarker.ext.beans.BeansWrapper; | |
7 | import freemarker.template.TemplateHashModel; | |
8 | import freemarker.template.TemplateModel; | |
9 | import freemarker.template.TemplateModelException; | |
10 | ||
11 | /** | |
12 | * Wrapper that provides a {@link BeanModel} only when trying to call to a | |
13 | * method of a bean. | |
14 | * | |
15 | * @author Aurélien Baudet | |
16 | * | |
17 | */ | |
18 | public class LazySpringBeanAccessModel implements TemplateHashModel { | |
19 | private final ApplicationContext applicationContext; | |
20 | private final BeansWrapper beansWrapper; | |
21 | private final String name; | |
22 | private BeanModel cached; | |
23 | ||
24 | public LazySpringBeanAccessModel(ApplicationContext applicationContext, BeansWrapper beansWrapper, String name) { | |
25 | super(); | |
26 | this.applicationContext = applicationContext; | |
27 | this.beansWrapper = beansWrapper; | |
28 | this.name = name; | |
29 | } | |
30 | ||
31 | @Override | |
32 | public TemplateModel get(String key) throws TemplateModelException { | |
33 |
2
1. get : replaced return value with null for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::get → KILLED 2. get : replaced return value with null for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::get → KILLED |
return getBeanModel().get(key); |
34 | } | |
35 | ||
36 | @Override | |
37 | public boolean isEmpty() throws TemplateModelException { | |
38 |
2
1. isEmpty : replaced boolean return with false for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::isEmpty → NO_COVERAGE 2. isEmpty : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::isEmpty → NO_COVERAGE |
return getBeanModel().isEmpty(); |
39 | } | |
40 | ||
41 | private BeanModel getBeanModel() { | |
42 |
2
1. getBeanModel : negated conditional → KILLED 2. getBeanModel : negated conditional → KILLED |
if (cached == null) { |
43 | cached = new BeanModel(applicationContext.getBean(name), beansWrapper); | |
44 | } | |
45 |
2
1. getBeanModel : replaced return value with null for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::getBeanModel → KILLED 2. getBeanModel : replaced return value with null for fr/sii/ogham/spring/template/freemarker/LazySpringBeanAccessModel::getBeanModel → KILLED |
return cached; |
46 | } | |
47 | } | |
Mutations | ||
33 |
1.1 2.2 |
|
38 |
1.1 2.2 |
|
42 |
1.1 2.2 |
|
45 |
1.1 2.2 |