View Javadoc

1   package org.kuali.common.util.property.processor;
2   
3   import java.util.List;
4   import java.util.Properties;
5   
6   import org.kuali.common.util.Mode;
7   import org.kuali.common.util.PropertyUtils;
8   import org.kuali.common.util.property.Constants;
9   import org.kuali.common.util.property.GlobalPropertiesMode;
10  
11  public class GlobalOverrideProcessor implements PropertyProcessor {
12  
13  	GlobalPropertiesMode globalPropertiesMode;
14  	Mode propertyOverwriteMode;
15  
16  	public GlobalOverrideProcessor() {
17  		this(GlobalPropertiesMode.BOTH, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
18  	}
19  
20  	public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode) {
21  		this(globalPropertiesMode, Constants.DEFAULT_PROPERTY_OVERWRITE_MODE);
22  	}
23  
24  	public GlobalOverrideProcessor(GlobalPropertiesMode globalPropertiesMode, Mode propertyOverwriteMode) {
25  		super();
26  		this.globalPropertiesMode = globalPropertiesMode;
27  		this.propertyOverwriteMode = propertyOverwriteMode;
28  	}
29  
30  	@Override
31  	public void process(Properties properties) {
32  		Properties global = PropertyUtils.getProperties(properties, globalPropertiesMode);
33  		List<String> keys = PropertyUtils.getSortedKeys(properties);
34  		for (String key : keys) {
35  			String newValue = global.getProperty(key);
36  			PropertyUtils.addOrOverrideProperty(properties, key, newValue, propertyOverwriteMode);
37  		}
38  	}
39  
40  	public GlobalPropertiesMode getGlobalPropertiesMode() {
41  		return globalPropertiesMode;
42  	}
43  
44  	public void setGlobalPropertiesMode(GlobalPropertiesMode globalPropertiesMode) {
45  		this.globalPropertiesMode = globalPropertiesMode;
46  	}
47  
48  	public Mode getPropertyOverwriteMode() {
49  		return propertyOverwriteMode;
50  	}
51  
52  	public void setPropertyOverwriteMode(Mode propertyOverwriteMode) {
53  		this.propertyOverwriteMode = propertyOverwriteMode;
54  	}
55  
56  }