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.springframework.beans.factory.FactoryBean;
21 import org.springframework.core.env.ConfigurableEnvironment;
22 import org.springframework.core.env.PropertiesPropertySource;
23 import org.springframework.core.env.PropertySource;
24
25 import com.google.common.base.Preconditions;
26
27 public class EnvironmentPropertySourceFactoryBean implements FactoryBean<PropertySource<?>> {
28
29 ConfigurableEnvironment env;
30 boolean quietly = false;
31
32 @Override
33 public PropertySource<?> getObject() {
34 Preconditions.checkNotNull(env, "'env' cannot be null");
35 Properties source = getProperties();
36 return new PropertiesPropertySource("environmentProperties", source);
37 }
38
39 protected Properties getProperties() {
40 if (quietly) {
41 return PropertySourceUtils.getAllEnumerablePropertiesQuietly(env);
42 } else {
43 return PropertySourceUtils.getAllEnumerableProperties(env);
44 }
45 }
46
47 @Override
48 public Class<PropertySource<?>> getObjectType() {
49 return null;
50 }
51
52 @Override
53 public boolean isSingleton() {
54 return false;
55 }
56
57 public ConfigurableEnvironment getEnv() {
58 return env;
59 }
60
61 public void setEnv(ConfigurableEnvironment env) {
62 this.env = env;
63 }
64
65 public boolean isQuietly() {
66 return quietly;
67 }
68
69 public void setQuietly(boolean quietly) {
70 this.quietly = quietly;
71 }
72 }