/** * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. * * @param val the {@code properties} to set * @return a reference to this Builder */ public Builder withProperty(String key, String val) { this.properties.put(key, PropertyValue.of(key, val, name)); return this; }
/** * Constructor for a simple properties configuration. * @param name the source's name, not null * @param props the properties, not null */ public PropertiesBasedPropertySource(String name, Map<String,String> props) { this.name = Objects.requireNonNull(name); for (Entry<String, String> en : props.entrySet()) { this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } }
/** * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. * * @param val the {@code properties} to set * @return a reference to this Builder */ public Builder withProperties(Map<String, String> val) { for(Map.Entry<String,String> en: val.entrySet()) { this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } return this; }
/** * Creates a new Properties based PropertySource. * * @param name the property source name, not null. * @param properties the properties, not null * @param defaultOrdinal the default ordinal */ public SimplePropertySource(String name, Map<String, String> properties, int defaultOrdinal){ super(name, defaultOrdinal); for(Map.Entry<String,String> en: properties.entrySet()) { this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } }
/** * Maps a map of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}. * @param config the String based map, not {@code null}. * @param source the source name, not {@code null}. * @return the corresponding value based map. */ public static Map<String,PropertyValue> map(Map<String, String> config, String source) { Map<String,PropertyValue> result = new HashMap<>(config.size()); for(Map.Entry<String,String> en:config.entrySet()){ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), source)); } return result; }
/** * Constructor for a simple properties configuration. * @param name the source's name, not null * @param props the properties, not null */ public PropertiesBasedPropertySource(String name, Properties props) { this.name = Objects.requireNonNull(name); for (Entry<Object, Object> en : props.entrySet()) { this.properties.put(en.getKey().toString(), PropertyValue.of(en.getKey().toString(), String.valueOf(en.getValue()), name)); } }
@Override public PropertyValue get(String key) { try { key = key.replace('.', '/'); Object o = context.lookup(key); return PropertyValue.of(key, o.toString(), getName()); } catch (NamingException e) { LOG.log(Level.FINER, "Failed to lookup key in JNDI: " + key, e); return null; } }
@Override public Map<String, PropertyValue> getProperties() { Map<String, PropertyValue> result = new HashMap<>(); for(Map.Entry<String,String> en:this.properties.entrySet()) { result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); } return result; }
@Override public PropertyValue get(String key) { String val = properties.get(key); return PropertyValue.of(key, val, getName()); }
@Override public PropertyValue get(String key) { String val = this.properties.get(key); if(val!=null) { return PropertyValue.of(key, val, getName()); } return null; }
/** * Creates a new Properties based PropertySource based on the given properties map. * * @param name the name, not {@code null}. * @param properties the properties, not {@code null}. */ public SimplePropertySource(String name, Map<String, String> properties) { super(0); setName(Objects.requireNonNull(name)); for(Map.Entry<String,String> en:properties.entrySet()){ this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } }
/** * Constructor. * * @param propertySource the base property source, not null. * @param properties the properties to be added. * @param overriding flag if existing properties are overridden. */ EnrichedPropertySource(PropertySource propertySource, Map<String, String> properties, boolean overriding) { this.basePropertySource = Objects.requireNonNull(propertySource); for(Map.Entry<String,String> en:properties.entrySet()){ this.addedProperties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), propertySource.getName())); } this.overriding = overriding; }
@Override public Map<String, PropertyValue> getProperties() { Map<String,PropertyValue> result = new HashMap<>(); for(Map.Entry<String,String> en:config.getProperties().entrySet()){ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); } return result; }
@Override public PropertyValue get(String key) { return PropertyValue.of(key, config.get(key), getName()); }
@Override public Map<String, PropertyValue> getProperties() { Map<String,PropertyValue> result = new HashMap<>(); for (PropertyValue en : this.propertySource.getProperties().values()) { String targetKey = keyMapper.mapKey(en.getKey()); if (targetKey != null) { result.put(targetKey, PropertyValue.of(targetKey, en.getValue(), getName())); } } return result; }
@Override public PropertyValue get(String key) { PropertyValue value = this.source.get(key); if(value!=null) { return PropertyValue.of(key, valueFilter.mapProperty(key, value.getValue()), getName()); } return null; }