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

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

Introduction

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

Prototype

public void setRoot(Node node) 

Source Link

Document

Sets the root node of this hierarchical configuration.

Usage

From source file:net.jradius.example.LocalUsersHandler.java

public void setConfig(ConfigurationItem cfg) {
    super.setConfig(cfg);
    HierarchicalConfiguration.Node root = cfg.getRoot();
    HierarchicalConfiguration xmlCfg = cfg.getXMLConfig();

    /*//from  w w  w. j a va 2  s.co  m
     * Look for <users> ... </users> in the configuration
     */
    List usersList = root.getChildren("users");
    HierarchicalConfiguration.Node node;

    for (Iterator l = usersList.iterator(); l.hasNext();) {
        /*
         * Iterate the <user> ... </user> blocks
         */
        node = (HierarchicalConfiguration.Node) l.next();
        List children = node.getChildren("user");
        for (Iterator i = children.iterator(); i.hasNext();) {
            node = (HierarchicalConfiguration.Node) i.next();
            root = xmlCfg.getRoot();
            xmlCfg.setRoot(node);

            LocalUser user = new LocalUser();

            /*
             * A user is defined in the configuration with the following XML syntax example:
             * 
             * <users>
             *   <user username="test" password="test">
             *       Reply-Message = Hello test user!
             *   </user>
             * </users>
             * 
             * The contents of the <user>...</user> block are the attributes to use in the
             * AccessAccept reply.
             */
            user.username = xmlCfg.getString("[@username]");
            user.realm = xmlCfg.getString("[@realm]");
            user.password = xmlCfg.getString("[@password]");
            Object v = node.getValue();

            if (v != null) {
                user.attributes = v.toString();
            }

            RadiusLog.debug("        -> Configured local user: " + user.getUserName());
            users.put(user.getUserName(), user);
            xmlCfg.setRoot(root);
        }
    }
}

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

private HierarchicalConfiguration getInnerNode(YangElement element) {
    HierarchicalConfiguration node = new HierarchicalConfiguration();
    node.setRoot(new HierarchicalConfiguration.Node(element.getBaseKey()));
    element.getKeysAndValues().forEach(node::setProperty);
    return node;/*from w  w w  .  ja  v a2s.c o m*/
}