Clover Coverage Report - Kuali Spring Utilities 1.1.0-SNAPSHOT
Coverage timestamp: Thu Apr 21 2011 09:03:37 EST
../../../../img/srcFileCovDistChart8.png 13% of files have more coverage
42   126   19   2.8
6   95   0.45   15
15     1.27  
1    
 
  PropertiesPlaceholderConfigurer       Line # 16 42 0% 19 17 73% 0.73015875
 
No Tests
 
1    package org.kuali.spring.util;
2   
3    import java.util.Properties;
4   
5    import org.kuali.spring.util.event.DefaultVisitListener;
6    import org.kuali.spring.util.event.VisitListener;
7    import org.springframework.beans.factory.BeanDefinitionStoreException;
8    import org.springframework.beans.factory.config.BeanDefinition;
9    import org.springframework.beans.factory.config.BeanDefinitionVisitor;
10    import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
11    import org.springframework.util.StringValueResolver;
12   
13    /**
14    *
15    */
 
16    public class PropertiesPlaceholderConfigurer extends PlaceholderConfigurer {
17   
18    private PropertiesLoader loader = new PropertiesLoader();
19    private PropertiesConverter converter = new PropertiesConverter();
20    private PropertiesResolver resolver = new PropertiesResolver();
21    private Properties properties;
22    private String nullValue;
23   
 
24  14 toggle protected boolean currentBeanIsMe(String currentBean, ConfigurableListableBeanFactory beanFactoryToProcess) {
25  14 if (!currentBean.equals(getBeanName())) {
26  13 return false;
27    }
28  1 if (!beanFactoryToProcess.equals(getBeanFactory())) {
29  0 return false;
30    }
31  1 return true;
32    }
33   
 
34  1 toggle protected BeanDefinitionVisitor getBeanDefinitionVisitor(StringValueResolver valueResolver) {
35  1 EnhancedBeanDefinitionVisitor visitor = new EnhancedBeanDefinitionVisitor();
36  1 visitor.setValueResolver(valueResolver);
37  1 VisitListener listener = new DefaultVisitListener();
38  1 visitor.addListener(listener);
39  1 return visitor;
40    }
41   
 
42  1 toggle protected void processBeans(ConfigurableListableBeanFactory beanFactory, StringValueResolver valueResolver) {
43  1 BeanDefinitionVisitor visitor = getBeanDefinitionVisitor(valueResolver);
44  1 String[] beanNames = beanFactory.getBeanDefinitionNames();
45  1 for (String curName : beanNames) {
46    // Skip processing our own bean definition
47  14 if (currentBeanIsMe(curName, beanFactory)) {
48  1 continue;
49    }
50  13 BeanDefinition bd = beanFactory.getBeanDefinition(curName);
51  13 try {
52  13 visitor.visitBeanDefinition(bd);
53    } catch (Exception e) {
54  0 throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, e.getMessage(), e);
55    }
56    }
57    }
58   
 
59  1 toggle protected StringValueResolver getStringValueResolver() {
60  1 ValueRetriever retriever = new PropertiesRetriever(this.properties);
61  1 DefaultStringValueResolver dsvr = new DefaultStringValueResolver();
62  1 dsvr.setResolver(this.resolver);
63  1 dsvr.setNullValue(this.nullValue);
64  1 dsvr.setRetriever(retriever);
65  1 return dsvr;
66    }
67   
 
68  1 toggle @Override
69    protected void processPlaceholders(ConfigurableListableBeanFactory beanFactoryToProcess) {
70  1 this.properties = this.loader.loadProperties();
71  1 this.converter.convert(this.properties);
72  1 this.resolver.resolve(this.properties);
73   
74  1 StringValueResolver valueResolver = getStringValueResolver();
75   
76  1 processBeans(beanFactoryToProcess, valueResolver);
77   
78    // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
79  1 beanFactoryToProcess.resolveAliases(valueResolver);
80   
81    // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
82  1 beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
83   
84    }
85   
 
86  0 toggle public PropertiesLoader getLoader() {
87  0 return loader;
88    }
89   
 
90  1 toggle public void setLoader(PropertiesLoader loader) {
91  1 this.loader = loader;
92    }
93   
 
94  0 toggle public PropertiesConverter getConverter() {
95  0 return converter;
96    }
97   
 
98  1 toggle public void setConverter(PropertiesConverter converter) {
99  1 this.converter = converter;
100    }
101   
 
102  0 toggle public Properties getProperties() {
103  0 return properties;
104    }
105   
 
106  0 toggle public void setProperties(Properties properties) {
107  0 this.properties = properties;
108    }
109   
 
110  0 toggle public PropertiesResolver getResolver() {
111  0 return resolver;
112    }
113   
 
114  1 toggle public void setResolver(PropertiesResolver resolver) {
115  1 this.resolver = resolver;
116    }
117   
 
118  0 toggle public String getNullValue() {
119  0 return nullValue;
120    }
121   
 
122  0 toggle public void setNullValue(String nullValue) {
123  0 this.nullValue = nullValue;
124    }
125   
126    }