1 16 17 package org.springframework.beans.factory.config; 18 19 import java.io.IOException ; 20 import java.util.Properties ; 21 22 import org.springframework.beans.factory.FactoryBean; 23 import org.springframework.beans.factory.InitializingBean; 24 import org.springframework.core.io.support.PropertiesLoaderSupport; 25 26 42 public class PropertiesFactoryBean extends PropertiesLoaderSupport 43 implements FactoryBean, InitializingBean { 44 45 private boolean singleton = true; 46 47 private Object singletonInstance; 48 49 50 54 public final void setSingleton(boolean singleton) { 55 this.singleton = singleton; 56 } 57 58 public final boolean isSingleton() { 59 return singleton; 60 } 61 62 63 public final void afterPropertiesSet() throws IOException { 64 if (this.singleton) { 65 this.singletonInstance = createInstance(); 66 } 67 } 68 69 public final Object getObject() throws IOException { 70 if (this.singleton) { 71 return this.singletonInstance; 72 } 73 else { 74 return createInstance(); 75 } 76 } 77 78 public Class getObjectType() { 79 return Properties .class; 80 } 81 82 83 93 protected Object createInstance() throws IOException { 94 return mergeProperties(); 95 } 96 97 } 98 99 | Popular Tags |