void registerChild(ConfigElement element) { Preconditions.checkNotNull(element); Preconditions.checkArgument(element.getNamespace()==this,"Configuration element registered with wrong namespace"); Preconditions.checkArgument(!children.containsKey(element.getName()), "A configuration element with the same name has already been added to this namespace: %s",element.getName()); children.put(element.getName(),element); }
public static String toString(ConfigElement element) { String result = element.getName(); if (element.isNamespace()) { result = "+ " + result; if (((ConfigNamespace)element).isUmbrella()) result += " [*]"; } else { result = "- " + result; ConfigOption option = (ConfigOption)element; result+= " ["; switch (option.getType()) { case FIXED: result+="f"; break; case GLOBAL_OFFLINE: result+="g!"; break; case GLOBAL: result+="g"; break; case MASKABLE: result+="m"; break; case LOCAL: result+="l"; break; } result+=","+option.getDatatype().getSimpleName(); result+=","+option.getDefaultValue(); result+="]"; } result = result + "\n"; String desc = element.getDescription(); result+="\t"+'"'+desc.substring(0, Math.min(desc.length(), 50))+'"'; return result; }
public static String getPath(ConfigElement element, boolean includeRoot, String... umbrellaElements) { Preconditions.checkNotNull(element); if (umbrellaElements==null) umbrellaElements = new String[0]; StringBuilder path = new StringBuilder(element.getName()); int umbrellaPos = umbrellaElements.length-1; while (!element.isRoot() && !element.getNamespace().isRoot()) { ConfigNamespace parent = element.getNamespace(); if (parent.isUmbrella()) { Preconditions.checkArgument(umbrellaPos>=0,"Missing umbrella element path for element: %s",element); String umbrellaName = umbrellaElements[umbrellaPos]; Preconditions.checkArgument(!StringUtils.containsAny(umbrellaName,ILLEGAL_CHARS),"Invalid umbrella name provided: %s. Contains illegal chars",umbrellaName); path.insert(0, umbrellaName + SEPARATOR); umbrellaPos--; } path.insert(0, parent.getName() + SEPARATOR); element = parent; } if (includeRoot) { // Assumes that roots are not umbrellas // If roots could be umbrellas, we might have to change the interpretation of umbrellaElements path.insert(0, (element.isRoot() ? element.getName() : element.getNamespace().getName()) + SEPARATOR); } //Don't make this check so that we can still access more general config items Preconditions.checkArgument(umbrellaPos<0,"Found unused umbrella element: %s",umbrellaPos<0?null:umbrellaElements[umbrellaPos]); return path.toString(); }