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 | 0 | protected boolean loadSystemProperties = true; |
42 | 0 | protected boolean enableTemplates = false; |
43 | |
|
44 | 0 | protected TemplateParser templateParser = TemplateParser.createAntStyleParser(); |
45 | |
|
46 | |
public PropertiesContainerContext() |
47 | |
{ |
48 | 0 | super("properties"); |
49 | 0 | } |
50 | |
|
51 | |
public void configure(Reader configuration) throws ContainerException |
52 | |
{ |
53 | 0 | 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 | 0 | if (key == null) |
70 | |
{ |
71 | 0 | throw new ObjectNotFoundException("null"); |
72 | |
} |
73 | 0 | Object value = MuleManager.getInstance().getProperty(key.toString()); |
74 | 0 | if (value == null) |
75 | |
{ |
76 | 0 | throw new ObjectNotFoundException(key.toString()); |
77 | |
} |
78 | 0 | if (value instanceof String && enableTemplates) |
79 | |
{ |
80 | 0 | value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString()); |
81 | |
} |
82 | 0 | return value; |
83 | |
} |
84 | |
|
85 | |
public Map getSystemProperties() |
86 | |
{ |
87 | 0 | return systemProperties; |
88 | |
} |
89 | |
|
90 | |
public void setSystemProperties(Map properties) |
91 | |
{ |
92 | 0 | this.systemProperties = properties; |
93 | |
String value; |
94 | |
Map.Entry entry; |
95 | 0 | if (systemProperties != null) |
96 | |
{ |
97 | 0 | for (Iterator iterator = systemProperties.entrySet().iterator(); iterator.hasNext();) |
98 | |
{ |
99 | 0 | entry = (Map.Entry) iterator.next(); |
100 | 0 | value = entry.getValue().toString(); |
101 | 0 | value = templateParser.parse(systemProperties, value); |
102 | 0 | value = templateParser.parse(MuleManager.getInstance().getProperties(), value); |
103 | 0 | System.setProperty(entry.getKey().toString(), value); |
104 | |
} |
105 | |
} |
106 | |
|
107 | 0 | if (loadSystemProperties) |
108 | |
{ |
109 | 0 | Map props = System.getProperties(); |
110 | |
|
111 | 0 | for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) |
112 | |
{ |
113 | 0 | entry = (Map.Entry) iterator.next(); |
114 | 0 | value = entry.getValue().toString(); |
115 | 0 | value = templateParser.parse(MuleManager.getInstance().getProperties(), value.toString()); |
116 | 0 | MuleManager.getInstance().setProperty(entry.getKey(), value); |
117 | |
} |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
public Map getProperties() |
122 | |
{ |
123 | 0 | return properties; |
124 | |
} |
125 | |
|
126 | |
public void setProperties(Map properties) |
127 | |
{ |
128 | 0 | this.properties = properties; |
129 | 0 | if (properties != null) |
130 | |
{ |
131 | |
Map.Entry entry; |
132 | |
String value; |
133 | 0 | for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) |
134 | |
{ |
135 | 0 | entry = (Map.Entry) iterator.next(); |
136 | 0 | value = entry.getValue().toString(); |
137 | 0 | value = templateParser.parse(MuleManager.getInstance().getProperties(), value); |
138 | 0 | MuleManager.getInstance().setProperty(entry.getKey(), value); |
139 | |
} |
140 | |
} |
141 | 0 | } |
142 | |
} |