Example usage for org.apache.commons.configuration2.tree ImmutableNode getValue

List of usage examples for org.apache.commons.configuration2.tree ImmutableNode getValue

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.tree ImmutableNode getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns the value of this node.

Usage

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricherTest.java

private Object getNodeValue(ImmutableNode node) {
    if (node.getChildren().isEmpty()) {
        if (node.getAttributes() != null && !node.getAttributes().isEmpty()) {
            return constructMap(node);
        } else {//  w  w  w.j  a v a  2s  . co m
            return node.getValue();
        }
    } else {
        return constructMap(node);
    }
}

From source file:com.virtlink.commons.configuration2.jackson.JacksonConfiguration.java

/**
 * Gets a serialization object from a node.
 *
 * @param node The node./*from  w w  w  .  j  a  v a 2s .  c o  m*/
 * @return The object representing the node.
 */
private Object fromNode(final ImmutableNode node) {
    if (!node.getChildren().isEmpty()) {
        final Map<String, List<ImmutableNode>> children = getChildrenWithName(node);

        final HashMap<String, Object> map = new HashMap<>();
        for (final Map.Entry<String, List<ImmutableNode>> entry : children.entrySet()) {
            assert !entry.getValue().isEmpty();
            if (entry.getValue().size() == 1) {
                // Just one node.
                final ImmutableNode child = entry.getValue().get(0);
                final Object childValue = fromNode(child);
                map.put(entry.getKey(), childValue);
            } else {
                // Multiple nodes.
                final ArrayList<Object> list = new ArrayList<>();
                for (final ImmutableNode child : entry.getValue()) {
                    final Object childValue = fromNode(child);
                    list.add(childValue);
                }
                map.put(entry.getKey(), list);
            }
        }
        return map;
    } else {
        return node.getValue();
    }
}