@Override public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { if(includes!=null){ for(String expression:includes){ if(context.getProperty().getKey().matches(expression)){ return valueToBeFiltered; } } return null; } if(excludes!=null){ for(String expression:excludes){ if(context.getProperty().getKey().matches(expression)){ return null; } } } return valueToBeFiltered; }
@Override public Map<String, PropertyValue> getProperties() { Map<String, PropertyValue> allProps; if (overriding) { allProps = new HashMap<>(); for(PropertyValue val:basePropertySource.getProperties().values()){ allProps.put(val.getKey(), val); } allProps.putAll(addedProperties); } else { allProps = new HashMap<>(addedProperties); for(PropertyValue val:basePropertySource.getProperties().values()){ allProps.put(val.getKey(), val); } } return allProps; }
/** * Filters all properties. * @param rawProperties the unfiltered properties, not null. * @param context the context * @return the filtered value, inclusing null. */ public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> rawProperties, ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); // Apply filters to values, prevent values filtered to null! for (Map.Entry<String, PropertyValue> entry : rawProperties.entrySet()) { FilterContext filterContext = new FilterContext(entry.getValue(), rawProperties, context); PropertyValue filtered = filterValue(filterContext); if(filtered!=null){ result.put(filtered.getKey(), filtered); } } return result; }
/** * Filters all properties. * @param rawProperties the unfiltered properties, not {@code null}. * @param context the context * @return the filtered value, inclusing null. */ public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> rawProperties, ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); // Apply filters to values, prevent values filtered to null! for (Map.Entry<String, PropertyValue> entry : rawProperties.entrySet()) { FilterContext filterContext = new FilterContext(entry.getValue(), rawProperties, context); PropertyValue filtered = filterValue(filterContext); if(filtered!=null){ result.put(filtered.getKey(), filtered); } } return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof PropertyValue)) return false; PropertyValue that = (PropertyValue) o; return Objects.equals(getKey(), that.getKey()) && Objects.equals(getValue(), that.getValue()) && Objects.equals(getSource(), that.getSource()) && Objects.equals(getMetaEntries(), that.getMetaEntries()); }
@Override public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); for (PropertySource propertySource : context.getPropertySources()) { for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) { PropertyValue unfilteredValue = result.get(propEntry.getKey()); unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, propEntry.getKey(), propertySource); if(unfilteredValue!=null){ result.put(unfilteredValue.getKey(), unfilteredValue); } } } return result; }
@Override public Map<String, PropertyValue> getProperties() { Map<String,PropertyValue> result = new HashMap<>(); for(PropertyValue val : source.getProperties().values()) { String mappedValue = valueFilter.mapProperty(val.getKey(), val.getValue()); PropertyValue value = val.toBuilder().setValue(mappedValue).build(); result.put(val.getKey(), value); } return result; }
@Override public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); for (PropertySource propertySource : context.getPropertySources()) { for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) { PropertyValue unfilteredValue = result.get(propEntry.getKey()); unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, propEntry.getKey(), propertySource); if(unfilteredValue!=null){ result.put(unfilteredValue.getKey(), unfilteredValue); } } } return result; }
@Override public int hashCode() { return Objects.hash(getKey(), getValue(), getSource(), getMetaEntries()); }
@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 filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { if(context.isSinglePropertyScoped()){ // When accessing keys explicitly, do not hide anything. return valueToBeFiltered; } if(ConfigurationFilter.isMetadataFiltered()) { if (context.getProperty().getKey().startsWith("_")) { // Hide metadata entries. return null; } } return valueToBeFiltered; } }
@Override public PropertyValue get(String key) { PropertyValue val = this.getBaseSource().get(key); if(val!=null && filter.test(val.getKey())) { return val; } return null; }
/** * Get the current properties, composed by the loaded {@link PropertySource} and filtered * by registered {@link PropertyFilter}. * * @return the final properties. */ @Override public Map<String, String> getProperties() { Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters( configEvaluator.evaluateRawValues(configurationContext), configurationContext); Map<String,String> result = new HashMap<>(); for(PropertyValue val:filtered.values()){ if(val.getValue()!=null) { result.put(val.getKey(), val.getValue()); // TODO: Discuss metadata handling... result.putAll(val.getMetaEntries()); } } return result; }
/** * Get the current properties, composed by the loaded {@link PropertySource} and filtered * by registered {@link org.apache.tamaya.spi.PropertyFilter}. * * @return the final properties. */ @Override public Map<String, String> getProperties() { Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters( configEvaluator.evaluateRawValues(configurationContext), configurationContext); Map<String,String> result = new HashMap<>(); for(PropertyValue val:filtered.values()){ if(val.getValue()!=null) { result.put(val.getKey(), val.getValue()); // TODO: Discuss metadata handling... result.putAll(val.getMetaEntries()); } } return result; }
/** * Creates a new builder instance based on this item. * @return a new builder, never null. */ public PropertyValueBuilder toBuilder() { return new PropertyValueBuilder(this.getKey(), this.getSource()) .setValue(this.getValue()) .setMetaEntries(this.metaEntries); }
String newKey = keyMapper.mapKey(property.getKey());
public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context){ LOG.finest("Resolving " + valueToBeFiltered); String newVal = evaluator().evaluateExpression(valueToBeFiltered.getKey(), valueToBeFiltered.getValue(), true); if(newVal!=null){ return valueToBeFiltered.toBuilder().setValue(newVal).build();