/** * This method will create a change set that clears all entries fromMap the given base configuration/properties. * * @return the builder for chaining. */ public PropertySourceChangeBuilder deleteAll() { this.delta.clear(); for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) { this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue().getValue(), null)); } return this; }
@Override public String get(String key) { Objects.requireNonNull(key, "Key must not be null."); PropertyValue value = configEvaluator.evaluteRawValue(key, configurationContext); if(value==null || value.getValue()==null){ return null; } value = PropertyFiltering.applyFilter(value, configurationContext); if(value!=null){ return value.getValue(); } return null; }
public int getOrdinal() { PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); if (configuredOrdinal != null) { try { return Integer.parseInt(configuredOrdinal.getValue()); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Configured Ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); }
@Override public int getOrdinal() { PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); if(configuredOrdinal!=null){ try{ return Integer.parseInt(configuredOrdinal.getValue()); } catch(Exception e){ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Configured Ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); }
/** * Get a given value, filtered with the context's filters as needed. * @param key the property's key, not null. * @return the filtered value, or null. */ @Override public String get(String key) { PropertyValue value = configEvaluator.evaluteRawValue(key, configurationContext); if(value==null || value.getValue()==null){ return null; } value = PropertyFiltering.applyFilter(value, configurationContext); if(value!=null){ return value.getValue(); } return null; }
@Override public int getOrdinal(){ PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); if(configuredOrdinal!=null){ try{ return Integer.parseInt(configuredOrdinal.getValue()); } catch(Exception e){ Logger.getLogger(getClass().getName()).log(Level.WARNING, "Configured Ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); }
public int getOrdinal() { Integer ordinal = this.ordinal; if(ordinal!=null){ Logger.getLogger(getClass().getName()).finest( "Using explicit ordinal '"+ordinal+"' for property source: " + getName()); return ordinal; } PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); if(configuredOrdinal!=null){ try { return Integer.parseInt(configuredOrdinal.getValue()); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Configured Ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); }
public int getOrdinal() { Integer ordinal = this.ordinal; if(ordinal!=null){ Logger.getLogger(getClass().getName()).finest( "Using explicit ordinal '"+ordinal+"' for property source: " + getName()); return ordinal; } PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); if(configuredOrdinal!=null){ try { return Integer.parseInt(configuredOrdinal.getValue()); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Configured ordinal is not an int number: " + configuredOrdinal, e); } } return getDefaultOrdinal(); }
/** * Compares the two property config/configurations and creates a collection current all changes * that must be applied to render {@code map1} into {@code map2}. * * @param map1 the source map, not null. * @param map2 the target map, not null. * @return a collection current change events, never null. */ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) { List<PropertyChangeEvent> changes = new ArrayList<>(); for (Map.Entry<String, PropertyValue> en : map1.getProperties().entrySet()) { PropertyValue val = map2.get(en.getKey()); if (val == null) { changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue().getValue())); } else if (!val.equals(en.getValue())) { changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue().getValue())); } } for (Map.Entry<String, PropertyValue> en : map2.getProperties().entrySet()) { PropertyValue val = map1.get(en.getKey()); if (val == null) { changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), null)); } else if (!val.equals(en.getValue())) { changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), val.getValue())); } } return changes; }
@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()); }
/** * 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; }
@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 evaluteRawValue(String key, ConfigurationContext context) { PropertyValue unfilteredValue = null; for (PropertySource propertySource : context.getPropertySources()) { unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, key, propertySource); } if(unfilteredValue==null || unfilteredValue.getValue()==null){ return unfilteredValue; } return unfilteredValue; }
@Override public PropertyValue evaluteRawValue(String key, ConfigurationContext context) { PropertyValue unfilteredValue = null; for (PropertySource propertySource : context.getPropertySources()) { unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, key, propertySource); } if(unfilteredValue==null || unfilteredValue.getValue()==null){ return unfilteredValue; } return unfilteredValue; }
@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 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; }
/** * 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); }
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();