View Javadoc

1   /**
2    * Copyright 2010-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.property.processor;
17  
18  import java.util.List;
19  import java.util.Properties;
20  
21  import org.kuali.common.util.Mode;
22  import org.kuali.common.util.PropertyUtils;
23  import org.kuali.common.util.property.Constants;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  public class SetSystemPropertiesProcessor implements PropertyProcessor {
28  	private static final Logger logger = LoggerFactory.getLogger(SetSystemPropertiesProcessor.class);
29  
30  	Mode propertyOverwriteMode;
31  	List<String> includes;
32  	List<String> excludes;
33  
34  	public SetSystemPropertiesProcessor() {
35  		this(null);
36  	}
37  
38  	public SetSystemPropertiesProcessor(List<String> includes) {
39  		super();
40  		this.includes = includes;
41  		this.propertyOverwriteMode = Constants.DEFAULT_PROPERTY_OVERWRITE_MODE;
42  	}
43  
44  	@Override
45  	public void process(Properties properties) {
46  		List<String> keys = PropertyUtils.getSortedKeys(properties, includes, excludes);
47  		Properties systemProperties = System.getProperties();
48  		for (String key : keys) {
49  			String value = properties.getProperty(key);
50  			logger.info("Setting system property [{}]", key);
51  			PropertyUtils.addOrOverrideProperty(systemProperties, key, value, propertyOverwriteMode);
52  		}
53  	}
54  
55  	public Mode getPropertyOverwriteMode() {
56  		return propertyOverwriteMode;
57  	}
58  
59  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
60  		this.propertyOverwriteMode = propertyOverwriteMode;
61  	}
62  
63  	public List<String> getIncludes() {
64  		return includes;
65  	}
66  
67  	public void setIncludes(List<String> includes) {
68  		this.includes = includes;
69  	}
70  
71  	public List<String> getExcludes() {
72  		return excludes;
73  	}
74  
75  	public void setExcludes(List<String> excludes) {
76  		this.excludes = excludes;
77  	}
78  
79  }