protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) { final String parentName = parentNode.getName(); if (obj instanceof Map<?, ?>) { for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) { final Node childNode = new Node(entry.getKey()); // if parent node is look like "tableS", "userS" or "groupS" if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) { //this is done to have "users.user[@name='smith'] instead of "users.smith" childNode.setName(parentName.substring(0, parentName.length() - 1)); childNode.addAttribute(new Node("name", entry.getKey())); } childNode.setReference(entry); loadHierarchy(childNode, entry.getValue()); parentNode.addChild(childNode); } } else if (obj instanceof Collection) { for (Object child : (Collection) obj) { final Node childNode = new Node("item"); childNode.setReference(child); loadHierarchy(childNode, child); parentNode.addChild(childNode); } } parentNode.setValue(obj); }
/** * Checks if a node is a list node. This implementation tests if the given * node name is contained in the set of known list nodes. Derived classes * which use different criteria may overload this method. * * @param node the node to be tested * @return a flag whether this is a list node */ public boolean isListNode(ConfigurationNode node) { return listNodes.contains(node.getName()); }
/** * Checks if a node is a list node. This implementation tests if the given * node name is contained in the set of known list nodes. Derived classes * which use different criteria may overload this method. * * @param node the node to be tested * @return a flag whether this is a list node */ public boolean isListNode(ConfigurationNode node) { return listNodes.contains(node.getName()); }
/** * Extracts the array with the node names from the given node list. * * @param nodes the list with the nodes * @return an array with the node names */ private String[] initNodeNames(List<ConfigurationNode> nodes) { String[] names = new String[nodes.size() - 1]; for (int i = 0; i < names.length; i++) { names[i] = nodes.get(i + 1).getName(); } return names; }
/** * Returns this node's name. * * @return the name */ @Override public QName getName() { return new QName(null, node.getName()); }
/** * Check if the configuration is of the indicated type. This means that the root node has the name * of the component, e.g. fileStore, mysql or whatever. * * @param name * @return */ public boolean isA(String name) { String x = getConfig().getName(); if (x == null || x.length() == 0) return false; return x.equals(name); }
/** * Returns this node's name. * * @return the name */ @Override public QName getName() { return new QName(null, node.getName()); }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals("messages")) { setConfig(cfgEvent.getConfiguration()); return true; } return false; }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals("myproxy")) { setConfig(cfgEvent.getConfiguration()); return true; } return false; }
private void populateAlternateKeyMap(HierarchicalConfiguration config) { List<SubnodeConfiguration> configurationsAt = config.configurationsAt("/*/" + ALTERNATE_KEY); alternateKeysMap = new HashMap<>(configurationsAt.size()); for (SubnodeConfiguration node : configurationsAt) { String rootKey = node.getRootNode() .getParentNode().getName(); String[] alternateKeys = config.getStringArray("/" + rootKey + "/" + ALTERNATE_KEY); for (String token : alternateKeys) { alternateKeysMap.put(token, rootKey); } } }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals(MAIL)) { setConfig(cfgEvent.getConfiguration()); return true; } return false; }
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
/** * Returns a map with the bean's (simple) properties. The properties are * collected from all attribute nodes, which are not reserved. * * @return a map with the bean's properties */ public Map<String, Object> getBeanProperties() { Map<String, Object> props = new HashMap<String, Object>(); for (ConfigurationNode attr : getNode().getAttributes()) { if (!isReservedNode(attr)) { props.put(attr.getName(), interpolate(attr .getValue())); } } return props; }
public static boolean iterateAllKeys(ConfigKeyFactory factory, HierarchicalConfiguration config, ConfigKeyHandler handler) { List<ConfigurationNode> configNodes = config.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = factory.generateByPropertiesKey(node.getName()); if (!handler.handle(key)) { return true; } } return false; }
/** * Prints all configuration values. Is the actual execution of the 'get-all' action ('-a', '--all') */ private void printAllValues() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); // TODO - move to one statement for all - time permitting; try { printAllValuesForKey(key.getKey()); } catch (Exception exception) { log.error("Error while retrieving value for key \"{}\".", key.getKey(), exception); } } }
@Override protected boolean checkEvent(CfgEvent cfgEvent) { if (cfgEvent.getConfiguration().getName().equals(getType()) && !cfgEvent.getConfiguration().getChildren(getTarget()).isEmpty()) { setTypeConfig(cfgEvent.getConfiguration()); setConfig((ConfigurationNode) cfgEvent.getConfiguration().getChildren(getTarget()).get(0)); return true; } return false; }
/** * Prints all reloadable configuration keys. Is the actual execution of the 'list' action ('-l', '--list') with the * --only-reloadable flag */ public void printReloadableKeys() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); if (key.isReloadable()) { printKeyInFormat(key); } } }
protected void printNodes(ConfigurationNode root) { for (Object kid : root.getChildren()) { ConfigurationNode cn = (ConfigurationNode) kid; say("key=" + cn.getName() + ", value=" + cn.getValue()); printNodes(cn); } }