1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring;
17
18 import java.util.Properties;
19
20 import org.kuali.common.util.property.DefaultPropertyLoadContext;
21 import org.kuali.common.util.service.DefaultPropertyService;
22 import org.kuali.common.util.service.PropertyService;
23 import org.springframework.beans.factory.FactoryBean;
24
25 public class PropertyFactoryBean extends DefaultPropertyLoadContext implements FactoryBean<Properties> {
26
27 protected static Properties properties;
28 boolean singleton = true;
29 PropertyService service = new DefaultPropertyService();
30
31 @Override
32 public Properties getObject() throws Exception {
33 if (isSingleton()) {
34 return getInstance();
35 } else {
36 return service.load(this);
37 }
38 }
39
40 protected synchronized Properties getInstance() {
41 if (properties == null) {
42 properties = service.load(this);
43 }
44 return properties;
45 }
46
47 @Override
48 public Class<Properties> getObjectType() {
49 return Properties.class;
50 }
51
52 @Override
53 public boolean isSingleton() {
54 return this.singleton;
55 }
56
57 public void setSingleton(boolean singleton) {
58 this.singleton = singleton;
59 }
60
61 public PropertyService getService() {
62 return service;
63 }
64
65 public void setService(PropertyService service) {
66 this.service = service;
67 }
68 }