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

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

Introduction

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

Prototype

public Map<String, Object> getAttributes() 

Source Link

Document

Returns a map with the attributes 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 {/*  www  .ja v  a 2  s .  c  o  m*/
            return node.getValue();
        }
    } else {
        return constructMap(node);
    }
}

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

private Map<String, Object> constructMap(ImmutableNode node) {
    final Map<String, Object> map = new HashMap<>(node.getChildren().size());
    map.putAll(node.getAttributes());

    MutableListMultimap<String, ImmutableNode> nodesByName = ListAdapter.adapt(node.getChildren())
            .groupBy(new Function<ImmutableNode, String>() {
                @Override/*  www. j  a v  a2 s .co  m*/
                public String valueOf(ImmutableNode immutableNode) {
                    return immutableNode.getNodeName();
                }
            });
    nodesByName.forEachKeyMultiValues(new Procedure2<String, Iterable<ImmutableNode>>() {
        @Override
        public void value(String nodeName, Iterable<ImmutableNode> nodeIterable) {
            //            System.out.println("At node " + cNode.getNodeName() + " and attrs " + cNode.getAttributes() + " and value " + cNode.getValue() + " and children " + cNode.getChildren());
            MutableList<ImmutableNode> nodes = CollectionAdapter.wrapList(nodeIterable);
            if (nodes.size() > 1) {
                map.put(nodeName, nodes.collect(new Function<ImmutableNode, Object>() {
                    @Override
                    public Object valueOf(ImmutableNode node1) {
                        return DbEnvironmentXmlEnricherTest.this.getNodeValue(node1);
                    }
                }));
            } else {
                map.put(nodeName, DbEnvironmentXmlEnricherTest.this.getNodeValue(nodes.getFirst()));
            }
        }
    });
    return map;
}