1 16 17 package org.springframework.beans.factory.config; 18 19 import java.io.IOException ; 20 import java.util.Enumeration ; 21 import java.util.Properties ; 22 23 import org.springframework.beans.BeansException; 24 import org.springframework.beans.factory.BeanInitializationException; 25 import org.springframework.core.Ordered; 26 import org.springframework.core.io.support.PropertiesLoaderSupport; 27 import org.springframework.util.ObjectUtils; 28 29 52 public abstract class PropertyResourceConfigurer extends PropertiesLoaderSupport 53 implements BeanFactoryPostProcessor, Ordered { 54 55 private int order = Ordered.LOWEST_PRECEDENCE; 57 58 public void setOrder(int order) { 59 this.order = order; 60 } 61 62 public int getOrder() { 63 return order; 64 } 65 66 67 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 68 try { 69 Properties mergedProps = mergeProperties(); 70 71 convertProperties(mergedProps); 73 74 processProperties(beanFactory, mergedProps); 76 } 77 catch (IOException ex) { 78 throw new BeanInitializationException("Could not load properties", ex); 79 } 80 } 81 82 90 protected void convertProperties(Properties props) { 91 Enumeration propertyNames = props.propertyNames(); 92 while (propertyNames.hasMoreElements()) { 93 String propertyName = (String ) propertyNames.nextElement(); 94 String propertyValue = props.getProperty(propertyName); 95 String convertedValue = convertPropertyValue(propertyValue); 96 if (!ObjectUtils.nullSafeEquals(propertyValue, convertedValue)) { 97 props.setProperty(propertyName, convertedValue); 98 } 99 } 100 } 101 102 115 protected String convertPropertyValue(String originalValue) { 116 return originalValue; 117 } 118 119 125 protected abstract void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) 126 throws BeansException; 127 128 } 129 | Popular Tags |