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

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

Introduction

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

Prototype

public ConfigurationNode getRootNode() 

Source Link

Document

Returns the root node of this hierarchical configuration.

Usage

From source file:org.lable.oss.dynamicconfig.serialization.yaml.YamlSerializer.java

/**
 * {@inheritDoc}/*from ww w  . jav a2  s.c om*/
 */
@Override
public void serialize(HierarchicalConfiguration configuration, OutputStream output)
        throws ConfigurationException {
    StringWriter writer = new StringWriter();
    yaml.dump(traverseTreeAndEmit(configuration.getRootNode()), writer);
    try {
        output.write(writer.toString().getBytes());
    } catch (IOException e) {
        throw new ConfigurationException("IOException caught.", e);
    }
}

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   w  ww.ja  v a2 s .  c o  m
    return properties.build();
}

From source file:org.wso2.carbon.device.mgt.iot.agent.kura.display.SequenceRunner.java

private List<ResourceType> getSequence() {
    List<ResourceType> sequence = new ArrayList<>();

    ConfigManager configManager = ConfigManager.getInstance();

    List<HierarchicalConfiguration> resources = configManager.getContentConfig()
            .configurationsAt("Content.DisplaySequence.Resource");

    for (HierarchicalConfiguration resource : resources) {

        String resourceTypeHandler = resource.getString("[@handler]");
        ResourceType resourceObj = null;

        try {/*from ww w.j  av a 2 s. c  om*/
            resourceObj = (ResourceType) Class.forName(resourceTypeHandler).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            log.severe("Error occurred while resolving resource type: " + e.getMessage());
        }

        //read all init args
        Map<String, String> configArgs = new HashMap<>();
        ConfigurationNode node = resource.getRootNode();
        List<ConfigurationNode> attrs = node.getAttributes();

        for (ConfigurationNode attr : attrs) {
            configArgs.put(attr.getName(), attr.getValue().toString());
        }

        //initialize the resource with config args
        resourceObj.init(configArgs);

        //add it to the sequence
        sequence.add(resourceObj);
    }

    return sequence;
}

From source file:velo.uiComponents.XMLTagInputs.java

public void encodeBegin(FacesContext context) throws IOException {
    if (getChildren().size() == 0) {
        // Get the view root from the Context
        UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
        // System.out.println("WAAAAAAAAAAAAAAAAAAA VIEW: " + view);
        //System.out.println("GET FOR: " + getFor());
        // Get the XMLManager component from the view
        UIComponent uiComponent = view.findComponent(getFor());

        // System.out.println("Loaded component that expected to be an
        // XMLManager of class \'" + uiComponent.getClass().getName() +
        // "\'");
        if (uiComponent instanceof XMLManager) {
            XMLManager xmlManager = (XMLManager) uiComponent;
            // System.out.println("xml conf: " + xmlManager.getConfig());
            try {
                HierarchicalConfiguration hc = xmlManager.getConfig().getConfig().configurationAt(getTagName());

                Iterator nodes = hc.getRootNode().getChildren().listIterator();

                HtmlPanelGrid hpg = (HtmlPanelGrid) this.getFacesContext().getApplication()
                        .createComponent(HtmlPanelGrid.COMPONENT_TYPE);
                hpg.setColumns(1);/*  w  ww  . ja v a  2 s.c  o m*/
                hpg.setStyleClass("xmlTagMainPanel");

                // System.out.println("Size of children(BEFORE): " +
                // getChildren().size());

                while (nodes.hasNext()) {
                    XMLConfiguration.Node currNode = (XMLConfiguration.Node) nodes.next();

                    // If node has childs, then iterate over childs and
                    // display them
                    if (currNode.getChildrenCount() > 0) {
                        if (renderSubNodes) {
                            Iterator subNodes = currNode.getChildren().listIterator();
                            while (subNodes.hasNext()) {
                                XMLConfiguration.Node currSubNode = (XMLConfiguration.Node) subNodes.next();
                                XMLTagInput xti = new XMLTagInput(XMLTagInput.getFullXmlTagPath(currSubNode),
                                        getFor());
                                // hpg.getChildren().add(getTag(currSubNode));
                                hpg.getChildren().add(xti);
                            }
                        } else {
                            // Specified not to render tags with childs,
                            // then continue to the next node
                            continue;
                        }
                        // Else render tag since this is not a parent
                    } else {
                        // hpg.getChildren().add(getTag(currNode));
                        XMLTagInput xti = new XMLTagInput(XMLTagInput.getFullXmlTagPath(currNode), getFor());
                        hpg.getChildren().add(xti);
                    }

                    this.getChildren().add(hpg);

                }

            } catch (ConfigurationException ce) {
                ce.printStackTrace();
            }

        } else {
            // TODO handle the exception correctly!
            //System.out.println("Expected UI Component is not an instance of XMLManager class!");
        }

        // System.out.println("Size of children(AFTER): " +
        // getChildren().size());
    } else {
        // this component already has childrens, probably from the restore
        // phase, then do nothing...
    }
}