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.PropertyUtils;
21 import org.kuali.common.util.property.DefaultPropertyLoadContext;
22 import org.kuali.common.util.service.DefaultPropertyService;
23 import org.kuali.common.util.service.PropertyService;
24 import org.springframework.beans.factory.FactoryBean;
25
26 public class PropertyFactoryBean extends DefaultPropertyLoadContext implements FactoryBean<Properties> {
27
28 protected static Properties instance;
29 boolean singleton = false;
30 PropertyService service = new DefaultPropertyService();
31 boolean show;
32
33 @Override
34 public Properties getObject() throws Exception {
35 if (isSingleton()) {
36 return getInstance();
37 } else {
38 Properties properties = service.load(this);
39 if (show) {
40 PropertyUtils.info(properties);
41 }
42 return properties;
43 }
44 }
45
46 protected synchronized Properties getInstance() {
47 if (instance == null) {
48 instance = service.load(this);
49 }
50 if (show) {
51 PropertyUtils.info(instance);
52 }
53 return instance;
54 }
55
56 @Override
57 public Class<Properties> getObjectType() {
58 return Properties.class;
59 }
60
61 @Override
62 public boolean isSingleton() {
63 return this.singleton;
64 }
65
66 public void setSingleton(boolean singleton) {
67 this.singleton = singleton;
68 }
69
70 public PropertyService getService() {
71 return service;
72 }
73
74 public void setService(PropertyService service) {
75 this.service = service;
76 }
77
78 public boolean isShow() {
79 return show;
80 }
81
82 public void setShow(boolean show) {
83 this.show = show;
84 }
85 }