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.config.spring.util;
8   
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.springframework.beans.factory.InitializingBean;
12  
13  import java.util.Map;
14  
15  /**
16   * Sets system properties from the configured list.
17   */
18  public class SystemPropertyInitializingBean implements InitializingBean {
19  
20      protected Log logger = LogFactory.getLog(getClass());
21  
22      private Map<String, String> systemProperties;
23  
24      /**
25       * Sets the system properties
26       */
27      public void afterPropertiesSet() throws Exception {
28          if (systemProperties == null || systemProperties.isEmpty()) {
29              return;
30          }
31  
32          for (Map.Entry<String, String> entry : systemProperties.entrySet()) {
33              String key = entry.getKey();
34              String value = systemProperties.get(key);
35  
36              if (logger.isInfoEnabled()) {
37                  logger.info(String.format("Setting system property: %s=%s", key, value));
38              }
39  
40              System.setProperty(key, value);
41  
42          }
43      }
44  
45      public void setSystemProperties(Map<String, String> systemProperties) {
46          this.systemProperties = systemProperties;
47      }
48  }