View Javadoc

1   /*
2    * $Id: PropertiesDescriptorParser.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  public class PropertiesDescriptorParser implements DescriptorParser
29  {
30  
31      public ApplicationDescriptor parse(File descriptor) throws IOException
32      {
33          final Properties p = new Properties();
34          p.load(new FileInputStream(descriptor));
35  
36          ApplicationDescriptor d = new ApplicationDescriptor();
37          d.setEncoding(p.getProperty("encoding"));
38          d.setConfigurationBuilder(p.getProperty("config.builder"));
39          d.setDomain(p.getProperty("domain"));
40  
41          // get a ref to an optional app props file (right next to the descriptor)
42          final File appPropsFile = new File(descriptor.getParent(), "mule-app.properties");
43          if (appPropsFile.exists() && appPropsFile.canRead())
44          {
45              final Properties props = PropertiesUtils.loadProperties(appPropsFile.toURI().toURL());
46              // ugh, no straightforward way to convert to a map
47              Map<String, String> m = new HashMap<String, String>(props.size());
48              for (String key : m.keySet())
49              {
50                  m.put(key, props.getProperty(key));
51              }
52              d.setAppProperties(m);
53          }
54          
55          // supports true (case insensitive), yes, on as positive values
56          d.setParentFirstClassLoader(BooleanUtils.toBoolean(p.getProperty("classloader.parentFirst", Boolean.TRUE.toString())));
57  
58          final String resProps = p.getProperty("config.resources");
59          String[] urls;
60          if (StringUtils.isBlank(resProps))
61          {
62              urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE};
63          }
64          else
65          {
66              urls = resProps.split(",");
67          }
68          d.setConfigResources(urls);
69  
70          // supports true (case insensitive), yes, on as positive values
71          d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty("redeployment.enabled", Boolean.TRUE.toString())));
72  
73          return d;
74      }
75  
76      public String getSupportedFormat()
77      {
78          return "properties";
79      }
80  }