List of usage examples for org.apache.commons.configuration.tree ConfigurationNode setValue
void setValue(Object val);
From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java
/** * Constructs the internal configuration nodes hierarchy. * * @param node The configuration node that is the root of the current configuration section. * @param map The map with the yaml configurations nodes, i.e. String -> Object. *//* www.j a va 2 s .co m*/ @SuppressWarnings("unchecked") private void constructHierarchy(ConfigurationNode node, Map<String, Object> map) { for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Map) { ConfigurationNode treeNode = createNode(key); constructHierarchy(treeNode, (Map) value); node.addChild(treeNode); } else { ConfigurationNode leaveNode = createNode(key); leaveNode.setValue(value); node.addChild(leaveNode); } } }
From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java
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())); }/*from w w w . j a v a 2 s . co m*/ 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); }
From source file:org.lable.oss.dynamicconfig.serialization.yaml.YamlDeserializer.java
/** * Process a node in the object tree, and store it with its parent node in the Config tree. * <p>/* ww w . j a va 2s . co m*/ * This method recursively calls itself to walk an object tree. * * @param parent Parent of the current node, as represented in the Config tree. * @param node Node to process. */ void traverseTreeAndLoad(ConfigurationNode parent, Object node) { if (node instanceof Map<?, ?>) { // It is not feasible for this class to check this cast, but it is guaranteed by the // yaml.load() call that it is a Map<String, Object>. @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) node; for (Map.Entry<String, Object> entry : map.entrySet()) { HierarchicalConfiguration.Node child = new HierarchicalConfiguration.Node(entry.getKey()); child.setReference(entry); // Walk the complete tree. traverseTreeAndLoad(child, entry.getValue()); parent.addChild(child); } } else { // This works for both primitives and lists. parent.setValue(node); } }