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  
25  public class OverrideProcessor implements PropertyProcessor {
26  
27  	Mode propertyOverwriteMode;
28  	Properties overrideProperties;
29  	List<String> includes;
30  	List<String> excludes;
31  
32  	public OverrideProcessor() {
33  		this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
34  	}
35  
36  	public OverrideProcessor(Mode propertyOverwriteMode) {
37  		this(Constants.DEFAULT_PROPERTY_OVERWRITE_MODE, null);
38  	}
39  
40  	public OverrideProcessor(Mode propertyOverwriteMode, Properties overrideProperties) {
41  		super();
42  		this.propertyOverwriteMode = propertyOverwriteMode;
43  		this.overrideProperties = overrideProperties;
44  	}
45  
46  	@Override
47  	public void process(Properties properties) {
48  		List<String> keys = PropertyUtils.getSortedKeys(overrideProperties, includes, excludes);
49  		for (String key : keys) {
50  			String newValue = overrideProperties.getProperty(key);
51  			PropertyUtils.addOrOverrideProperty(properties, key, newValue, 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 Properties getOverrideProperties() {
64  		return overrideProperties;
65  	}
66  
67  	public void setOverrideProperties(Properties overrideProperties) {
68  		this.overrideProperties = overrideProperties;
69  	}
70  
71  	public List<String> getIncludes() {
72  		return includes;
73  	}
74  
75  	public void setIncludes(List<String> includes) {
76  		this.includes = includes;
77  	}
78  
79  	public List<String> getExcludes() {
80  		return excludes;
81  	}
82  
83  	public void setExcludes(List<String> excludes) {
84  		this.excludes = excludes;
85  	}
86  
87  }