Example usage for org.apache.commons.configuration HierarchicalConfiguration configurationsAt

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration configurationsAt

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration configurationsAt.

Prototype

public List configurationsAt(String key) 

Source Link

Document

Returns a list of sub configurations for all configuration nodes selected by the given key.

Usage

From source file:org.onosproject.drivers.utilities.YangXmlUtils.java

/**
 * Reads a valid XML configuration and returns a Map containing XML field name.
 * and value contained for every subpath.
 *
 * @param cfg the Configuration to read.
 * @param path path of the information to be read.
 * @return list of elements containing baskey and map of key value pairs.
 *//*from www.  j ava  2s .co  m*/
public List<YangElement> readXmlConfiguration(HierarchicalConfiguration cfg, String path) {
    List<YangElement> elements = new ArrayList<>();

    String key = nullIsNotFound(findPath(cfg, path), "Configuration does not contain desired path");

    getElements(cfg.configurationsAt(key), elements, key, cfg, path, key);
    return ImmutableList.copyOf(elements);
}

From source file:org.onosproject.drivers.utilities.YangXmlUtils.java

private void getElements(List<HierarchicalConfiguration> configurations, List<YangElement> elements,
        String basekey, HierarchicalConfiguration originalCfg, String path, String originalKey) {
    //consider each sub configuration
    configurations.forEach(config -> {

        YangElement element = new YangElement(path, new HashMap<>());
        //for each of the keys of the sub configuration
        config.getKeys().forEachRemaining(key -> {
            //considers only one step ahead
            //if one step ahead has other steps calls self to analize them
            //else adds to yang element.
            if (key.split("\\.").length > 1) {
                getElements(originalCfg.configurationsAt(basekey + "." + key.split("\\.")[0]), elements,
                        basekey + "." + key.split("\\.")[0], originalCfg, path, originalKey);
            } else {
                String replaced = basekey.replace(originalKey, "");
                String partialKey = replaced.isEmpty() ? key : replaced.substring(1) + "." + key;
                partialKey = partialKey.isEmpty() ? originalKey : partialKey;
                //Adds values to the element with a subkey starting from the requeste path onwards
                element.getKeysAndValues().put(partialKey, config.getProperty(key).toString());
            }/* www .ja va 2s.  c om*/
        });
        //if the element doesnt already exist
        if (!elements.contains(element) && !element.getKeysAndValues().isEmpty()) {
            elements.add(element);
        }
    });
}

From source file:org.onosproject.net.driver.XmlDriverLoader.java

/**
 * Loads a driver provider from the supplied hierarchical configuration.
 *
 * @param driversCfg hierarchical configuration containing the drivers definitions
 * @param resolver   driver resolver//from   w  w w  .  ja v  a  2  s  . com
 * @return driver provider
 */
public DefaultDriverProvider loadDrivers(HierarchicalConfiguration driversCfg, DriverResolver resolver) {
    DefaultDriverProvider provider = new DefaultDriverProvider();
    for (HierarchicalConfiguration cfg : driversCfg.configurationsAt(DRIVER)) {
        DefaultDriver driver = loadDriver(cfg, resolver);
        drivers.put(driver.name(), driver);
        provider.addDriver(driver);
    }
    drivers.clear();
    return provider;
}

From source file:org.onosproject.net.driver.XmlDriverLoader.java

private Map<Class<? extends Behaviour>, Class<? extends Behaviour>> parseBehaviours(
        HierarchicalConfiguration driverCfg) {
    ImmutableMap.Builder<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = ImmutableMap
            .builder();//from  w w w. j ava 2  s .  c  o m
    for (HierarchicalConfiguration b : driverCfg.configurationsAt(BEHAVIOUR)) {
        behaviours.put(getClass(b.getString(API)), getClass(b.getString(IMPL)));
    }
    return behaviours.build();
}

From source file:org.onosproject.net.driver.XmlDriverLoader.java

private Map<String, String> parseProperties(HierarchicalConfiguration driverCfg) {
    ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
    for (HierarchicalConfiguration b : driverCfg.configurationsAt(PROPERTY)) {
        properties.put(b.getString(NAME), (String) b.getRootNode().getValue());
    }/*from   ww w.j  ava  2 s .  c o m*/
    return properties.build();
}

From source file:org.pivot4j.ui.AbstractPivotRenderer.java

/**
 * @see org.pivot4j.state.Configurable#restoreSettings(org.apache.commons.configuration.HierarchicalConfiguration)
 *//*from  w  w w  .  ja v  a2 s .com*/
