View Javadoc

1   /*
2    * $Id: PropertiesDescriptorParser.java 20792 2010-12-16 16:58:49Z aperepel $
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.StringUtils;
14  
15  import java.io.File;
16  import java.io.FileInputStream;
17  import java.io.IOException;
18  import java.util.Properties;
19  
20  import org.apache.commons.lang.BooleanUtils;
21  
22  /**
23   *
24   */
25  public class PropertiesDescriptorParser implements DescriptorParser
26  {
27      protected static final String PROPERTY_ENCODING = "encoding";
28      protected static final String PROPERTY_CONFIG_BUILDER = "config.builder";
29      protected static final String PROPERTY_DOMAIN = "domain";
30      // support not yet implemented for CL reversal
31      protected static final String PROPERTY_CLASSLOADER_PARENT_FIRST = "classloader.parentFirst";
32      protected static final String PROPERTY_CONFIG_RESOURCES = "config.resources";
33      protected static final String PROPERTY_REDEPLOYMENT_ENABLED = "redeployment.enabled";
34      protected static final String PROPERTY_PRIVILEDGED = "priviledged";
35  
36      public ApplicationDescriptor parse(File descriptor) throws IOException
37      {
38          final Properties p = new Properties();
39          p.load(new FileInputStream(descriptor));
40  
41          ApplicationDescriptor d = new ApplicationDescriptor();
42          d.setEncoding(p.getProperty(PROPERTY_ENCODING));
43          d.setConfigurationBuilder(p.getProperty(PROPERTY_CONFIG_BUILDER));
44          d.setDomain(p.getProperty(PROPERTY_DOMAIN));
45  
46          // supports 'true' (case insensitive), 'yes', 'on' as positive values
47          d.setParentFirstClassLoader(BooleanUtils.toBoolean(p.getProperty(PROPERTY_CLASSLOADER_PARENT_FIRST, Boolean.TRUE.toString())));
48  
49          final String resProps = p.getProperty(PROPERTY_CONFIG_RESOURCES);
50          String[] urls;
51          if (StringUtils.isBlank(resProps))
52          {
53              urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE};
54          }
55          else
56          {
57              urls = resProps.split(",");
58          }
59          d.setConfigResources(urls);
60  
61          // supports true (case insensitive), yes, on as positive values
62          d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty(PROPERTY_REDEPLOYMENT_ENABLED, Boolean.TRUE.toString())));
63  
64          d.setPriviledged(BooleanUtils.toBoolean(p.getProperty(PROPERTY_PRIVILEDGED, Boolean.FALSE.toString())));
65  
66          return d;
67      }
68  
69      public String getSupportedFormat()
70      {
71          return "properties";
72      }
73  }