@Override public PropertyValue collect(PropertyValue currentValue, String key, PropertySource propertySource) { PropertyValue value = propertySource.get(key); return value!=null?value:currentValue; }
@Override public String getName() { return delegate.getName(); }
@Override public Map<String, PropertyValue> getProperties() { return delegate.getProperties(); }
/** * Constructor. * * @param propertySource The base PropertySource. */ private FrozenPropertySource(PropertySource propertySource) { this.properties.putAll(propertySource.getProperties()); this.properties = Collections.unmodifiableMap(this.properties); this.ordinal = PropertySourceComparator.getOrdinal(propertySource); this.name = propertySource.getName(); }
b.append(" "); appendFormatted(b, ps.getClass().getSimpleName(), 30); appendFormatted(b, ps.getName(), 70); appendFormatted(b, String.valueOf(ps.isScannable()), 10); if (ps.isScannable()) { appendFormatted(b, String.valueOf(ps.getProperties().size()), 8); } else { appendFormatted(b, "-", 8); PropertyValue state = ps.get("_state"); if(state==null){ appendFormatted(b, "OK", 10); appendFormatted(b, state.getValue(), 10); if("ERROR".equals(state.getValue())){ PropertyValue val = ps.get("_exception"); if(val!=null) { appendFormatted(b, val.getValue(), 30);
/** * 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; }
public static int getOrdinal(PropertySource propertySource) { // PropertyValue ordinalValue = propertySource.get(PropertySource.TAMAYA_ORDINAL); // if(ordinalValue!=null){ // try{ // return Integer.parseInt(ordinalValue.getProperty().trim()); // }catch(Exception e){ // LOG.finest("Failed to parse ordinal from " + PropertySource.TAMAYA_ORDINAL + // " in " + propertySource.getName()+": "+ordinalValue.getProperty()); // } // } // try { // Method method = propertySource.getClass().getMethod("getOrdinal"); // if(int.class.equals(method.getReturnType())){ // try { // return (int)method.invoke(propertySource); // } catch (Exception e) { // LOG.log(Level.FINEST, "Error calling int getOrdinal() on " + propertySource.getName(), e); // } // } // } catch (NoSuchMethodException e) { // LOG.finest("No int getOrdinal() method found in " + propertySource.getName()); // } // Priority prio = propertySource.getClass().getAnnotation(Priority.class); // if(prio!=null){ // return prio.value(); // } return propertySource.getOrdinal(); } @Override
@Override public boolean isScannable() { return basePropertySource.isScannable(); } }
b.append(" "); appendFormatted(b, ps.getClass().getSimpleName(), 30); appendFormatted(b, ps.getName(), 70); appendFormatted(b, String.valueOf(PropertySourceComparator.getOrdinal(ps)), 8); appendFormatted(b, String.valueOf(ps.isScannable()), 10); if (ps.isScannable()) { appendFormatted(b, String.valueOf(ps.getProperties().size()), 8); } else { appendFormatted(b, "-", 8); PropertyValue state = ps.get("_state"); if(state==null){ appendFormatted(b, "OK", 10); appendFormatted(b, state.getValue(), 10); if("ERROR".equals(state.getValue())){ PropertyValue val = ps.get("_exception"); if(val!=null) { appendFormatted(b, val.getValue(), 30);
/** * Get the current properties, composed by the loaded {@link org.apache.tamaya.spi.PropertySource} and filtered * by registered {@link org.apache.tamaya.spi.PropertyFilter}. * * @return the final properties. */ @Override public Map<String, String> getProperties() { List<PropertySource> propertySources = new ArrayList<>(configurationContext.getPropertySources()); Collections.reverse(propertySources); Map<String, String> result = new HashMap<>(); for (PropertySource propertySource : propertySources) { try { int origSize = result.size(); Map<String, String> otherMap = propertySource.getProperties(); LOG.log(Level.FINEST, null, "Overriding with properties from " + propertySource.getName()); result.putAll(otherMap); LOG.log(Level.FINEST, null, "Handled properties from " + propertySource.getName() + "(new: " + (result.size() - origSize) + ", overrides: " + origSize + ", total: " + result.size()); } catch (Exception e) { LOG.log(Level.SEVERE, "Error adding properties from PropertySource: " + propertySource + ", ignoring PropertySource.", e); } } return applyFilters(result); }
/** * Order property source reversely, the most important come first. * * @param source1 the first PropertySource * @param source2 the second PropertySource * @return the comparison result. */ private int comparePropertySources(PropertySource source1, PropertySource source2) { if (source1.getOrdinal() < source2.getOrdinal()) { return -1; } else if (source1.getOrdinal() > source2.getOrdinal()) { return 1; } else { return source1.getClass().getName().compareTo(source2.getClass().getName()); } }
@Override public boolean isScannable() { return delegate.isScannable(); }
@Override public String toString() { return "ValueMappedPropertySource{" + "source=" + source.getName() + ", name='" + name + '\'' + ", valueFilter=" + valueFilter + '}'; } }
/** * Puts all values from the given property source. * @param propertySource the property source, not null. * @return the bulder for chaining. */ public PropertySourceBuilder putAll(PropertySource propertySource){ this.properties.putAll(propertySource.getProperties()); return this; }
@Override public String collect(String currentValue, String key, PropertySource propertySource) { String value = propertySource.get(key); return value!=null?value:currentValue; }
/** * Order property source reversely, the most important come first. * * @param source1 the first PropertySource * @param source2 the second PropertySource * @return the comparison result. */ private int comparePropertySources(PropertySource source1, PropertySource source2) { //X TODO this method duplicates org.apache.tamaya.core.internal.DefaultConfigurationContext.PropertySourceComparator.comparePropertySources() //X maybe we should extract the Comperator in an own class for real code-reuse (copy paste == bad code reuse) if (source1.getOrdinal() < source2.getOrdinal()) { return -1; } else if (source1.getOrdinal() > source2.getOrdinal()) { return 1; } else { return source1.getClass().getName().compareTo(source2.getClass().getName()); } }
@Override public boolean isScannable() { return propertySource.isScannable(); }
@Override public String getName() { return baseSource.getName(); }
/** * 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 PropertyValue get(String key) { return delegate.get(key); }