@Override
public void restoreSettings(HierarchicalConfiguration configuration) {
    if (configuration == null) {
        throw new NullArgumentException("configuration");
    }

    this.drillDownMode = configuration.getString("drillDown[@mode]", DrillDownCommand.MODE_POSITION);
    this.enableDrillDown = configuration.getBoolean("drillDown[@enabled]", true);
    this.enableSort = configuration.getBoolean("sort[@enabled]", true);

    // TODO Need to support a custom implementation.
    String sortModeName = configuration.getString("sort[@mode]", SortMode.BASIC.getName());

    this.sortMode = SortMode.fromName(sortModeName);

    if (sortMode == null) {
        Logger logger = LoggerFactory.getLogger(getClass());
        if (logger.isWarnEnabled()) {
            logger.warn("Ignoring unknown sort mode name : {}", sortModeName);
        }

        this.sortMode = SortMode.BASIC;
    }

    this.enableDrillThrough = configuration.getBoolean("drillThrough[@enabled]", false);

    List<HierarchicalConfiguration> aggregationSettings = configuration
            .configurationsAt("aggregations.aggregation");

    this.aggregatorNames.clear();

    for (HierarchicalConfiguration aggConfig : aggregationSettings) {
        String name = aggConfig.getString("[@name]");

        if (name != null) {
            Axis axis = Axis.Standard.valueOf(aggConfig.getString("[@axis]"));

            AggregatorPosition position = AggregatorPosition.valueOf(aggConfig.getString("[@position]"));

            AggregatorKey key = new AggregatorKey(axis, position);

            List<String> names = aggregatorNames.get(key);

            if (names == null) {
                names = new LinkedList<String>();
                aggregatorNames.put(key, names);
            }

            if (!names.contains(name)) {
                names.add(name);
            }
        }
    }

    initializeRenderProperties();

    for (String category : getRenderPropertyCategories()) {
        RenderPropertyList properties = renderProperties.get(category);

        if (properties != null) {
            try {
                properties.restoreSettings(configuration.configurationAt("properties." + category));
            } catch (IllegalArgumentException e) {
            }
        }
    }

    this.renderSlicer = configuration.getBoolean("filter[@visible]", false);

    String collectorType = configuration.getString("propertyCollector[@type]");

    // TODO At this time, we're not sure how to make property collector
    // configurable. So, let's just treat it as a read-only property.
    if ("non-internal".equalsIgnoreCase(collectorType)) {
        this.propertyCollector = new NonInternalPropertyCollector();
    } else {
        this.propertyCollector = null;
    }
}

From source file:org.pivot4j.ui.property.DefaultRenderPropertyList.java

/**
 * @see org.pivot4j.state.Configurable#restoreSettings(org.apache.commons.configuration.HierarchicalConfiguration)
 *//* w  w  w. j a va2  s  . co  m*/
@Override
public void restoreSettings(HierarchicalConfiguration configuration) {
    this.properties.clear();

    try {
        List<HierarchicalConfiguration> configurations = configuration.configurationsAt("property");

        for (HierarchicalConfiguration propertyConfig : configurations) {
            boolean conditional = propertyConfig.containsKey("conditions");

            RenderProperty property;

            // TODO Need more robust method to determine property types.
            if (conditional) {
                property = new ConditionalRenderProperty(conditionFactory);
            } else {
                property = new SimpleRenderProperty();
            }

            property.restoreSettings(propertyConfig);

            this.properties.put(property.getName(), property);
        }
    } catch (IllegalArgumentException e) {
    }
}

From source file:org.topology.bgp_ls.config.nodes.impl.AddressFamilyRoutingPeerConfigurationParser.java

private HierarchicalConfiguration first(HierarchicalConfiguration config, String key)
        throws ConfigurationException {
    HierarchicalConfiguration result = null;
    List<HierarchicalConfiguration> childs = config.configurationsAt(key);

    if (childs.size() > 1)
        throw new ConfigurationException("Duplicate element " + key);
    else if (childs.size() == 1)
        result = childs.get(0);//from w  w  w.j  av  a2  s  .  c o  m

    return result;
}

From source file:org.topology.bgp_ls.config.nodes.impl.AddressFamilyRoutingPeerConfigurationParser.java

private Set<RoutingFilterConfiguration> parsRoutingeFilters(HierarchicalConfiguration config)
        throws ConfigurationException {
    Set<RoutingFilterConfiguration> result = new TreeSet<RoutingFilterConfiguration>();

    for (HierarchicalConfiguration subConfig : config.configurationsAt("Filter"))
        result.add(filterParser.parseConfiguration(subConfig));

    return result;
}

From source file:org.topology.bgp_ls.config.nodes.impl.BgpServerConfigurationParser.java

public ServerConfiguration parseConfig(HierarchicalConfiguration config) throws ConfigurationException {
    BgpServerConfigurationImpl result = new BgpServerConfigurationImpl();
    List<HierarchicalConfiguration> serverConfig = config.configurationsAt("Server");

    if (serverConfig.size() == 1) {
        result.setServerConfiguration(super.parseConfig(serverConfig.get(0)));
    } else if (serverConfig.size() > 1) {
        throw new ConfigurationException("duplicate <Server/> element");
    }//from  w  w  w  .  j  av  a2  s.  c om

    return result;
}