1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.launcher.descriptor; |
12 | |
|
13 | |
import org.mule.util.PropertiesUtils; |
14 | |
import org.mule.util.StringUtils; |
15 | |
|
16 | |
import java.io.File; |
17 | |
import java.io.FileInputStream; |
18 | |
import java.io.IOException; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.Map; |
21 | |
import java.util.Properties; |
22 | |
|
23 | |
import org.apache.commons.lang.BooleanUtils; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class PropertiesDescriptorParser implements DescriptorParser |
29 | |
{ |
30 | |
|
31 | |
public ApplicationDescriptor parse(File descriptor) throws IOException |
32 | |
{ |
33 | 0 | final Properties p = new Properties(); |
34 | 0 | p.load(new FileInputStream(descriptor)); |
35 | |
|
36 | 0 | ApplicationDescriptor d = new ApplicationDescriptor(); |
37 | 0 | d.setEncoding(p.getProperty("encoding")); |
38 | 0 | d.setConfigurationBuilder(p.getProperty("config.builder")); |
39 | 0 | d.setDomain(p.getProperty("domain")); |
40 | |
|
41 | |
|
42 | 0 | final File appPropsFile = new File(descriptor.getParent(), "mule-app.properties"); |
43 | 0 | if (appPropsFile.exists() && appPropsFile.canRead()) |
44 | |
{ |
45 | 0 | final Properties props = PropertiesUtils.loadProperties(appPropsFile.toURI().toURL()); |
46 | |
|
47 | 0 | Map<String, String> m = new HashMap<String, String>(props.size()); |
48 | 0 | for (String key : m.keySet()) |
49 | |
{ |
50 | 0 | m.put(key, props.getProperty(key)); |
51 | |
} |
52 | 0 | d.setAppProperties(m); |
53 | |
} |
54 | |
|
55 | |
|
56 | 0 | d.setParentFirstClassLoader(BooleanUtils.toBoolean(p.getProperty("classloader.parentFirst", Boolean.TRUE.toString()))); |
57 | |
|
58 | 0 | final String resProps = p.getProperty("config.resources"); |
59 | |
String[] urls; |
60 | 0 | if (StringUtils.isBlank(resProps)) |
61 | |
{ |
62 | 0 | urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE}; |
63 | |
} |
64 | |
else |
65 | |
{ |
66 | 0 | urls = resProps.split(","); |
67 | |
} |
68 | 0 | d.setConfigResources(urls); |
69 | |
|
70 | |
|
71 | 0 | d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty("redeployment.enabled", Boolean.TRUE.toString()))); |
72 | |
|
73 | 0 | return d; |
74 | |
} |
75 | |
|
76 | |
public String getSupportedFormat() |
77 | |
{ |
78 | 0 | return "properties"; |
79 | |
} |
80 | |
} |