public static ConfigKey<String> javaSysProp(String propertyName) { return UsesJava.JAVA_SYSPROPS.subKey(propertyName); }
public boolean isSubKey(ConfigKey<?> contender) { return (contender instanceof SubElementConfigKey && this.equals(((SubElementConfigKey<?>) contender).parent)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object applyEntryValueToMap(Entry value, Map target) { Object k = value.getKey(); if (isSubKey(k)) { // do nothing } else if (k instanceof String) { k = subKey((String)k); } else { log.warn("Unexpected subkey "+k+" being inserted into "+this+"; ignoring"); k = null; } if (k!=null) return target.put(k, value.getValue()); else return null; }
/** returns the entries in the map against this config key and any sub-config-keys, without resolving * (like {@link #extractValue(Map, ExecutionContext)} but without resolving/coercing; * useful because values in this "map" are actually stored against {@link SubElementConfigKey}s */ public Map<String,Object> rawValue(Map<?,?> vals) { Map<String,Object> result = Maps.newLinkedHashMap(); for (Map.Entry<?,?> entry : vals.entrySet()) { Object k = entry.getKey(); if (isSubKey(k)) { @SuppressWarnings("unchecked") SubElementConfigKey<V> subk = (SubElementConfigKey<V>) k; result.put(extractSubKeyName(subk), vals.get(subk)); } } return result; }
@SuppressWarnings("rawtypes") @Override public Object applyToKeyInMap(MapConfigKey<V> key, Map target) { return key.applyValueToMap(Jsonya.of(key.rawValue(target)).add(this).getRootMap(), target); } };
public String extractSubKeyName(ConfigKey<?> subKey) { return subKey.getName().substring(getName().length() + 1); }
public boolean isSubKey(Object contender) { return contender instanceof ConfigKey && isSubKey((ConfigKey<?>)contender); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object applyValueToMap(Object value, Map target) { if (value == null) return null; if (value instanceof StructuredModification) return ((StructuredModification)value).applyToKeyInMap(this, target); if (value instanceof Map.Entry) return applyEntryValueToMap((Map.Entry)value, target); if (!(value instanceof Map)) throw new IllegalArgumentException("Cannot set non-map entries "+value+" on "+this); Map result = new MutableMap(); for (Object entry: ((Map)value).entrySet()) { Map.Entry entryT = (Map.Entry)entry; result.put(entryT.getKey(), applyEntryValueToMap(entryT, target)); } return result; }
@SuppressWarnings({ "rawtypes" }) @Override public Object applyToKeyInMap(MapConfigKey<V> key, Map target) { if (clearFirst) { StructuredModification<StructuredConfigKey> clearing = StructuredModifications.clearing(); clearing.applyToKeyInMap(key, target); } return key.applyValueToMap(new LinkedHashMap<String,V>(this), target); } }
@Override public Map<String,V> extractValue(Map<?,?> vals, ExecutionContext exec) { Map<String,V> result = Maps.newLinkedHashMap(); for (Map.Entry<?,?> entry : vals.entrySet()) { Object k = entry.getKey(); if (isSubKey(k)) { @SuppressWarnings("unchecked") SubElementConfigKey<V> subk = (SubElementConfigKey<V>) k; result.put(extractSubKeyName(subk), (V) subk.extractValue(vals, exec)); } } return Collections.unmodifiableMap(result); } /** returns the entries in the map against this config key and any sub-config-keys, without resolving
public ConfigKey<V> subKey(String subName, String description) { return new SubElementConfigKey<V>(this, subType, getName() + "." + subName, description, null); }
@Override public boolean isSet(Map<?, ?> vals) { if (vals.containsKey(this)) return true; for (Object contender : vals.keySet()) { if (isSubKey(contender)) { return true; } } return false; }
/** replaces the attributes underneath the rootAttribute parameter with the given value; * see {@link #addLaunchAttributesMap(EntitySpec, Map)} for richer functionality */ public static void setLaunchAttribute(EntityInternal entity, String rootAttribute, Object value) { entity.setConfig(ChefSoloDriver.CHEF_LAUNCH_ATTRIBUTES.subKey(rootAttribute), value); }
public static void addToCookbooksFromGithub(EntitySpec<?> entity, String cookbookName, String cookbookUrl) { entity.configure(ChefSoloDriver.CHEF_COOKBOOKS.subKey(cookbookName), cookbookUrl); }
/** replaces the attributes underneath the rootAttribute parameter with the given value; * see {@link #addLaunchAttributesMap(EntitySpec, Map)} for richer functionality */ public static void setLaunchAttribute(EntitySpec<?> entity, String rootAttribute, Object value) { entity.configure(ChefSoloDriver.CHEF_LAUNCH_ATTRIBUTES.subKey(rootAttribute), value); }
public static void addToCookbooksFromGithub(EntityInternal entity, String cookbookName, String cookbookUrl) { entity.setConfig(ChefSoloDriver.CHEF_COOKBOOKS.subKey(cookbookName), cookbookUrl); }