@Override public Optional<String> lookup(final Map<String, Object> coordinates) throws LookupFailureException { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (StringUtils.isBlank(key)) { return Optional.empty(); } final Configuration config = getConfiguration(); if (config != null) { final Object value = config.getProperty(key); if (value != null) { return Optional.of(String.valueOf(value)); } } return Optional.empty(); }
/** * Will poke parents for defaults * @param key to lookup * @return the value or null */ @Override public Object getPropertyInternal(String key) { Object value = super.getPropertyInternal(key); if (value == null) { if (LOG.isDebugEnabled()) { LOG.debug("poking parent '" + getParent().getClass().getSimpleName() + "' for key: " + key); } return getParent().getProperty(key.startsWith(PREFIX_DEFAULT) ? key : PREFIX_DEFAULT + key); } LOG.debug("Returning '{}' for key: {}", value, key); return value; }
@Override public Object getProperty(final String name) { return source.getProperty(name); } }
@Override protected Object getPropertyInternal(final String key) { return configuration.getProperty(key); }
@Override public Object getValue() { return configuration.getProperty((String) key); }
/** * Returns the value of the specified key. The key is converted to a string * and then passed to the underlying configuration. * * @param key the key * @return the value of this key * @see java.util.Map#get(java.lang.Object) */ @Override public Object get(final Object key) { return configuration.getProperty(String.valueOf(key)); }
@Override protected Object getPropertyInternal(final String key) { return parent.getProperty(getParentKey(key)); }
/** * Stores the value for the specified key. The value is stored in the * underlying configuration. * * @param key the key (will be converted to a string) * @param value the value * @return the old value of this key or <b>null</b> if it is new * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ @Override public Object put(final Object key, final Object value) { final String strKey = String.valueOf(key); final Object old = configuration.getProperty(strKey); configuration.setProperty(strKey, value); return old; }
/** * Set System properties from a configuration object. * @param systemConfig The configuration containing the properties to be set. * @since 1.6 */ public static void setSystemProperties(final Configuration systemConfig) { final Iterator<String> iter = systemConfig.getKeys(); while (iter.hasNext()) { final String key = iter.next(); final String value = (String) systemConfig.getProperty(key); if (log.isDebugEnabled()) { log.debug("Setting system property " + key + " to " + value); } System.setProperty(key, value); } }
/** * Tests whether the given name references an indexed property. This * implementation tests for properties of type list or array. If the * property does not exist, an exception is thrown. * * @param name the name of the property to check * @return a flag whether this is an indexed property * @throws IllegalArgumentException if the property does not exist */ private boolean checkIndexedProperty(final String name) { final Object property = getConfiguration().getProperty(name); if (property == null) { throw new IllegalArgumentException("Property '" + name + "' does not exist."); } return (property instanceof List) || property.getClass().isArray(); } }
@Override public Object get(final String name, final String key) { final Configuration subset = getConfiguration().subset(name); if (subset == null) { throw new IllegalArgumentException("Mapped property '" + name + "' does not exist."); } return subset.getProperty(key); }
/** * Read property from underlying composite * * @param key key to use for mapping * * @return object associated with the given configuration key. */ @Override protected Object getPropertyInternal(final String key) { Configuration firstMatchingConfiguration = null; for (final Configuration config : configList) { if (config.containsKey(key)) { firstMatchingConfiguration = config; break; } } if (firstMatchingConfiguration != null) { return firstMatchingConfiguration.getProperty(key); } return null; }
final Object value = a.getProperty(key); if (!value.equals(b.getProperty(key))) final Object value = b.getProperty(key); if (!value.equals(a.getProperty(key)))
/** * Adds the value of a property to the given list. This method is used by * {@code getList()} for gathering property values from the child * configurations. * * @param dest the list for collecting the data * @param config the configuration to query * @param key the key of the property */ private void appendListProperty(final List<Object> dest, final Configuration config, final String key) { final Object value = interpolate(config.getProperty(key)); if (value != null) { if (value instanceof Collection) { final Collection<?> col = (Collection<?>) value; dest.addAll(col); } else { dest.add(value); } } } }
@Override public Object get(final String name) { if (LOG.isTraceEnabled()) { LOG.trace("get(" + name + ")"); } // get configuration property Object result = getConfiguration().getProperty(name); if (result == null) { // otherwise attempt to create bean from configuration subset final Configuration subset = new SubsetConfiguration(getConfiguration(), name, PROPERTY_DELIMITER); if (!subset.isEmpty()) { result = new ConfigurationDynaBean(subset); } } if (LOG.isDebugEnabled()) { LOG.debug(name + "=[" + result + "]"); } if (result == null) { throw new IllegalArgumentException("Property '" + name + "' does not exist."); } return result; }
@Override public void set(final String name, final int index, final Object value) { if (!checkIndexedProperty(name) && index > 0) { throw new IllegalArgumentException("Property '" + name + "' is not indexed."); } final Object property = getConfiguration().getProperty(name); if (property instanceof List) { // This is safe because multiple values of a configuration property // are always stored as lists of type Object. @SuppressWarnings("unchecked") final List<Object> list = (List<Object>) property; list.set(index, value); getConfiguration().setProperty(name, list); } else if (property.getClass().isArray()) { Array.set(property, index, value); } else if (index == 0) { getConfiguration().setProperty(name, value); } }
closeElements(keyLast, keyAct); final String elem = openElements(keyLast, keyAct, config, keySet); fireValue(elem, config.getProperty(key)); keyLast = keyAct;
final Object value = encodeForCopy(c.getProperty(key)); addProperty(key, value);
final Object value = encodeForCopy(c.getProperty(key)); setProperty(key, value);
/** * Fires all necessary element start events for the specified key. This * method is called for each key obtained from the configuration to be * converted. It ensures that all elements "between" the last key and the * actual key are opened and their values are set. * * @param keyLast the last processed key * @param keyAct the actual key * @param config the configuration to process * @param keySet the set with the processed keys * @return the name of the last element on the path */ protected String openElements(final DefaultConfigurationKey keyLast, final DefaultConfigurationKey keyAct, final Configuration config, final Set<String> keySet) { final DefaultConfigurationKey.KeyIterator it = keyLast.differenceKey(keyAct).iterator(); final DefaultConfigurationKey k = keyLast.commonKey(keyAct); for (it.nextKey(); it.hasNext(); it.nextKey()) { k.append(it.currentKey(true)); elementStart(it.currentKey(true), config.getProperty(k.toString())); keySet.add(k.toString()); } return it.currentKey(true); }