Example usage for org.apache.commons.configuration.tree ConfigurationNode getChildrenCount

List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getChildrenCount

Introduction

In this page you can find the example usage for org.apache.commons.configuration.tree ConfigurationNode getChildrenCount.

Prototype

int getChildrenCount();

Source Link

Document

Returns the number of this node's children.

Usage

From source file:com.aol.advertising.qiao.util.XmlConfigUtil.java

public static void walkTree(ConfigurationNode node) {
    if (node != null) {
        logger.info("node name=" + node.getName() + ", #childrens=" + node.getChildrenCount());
        List<ConfigurationNode> childrens = node.getChildren();
        for (ConfigurationNode sub : childrens)
            walkTree(sub);//from w  w w  .  j  a v  a2 s .c  o m
    }
}

From source file:au.org.intersect.dms.instrument.harvester.WindowsIniLogParser.java

private Map<String, Object> parseFields(String sectionName, Map<String, Object> sectionMap,
        ConfigurationNode node) {
    if (node.getReference() == null && node.getChildrenCount() == 0) {
        String sectionProperty = sectionName + "." + node.getName();

        if ((mode == Mode.EXCLUSION && !findMatch(sectionProperty.trim()))
                || (mode == Mode.INCLUSION && findMatch(sectionProperty.trim()))) {

            String name = node.getName();
            String value = node.getValue().toString();
            MetadataField field = mapField(name, value);
            value = convertPropertyValue(sectionProperty, field.getValue());
            sectionMap.put(AbstractHarvester.toXML(field.getName()), AbstractHarvester.toXML(value));
        }/*from   w ww  .  j  av  a  2  s  .c om*/
    }
    return sectionMap;
}

From source file:com.gamma.dam.conf.db.DBConfig.java

/**
 * Parses the./*w  ww.j a v  a 2  s.c  om*/
 *
 * @param node the node
 */
public void parse(ConfigurationNode node) {
    if (node.getChildrenCount() > 0) {
        for (ConfigurationNode n : node.getChildren()) {
            String name = n.getName();
            String val = (String) n.getValue();
            switch (name) {
            case "host":
                setHost(val);
                break;
            case "port":
                setPort(val);
                break;
            case "database":
                setDatabase(val);
                break;
            case "username":
                setUsername(val);
                break;
            case "password":
                setPassword(val);
                break;
            case "driver":
                setDriver(val);
                break;
            case "idleMaxAgeInMinutes":
                setIdleMaxAgeInMinutes(val);
                break;
            case "idleConnectionTestPeriodInMinutes":
                setIdleConnectionTestPeriodInMinutes(val);
                break;
            case "maxConnectionsPerPartition":
                setMaxConnectionsPerPartition(val);
                break;
            case "minConnectionsPerPartition":
                setMinConnectionsPerPartition(val);
                break;
            case "partitionCount":
                setPartitionCount(val);
                break;
            case "acquireIncrement":
                setAcquireIncrement(val);
                break;
            case "statementsCacheSize":
                setStatementsCacheSize(val);
                break;
            default:
                break;
            }
        }
    }
}

From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java

/**
 * Constructs a YAML map, i.e. String -> Object from a given
 * configuration node.// w  w w. j a  va  2s .  c  o  m
 *
 * @param node The configuration node to create a map from.
 * @return A Map that contains the configuration node information.
 */
public Map<String, Object> constructMap(ConfigurationNode node) {
    Map<String, Object> map = new HashMap<>(node.getChildrenCount());
    for (ConfigurationNode cNode : node.getChildren()) {
        if (cNode.getChildren().isEmpty()) {
            map.put(cNode.getName(), cNode.getValue());
        } else {
            map.put(cNode.getName(), constructMap(cNode));
        }
    }
    return map;
}

From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java

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 {// www  .j  a va  2s  . c o  m
        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;
    }
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * add the structure of root to prop/*ww w.ja  va  2 s  . c  o m*/
 */
private ConfigurationProperty getConfiguration(ConfigurationNode root, Module m,
        ConfigurationNamespace namespace) throws Exception {
    String originMod;
    boolean originOk = true;
    ConfigurationProperty cp = new ConfigurationProperty(m, root.getName());
    cp.setNamespace(namespace);
    String value = (String) root.getValue();
    boolean mutable = true;
    if (value != null && !value.equals("")) {
        cp.setValue(value);
    }

    if (root.getChildrenCount() != 0) {
        Iterator it = root.getChildren().iterator();
        while (it.hasNext()) {
            ConfigurationNode child = (ConfigurationNode) it.next();
            ConfigurationProperty nextProp = getConfiguration(child, m, namespace);
            if (nextProp == null) {
                if (_isDebugging) {
                    _log.debug("not loading property " + child.getName()
                            + " because it was added from an inactive module.");
                }
                continue;
            }

            if (nextProp.getName().equals("mutable")) {
                if (nextProp.getValue() != null && nextProp.getValue().equals("false")) {
                    cp.setMutable(false);
                }
            } else if (nextProp.getName().equals("originModule")) {
                if (nextProp.getValue() != null && !nextProp.getValue().equals("")) {
                    originMod = nextProp.getValue();
                    if (!ModuleTree.instance().contains(originMod)) {
                        originOk = false;
                    } else {
                        cp.setOriginModule(ConfigurationManager.getModule(originMod));
                    }
                }
            }

            cp.addProperty(nextProp, true);
        }
    }

    if (originOk) {
        return cp;
    } else {
        return null;
    }
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.Objectifier.java

/**
 * Process a node in the Config tree, and store it with its parent node in an object tree.
 * <p>/*ww  w  .j  a  v  a  2  s .c om*/
 * This method recursively calls itself to walk a Config tree.
 *
 * @param parent Parent of the current node, as represented in the Config tree.
 * @return An object tree.
 */
public static Object traverseTreeAndEmit(ConfigurationNode parent) {
    if (parent.getChildrenCount() == 0) {
        return parent.getValue();
    } else {
        Map<String, Object> map = new LinkedHashMap<>();
        for (Object o : parent.getChildren()) {
            ConfigurationNode child = (ConfigurationNode) o;
            String nodeName = child.getName();
            addToMap(map, nodeName, traverseTreeAndEmit(child));
        }
        return map;
    }
}