View Javadoc

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