1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl.container;
12
13 import org.mule.MuleManager;
14 import org.mule.umo.manager.ContainerException;
15 import org.mule.umo.manager.ObjectNotFoundException;
16 import org.mule.util.TemplateParser;
17
18 import java.io.Reader;
19 import java.util.Iterator;
20 import java.util.Map;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public class PropertiesContainerContext extends AbstractContainerContext
37 {
38
39 protected Map systemProperties;
40 protected Map properties;
41 protected boolean loadSystemProperties = true;
42 protected boolean enableTemplates = false;
43
44 protected TemplateParser templateParser = TemplateParser.createAntStyleParser();
45
46 public PropertiesContainerContext()
47 {
48 super("properties");
49 }
50
51 public void configure(Reader configuration) throws ContainerException
52 {
53 throw new UnsupportedOperationException("configure");
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67 public Object getComponent(Object key) throws ObjectNotFoundException
68 {
69 if (key == null)
70 {
71 throw new ObjectNotFoundException("null");
72 }
73 Object value = MuleManager.getInstance().getProperty(key.toString());
74 if (value == null)
75 {
76 throw new ObjectNotFoundException(key.toString());
77 }
78 if (value instanceof String && enableTemplates)
79 {
80 value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString());
81 }
82 return value;
83 }
84
85 public Map getSystemProperties()
86 {
87 return systemProperties;
88 }
89
90 public void setSystemProperties(Map properties)
91 {
92 this.systemProperties = properties;
93 String value;
94 Map.Entry entry;
95 if (systemProperties != null)
96 {
97 for (Iterator iterator = systemProperties.entrySet().iterator(); iterator.hasNext();)
98 {
99 entry = (Map.Entry) iterator.next();
100 value = entry.getValue().toString();
101 value = templateParser.parse(systemProperties, value);
102 value = templateParser.parse(MuleManager.getInstance().getProperties(), value);
103 System.setProperty(entry.getKey().toString(), value);
104 }
105 }
106
107 if (loadSystemProperties)
108 {
109 Map props = System.getProperties();
110
111 for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();)
112 {
113 entry = (Map.Entry) iterator.next();
114 value = entry.getValue().toString();
115 value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString());
116 MuleManager.getInstance().setProperty(entry.getKey(), value);
117 }
118 }
119 }
120
121 public Map getProperties()
122 {
123 return properties;
124 }
125
126 public void setProperties(Map properties)
127 {
128 this.properties = properties;
129 if (properties != null)
130 {
131 Map.Entry entry;
132 String value;
133 for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();)
134 {
135 entry = (Map.Entry) iterator.next();
136 value = entry.getValue().toString();
137 value = templateParser.parse(MuleManager.getInstance().getProperties(), value);
138 MuleManager.getInstance().setProperty(entry.getKey(), value);
139 }
140 }
141 }
142 }