1 16 package scriptella.configuration; 17 18 import scriptella.expression.PropertiesSubstitutor; 19 import scriptella.spi.ParametersCallback; 20 import scriptella.util.CollectionUtils; 21 import scriptella.util.PropertiesMap; 22 23 import java.util.Map ; 24 import java.util.Properties ; 25 26 34 class PropertiesMerger implements ParametersCallback { 35 private PropertiesMap properties; 36 private PropertiesSubstitutor substitutor=new PropertiesSubstitutor(this); 37 38 public PropertiesMerger() { 39 properties = new PropertiesMap(); 40 } 41 42 public PropertiesMerger(Properties properties) { 43 this.properties = new PropertiesMap(CollectionUtils.asMap(properties)); 44 } 45 46 public PropertiesMerger(Map<String ,?> properties) { 47 this.properties = new PropertiesMap(properties); 48 } 49 50 56 void addProperties(final Map<String , ?> properties) { 57 for (Map.Entry<String , ?> entry : properties.entrySet()) { 58 Object v = entry.getValue(); 59 if (v instanceof CharSequence ) { 60 v = substitutor.substitute(v.toString()); 61 } 62 this.properties.put(entry.getKey(), v); 63 } 64 } 65 66 public Object getParameter(final String name) { 67 return properties.get(name); 68 } 69 70 75 public PropertiesSubstitutor getSubstitutor() { 76 return substitutor; 77 } 78 79 80 public String toString() { 81 return "PropertiesMerger{" + 82 properties + 83 '}'; 84 } 85 } 86 | Popular Tags |