View Javadoc

1   /*
2    * $Id: PropertiesDescriptorParser.java 22252 2011-06-23 06:15:55Z dirk.olmes $
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.Collections;
19  import java.util.HashSet;
20  import java.util.Properties;
21  import java.util.Set;
22  
23  import org.apache.commons.lang.BooleanUtils;
24  
25  /**
26   *
27   */
28  public class PropertiesDescriptorParser implements DescriptorParser
29  {
30      protected static final String PROPERTY_ENCODING = "encoding";
31      protected static final String PROPERTY_CONFIG_BUILDER = "config.builder";
32      protected static final String PROPERTY_DOMAIN = "domain";
33      // support not yet implemented for CL reversal
34      protected static final String PROPERTY_CONFIG_RESOURCES = "config.resources";
35      protected static final String PROPERTY_REDEPLOYMENT_ENABLED = "redeployment.enabled";
36      // there was a typo in the prop name, but we still support it
37      protected static final String PROPERTY_LEGACY_PRIVILEGED = "priviledged";
38      protected static final String PROPERTY_PRIVILEGED = "privileged";
39      protected static final String PROPERTY_LOADER_OVERRIDE = "loader.override";
40      protected static final String PROPERTY_SCAN_PACKAGES = "scan.packages";
41  
42      public ApplicationDescriptor parse(File descriptor) throws IOException
43      {
44          final Properties p = new Properties();
45          p.load(new FileInputStream(descriptor));
46  
47          ApplicationDescriptor d = new ApplicationDescriptor();
48          d.setEncoding(p.getProperty(PROPERTY_ENCODING));
49          d.setConfigurationBuilder(p.getProperty(PROPERTY_CONFIG_BUILDER));
50          d.setDomain(p.getProperty(PROPERTY_DOMAIN));
51          d.setPackagesToScan(p.getProperty(PROPERTY_SCAN_PACKAGES));
52  
53          final String resProps = p.getProperty(PROPERTY_CONFIG_RESOURCES);
54          String[] urls;
55          if (StringUtils.isBlank(resProps))
56          {
57              urls = new String[] {ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE};
58          }
59          else
60          {
61              urls = resProps.split(",");
62          }
63          d.setConfigResources(urls);
64  
65          // supports true (case insensitive), yes, on as positive values
66          d.setRedeploymentEnabled(BooleanUtils.toBoolean(p.getProperty(PROPERTY_REDEPLOYMENT_ENABLED, Boolean.TRUE.toString())));
67  
68          // fallback to a legacy property name
69          d.setPrivileged(BooleanUtils.toBoolean(p.getProperty(PROPERTY_PRIVILEGED,
70                                                               p.getProperty(PROPERTY_LEGACY_PRIVILEGED, Boolean.FALSE.toString()))));
71  
72          final String overrideString = p.getProperty(PROPERTY_LOADER_OVERRIDE);
73          if (StringUtils.isNotBlank(overrideString))
74          {
75              Set<String> values = new HashSet<String>();
76              final String[] overrides = overrideString.split(",");
77              Collections.addAll(values, overrides);
78              d.setLoaderOverride(values);
79          }
80  
81          return d;
82      }
83  
84      public String getSupportedFormat()
85      {
86          return "properties";
87      }
88  }