/** * Gets all properties that start with the given {@code fullPrefix}, stripping off * the prefix in the returned map. */ protected Map<String, Object> getMatchingProperties(String fullPrefix, Map<String, ?> properties) { return ConfigUtils.filterForPrefixAndStrip(properties, fullPrefix).asMapWithStringKeys(); }
@Override public String apply(HasConfigKey<?> input) { return input.getConfigKey().getName(); } }));
@Override public <T> T getConfig(HasConfigKey<T> key) { return getConfig(key.getConfigKey(), null); }
@Override public <T> T getConfig(ConfigKey<T> key, T defaultValue) { if (!containsKey(key.getName())) { if (defaultValue!=null) return defaultValue; return key.getDefaultValue(); } Object value = get(key.getName()); if (value==null) return null; // no evaluation / key extraction here return TypeCoercions.coerce(value, key.getTypeToken()); }
public static BrooklynProperties filterFor(BrooklynProperties properties, Predicate<? super String> filter) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); for (String k: (Collection<String>)properties.keySet()) { if (filter.apply(k)) { result.put(k, properties.get(k)); } } return result; }
/** * Gets all properties that start with the given {@code fullPrefix}, stripping off * the prefix in the returned map. * * Returns only those properties whose key suffix is a single word (i.e. contains no dots). * We do this special (sub-optimal!) filtering because we want sub-scoped things * (e.g. could want brooklyn.location.privateKeyFile, but not brooklyn.location.named.*). */ protected Map<String, Object> getMatchingSingleWordProperties(String fullPrefix, Map<String, ?> properties) { BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, fullPrefix); return ConfigUtils.filterFor(filteredProperties, Predicates.not(Predicates.containsPattern("\\."))).asMapWithStringKeys(); }
public final static boolean hasNoSecurityOptions(ConfigMap config) { return config.submap(ConfigPredicates.startingWith(BrooklynWebConfig.BASE_NAME_SECURITY)).isEmpty(); }
/** inserts the value under the given key, if it was not present */ public boolean putIfAbsent(String key, Object value) { if (containsKey(key)) return false; put(key, value); return true; }
@Override public <T> T getConfig(ConfigKey<T> key) { return getConfig(key, null); }
/** expects a property already set in scope, whose value is acceptable to {@link #addFromUrl(String)}; * if property not set, does nothing */ public BrooklynProperties addFromUrlProperty(String urlProperty) { String url = (String) get(urlProperty); if (url==null) addFromUrl(url); return this; }
/** * Creates a LocalManagement with default BrooklynProperties. */ public LocalManagementContext() { this(BrooklynProperties.Factory.newDefault()); }
@Override public synchronized Object put(Object key, Object value) { // ugly way to load them in order // (Properties is a hashtable so loses order otherwise) return BrooklynProperties.this.put(key, value); } };
/** * adds the indicated properties */ @SuppressWarnings("unchecked") public BrooklynProperties addFromMap(Map properties) { putAll(properties); return this; }
@Override public String toString() { return "BrooklynProperties["+size()+"]"; }
/** like normal map.put, except config keys are dereferenced on the way in */ @SuppressWarnings("unchecked") public Object put(Object key, Object value) { if (key instanceof HasConfigKey) key = ((HasConfigKey)key).getConfigKey().getName(); if (key instanceof ConfigKey) key = ((ConfigKey)key).getName(); return super.put(key, value); }
@Override public <T> T getConfig(HasConfigKey<T> key, T defaultValue) { return getConfig(key.getConfigKey(), defaultValue); }
public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); for (String k: (Collection<String>)properties.keySet()) { if (k.startsWith(prefix)) { result.put(k, properties.get(k)); } } return result; }
@SuppressWarnings("unchecked") public <T> Object put(HasConfigKey<T> key, T value) { return super.put(key.getConfigKey().getName(), value); }