View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.launcher.descriptor;
8   
9   import org.mule.util.PropertiesUtils;
10  import org.mule.util.StringUtils;
11  
12  import java.io.File;
13  import java.io.FileInputStream;
14  import java.io.IOException;
15  import java.util.Properties;
16  
17  import org.apache.commons.lang.BooleanUtils;
18  
19  public class PropertiesDescriptorParser implements DescriptorParser
20  {
21      protected static final String PROPERTY_ENCODING = "encoding";
22      protected static final String PROPERTY_CONFIG_BUILDER = "config.builder";
23      protected static final String PROPERTY_DOMAIN = "domain";
24      // support not yet implemented for CL reversal
25      protected static final String PROPERTY_CLASSLOADER_PARENT_FIRST = "classloader.parentFirst";
26      protected static final String PROPERTY_CONFIG_RESOURCES = "config.resources";
27      protected static final String PROPERTY_REDEPLOYMENT_ENABLED = "redeployment.enabled";
28      protected static final String PROPERTY_PRIVILEDGED = "priviledged";
29      protected static final String PROPERTY_SCAN_PACKAGES = "scan.packages";
30  
31      public ApplicationDescriptor parse(File descriptor) throws IOException
32      {
33          final Properties p = PropertiesUtils.loadProperties(new FileInputStream(descriptor));
34  
35          ApplicationDescriptor d = new ApplicationDescriptor();
36          d.setEncoding(p.getProperty(PROPERTY_ENCODING));
37          d.setConfigurationBuilder(p.getProperty(PROPERTY_CONFIG_BUILDER));
38          d.setDomain(p.getProperty(PROPERTY_DOMAIN));
39          d.setPackagesToScan(p.getProperty(PROPERTY_SCAN_PACKAGES));
40  
41          // supports 'true' (case insensitive), 'yes', 'on' as positive values
42          d.setParentFirstClassLoader(BooleanUtils.toBoolean(p.getProperty(PROPERTY_CLASSLOADER_PARENT_FIRST, Boolean.TRUE.toString())));
43  
44          final String resProps = p.getProperty(PROPERTY_CONFIG_RESOURCES);
45          String[] urls;
46          if (StringUtils.isBlank(resProps))
47          {
48              urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE};
49          }
50          else
51          {
52              urls = resProps.split(",");
53          }
54          d.setConfigResources(urls);
55  
56          // supports true (case insensitive), yes, on as positive values
57          d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty(PROPERTY_REDEPLOYMENT_ENABLED, Boolean.TRUE.toString())));
58  
59          d.setPriviledged(BooleanUtils.toBoolean(p.getProperty(PROPERTY_PRIVILEDGED, Boolean.FALSE.toString())));
60  
61          return d;
62      }
63  
64      public String getSupportedFormat()
65      {
66          return "properties";
67      }
68  }