Java 类org.apache.commons.configuration.tree.ConfigurationNode 实例源码

项目:KernelHive    文件:KernelRepository.java   
@Override
public KernelRepositoryEntry getEntryForGraphNodeType(GraphNodeType type)
        throws ConfigurationException {
    config.load(resource);

    List<ConfigurationNode> entryNodes = config.getRootNode().getChildren(ENTRY_NODE);
    for(ConfigurationNode node : entryNodes){
        List<ConfigurationNode> typeAttrList = node.getAttributes(ENTRY_NODE_TYPE_ATTRIBUTE);

        if(typeAttrList.size()>0){
            String val = (String) typeAttrList.get(0).getValue();

            if(type.equals(GraphNodeType.getType(val))){
                return getEntryFromConfigurationNode(node);
            }
        } else{
            throw new ConfigurationException("KH: no required '"+ENTRY_NODE_TYPE_ATTRIBUTE+"' attribute in "+ENTRY_NODE+" node");
        }
    }

    return null;
}
项目:KernelHive    文件:KernelRepository.java   
private KernelRepositoryEntry getEntryFromConfigurationNode(ConfigurationNode node) throws ConfigurationException{
    List<ConfigurationNode> typeAttrList = node.getAttributes(ENTRY_NODE_TYPE_ATTRIBUTE);
    List<ConfigurationNode> descAttrList = node.getAttributes(ENTRY_NODE_DESCRIPTION_ATTRIBUTE);
    String typeStr;
    String desc = null;

    if(typeAttrList.size()>0){
        typeStr = (String) typeAttrList.get(0).getValue();
    } else{
        throw new ConfigurationException("KH: no required '"+ENTRY_NODE_TYPE_ATTRIBUTE+"' attribute in "+ENTRY_NODE+" node");
    }

    if(descAttrList.size()>0){
        desc = (String) descAttrList.get(0).getValue();
    }

    List<KernelPathEntry> kernelPathEntries = getKernelPathEntries(node);
    Map<String, Object> kernelProperties = getKernelProperties(node);

    return new KernelRepositoryEntry(GraphNodeType.getType(typeStr), desc, kernelPathEntries, kernelProperties);
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
private IKernelString loadKernel(final ConfigurationNode node)
        throws ConfigurationException {
    String src;
    String srcId;

    final List<ConfigurationNode> idSourceAttrs = node
            .getAttributes(KERNEL_ID_ATTRIBUTE);
    if (idSourceAttrs.size() > 0) {
        srcId = (String) idSourceAttrs.get(0).getValue();
    } else {
        throw new ConfigurationException("KH: no required attribute '"
                + KERNEL_ID_ATTRIBUTE + "' found in " + KERNEL + " node");
    }

    final List<ConfigurationNode> srcAttrs = node
            .getAttributes(KERNEL_SRC_ATTRIBUTE);
    if (srcAttrs.size() > 0) {
        src = (String) srcAttrs.get(0).getValue();
    } else {
        throw new ConfigurationException(
                "KH: no required attribute 'src' in " + KERNEL + " node");
    }

    final Map<String, Object> properties = loadKernelProperties(node);
    return new KernelString(srcId, src, properties);
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
@Override
public void saveGraphForEngine(
        final List<EngineGraphNodeDecorator> graphNodes, final File file)
        throws ConfigurationException {
    final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
    try {
        config.clear();
        config.setRootNode(tempConfig.getRootNode());
        config.getRootNode().removeChildren();
        final List<ConfigurationNode> inputDataURLNodes = tempConfig
                .getRootNode().getChildren(INPUT_DATA_NODE);
        for (final ConfigurationNode node : inputDataURLNodes) {
            config.getRootNode().addChild(node);
        }
        for (final EngineGraphNodeDecorator engineNode : graphNodes) {
            config.getRoot().addChild(createGraphNodeForEngine(engineNode));
        }
        config.save(file);
    } catch (final ConfigurationException e) {
        config = tempConfig;
        config.save(file);
        throw e;
    }

}
项目:KernelHive    文件:EngineGraphConfiguration.java   
@Override
public void setInputDataURL(final String inputDataUrl)
        throws ConfigurationException {
    final List<ConfigurationNode> dataNodes = config.getRoot().getChildren(
            INPUT_DATA_NODE);
    if (dataNodes.size() > 0) {
        final List<ConfigurationNode> attrList = dataNodes.get(0)
                .getChildren(INPUT_DATA_NODE_URL_ATTRIBUTE);
        if (attrList.size() > 0) {
            attrList.get(0).setValue(inputDataUrl);
        }
    } else {
        final Node data = new Node(INPUT_DATA_NODE);
        final Node url = new Node(INPUT_DATA_NODE_URL_ATTRIBUTE);
        url.setAttribute(true);
        url.setValue(inputDataUrl);
        data.addAttribute(url);
        config.getRoot().addChild(data);
    }
}
项目:KernelHive    文件:GUIGraphConfiguration.java   
private GUIGraphNodeDecorator loadGraphNodeForGUI(ConfigurationNode node)
        throws ConfigurationException {

    IGraphNode graphNode = loadGraphNode(node);
    int x = -1, y = -1;

    List<ConfigurationNode> xAttrList = node
            .getAttributes(NODE_X_ATTRIBUTE);
    List<ConfigurationNode> yAttrList = node
            .getAttributes(NODE_Y_ATTRIBUTE);
    if (xAttrList.size() > 0) {
        x = Integer.parseInt((String) xAttrList.get(0).getValue());
    }
    if (yAttrList.size() > 0) {
        y = Integer.parseInt((String) yAttrList.get(0).getValue());
    }

    GUIGraphNodeDecorator guiNode = new GUIGraphNodeDecorator(graphNode);
    guiNode.setX(x);
    guiNode.setY(y);

    return guiNode;
}
项目:KernelHive    文件:KernelRepository.java   
@Override
public List<IKernelRepositoryEntry> getEntries()
        throws KernelRepositoryException {
    try {
        resource = repoConfig
                .getKernelRepositoryDescriptorFileURL(jarFileLocation);
        config.load(resource);

        final List<IKernelRepositoryEntry> entries = new ArrayList<IKernelRepositoryEntry>();

        final List<ConfigurationNode> entryNodes = config.getRoot()
                .getChildren(ENTRY_NODE);
        for (final ConfigurationNode node : entryNodes) {
            entries.add(getEntryFromConfigurationNode(node));
        }
        return entries;
    } catch (final ConfigurationException e) {
        throw new KernelRepositoryException(e);
    }
}
项目:configurations-yaml    文件:YAMLConfiguration.java   
/**
 * Constructs the internal configuration nodes hierarchy.
 *
 * @param node The configuration node that is the root of the current configuration section.
 * @param map The map with the yaml configurations nodes, i.e. String -> Object.
 */
@SuppressWarnings("unchecked")
private void constructHierarchy(ConfigurationNode node, Map<String, Object> map)
{
    for (Map.Entry<String, Object> entry : map.entrySet())
    {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof Map)
        {
            ConfigurationNode treeNode = createNode(key);
            constructHierarchy(treeNode, (Map) value);
            node.addChild(treeNode);
        }
        else
        {
            ConfigurationNode leaveNode = createNode(key);
            leaveNode.setValue(value);
            node.addChild(leaveNode);
        }
    }
}
项目:configurations-yaml    文件:YAMLConfiguration.java   
/**
 * Constructs a YAML map, i.e. String -> Object from a given
 * configuration node.
 *
 * @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;
}
项目:java-dynamicconfig    文件:YamlDeserializer.java   
/**
 * Process a node in the object tree, and store it with its parent node in the Config tree.
 * <p>
 * This method recursively calls itself to walk an object tree.
 *
 * @param parent   Parent of the current node, as represented in the Config tree.
 * @param path     Path.
 * @param includes Includes encountered.
 * @param node     Node to process.
 */
void traverseTreeAndLoad(ConfigurationNode parent, String path, List<IncludeReference> includes, Object node) {
    if (node instanceof IncludeReference) {
        IncludeReference include = (IncludeReference) node;
        include.setConfigPath(path);
        includes.add(include);
    } else if (node instanceof Map<?, ?>) {
        // It is not feasible for this class to check this cast, but it is guaranteed by the
        // yaml.load() call that it is a Map<String, Object>.
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) node;

        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            HierarchicalConfiguration.Node child = new HierarchicalConfiguration.Node(key);
            child.setReference(entry);
            // Walk the complete tree.
            traverseTreeAndLoad(child, combineConfigKeyPath(path, key), includes, entry.getValue());
            parent.addChild(child);
        }
    } else {
        // This works for both primitives and lists.
        parent.setValue(node);
    }
}
项目:wmq-mqsc-mojo    文件:MqscMojo.java   
private void processMqscFiles(XMLConfiguration config, List<File> mqscFiles, String releaseFolder) {

    if(CollectionUtils.isNotEmpty(mqscFiles)){
        List<ConfigurationNode> allMQSCEnvironments = config.getRootNode().getChildren();
        if(CollectionUtils.isNotEmpty(allMQSCEnvironments)){
            MultiValuedMap<String,String> allMQSCForEnvironment = new ArrayListValuedHashMap<>();

            processMQSCForAllEnvironments(config, mqscFiles,
                    allMQSCEnvironments, allMQSCForEnvironment);

            for(String key: allMQSCForEnvironment.keySet()){
                List<String> mqscContentList = (List<String>)allMQSCForEnvironment.get(key);
                generateMQSCContent(config, mqscContentList, key, releaseFolder);
            }
        }
    }
}
项目:wmq-mqsc-mojo    文件:MqscMojo.java   
private void processMQSCForAllEnvironments(XMLConfiguration config,
        List<File> allMqscFiles,
        List<ConfigurationNode> allMQSCEnvironments,
        MultiValuedMap<String,String> allMQSCForEnvironment) {
    for(ConfigurationNode rootConfigNode: allMQSCEnvironments){
        String environment = rootConfigNode.getName();

        for(File mqscFile: allMqscFiles){
            try {
                String originalfileContent = FileUtils.readFileToString(mqscFile, Charset.defaultCharset());
                allMQSCForEnvironment.put(environment, originalfileContent);
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
}
项目:MEater    文件:InstanceConfigContainer.java   
private void saveComponentConfigurationsTo(HierarchicalConfiguration config)
        throws MEaterConfigurationException {
    // create a collection to hold the components section
    Collection<ConfigurationNode> configNodes = new LinkedList<ConfigurationNode>();

    // save all of our components to the section
    for (I c : this.configUnits) {
        // create a configuration for the component + save it, add it
        HierarchicalConfiguration cc = new HierarchicalConfiguration();
        c.saveConfigurationTo(cc);
        cc.getRootNode().setName(c.getRegisteredTypeName());
        configNodes.add(cc.getRootNode());
    }

    // add components section to config
    config.addNodes(CKEY_INSTANCES, configNodes);
}
项目:MEater    文件:MEaterConfig.java   
private void saveModulesTo(HierarchicalConfiguration config)
        throws MEaterConfigurationException {
    // create a collection to hold the modules section
    Collection<ConfigurationNode> moduleNodes = new LinkedList<ConfigurationNode>();

    // save all of our modules to the section
    for (ConfigModule m : this.modules.values()) {
        // create a configuration for the module + save it, add it
        HierarchicalConfiguration mc = new HierarchicalConfiguration();
        m.saveConfigurationTo(mc);
        mc.getRootNode().setName(m.getModuleName());
        moduleNodes.add(mc.getRootNode());
    }

    // add modules section to config
    config.addNodes(CKEY_MODULES, moduleNodes);
}
项目:qtaste    文件:XMLConfiguration.java   
/**
 * Fetches the specified property. This task is delegated to the associated
 * expression engine.
 *
 * @param key the key to be looked up
 * @return the found value
 */
@Override
public List<Object> getProperty(String key) {
    List<?> nodes = fetchNodeList(key);

    if (nodes.size() == 0) {
        return null;
    } else {
        List<Object> list = new ArrayList<>();
        for (Object node : nodes) {
            ConfigurationNode configurationNode = (ConfigurationNode) node;
            if (configurationNode.getValue() != null) {
                list.add(configurationNode.getValue());
            }
        }

        if (list.size() < 1) {
            return null;
        } else {
            return list;
        }
    }
}
项目:MaduraConfiguration    文件:XMLBeanFactory.java   
private Element makeElement(ConfigurationNode node)
{
    Element element = new Element(node.getName());
    Object value = node.getValue();
    if (value != null)
        element.setText(value.toString());
    List<ConfigurationNode> attributes = node.getAttributes();
    for (ConfigurationNode attribute: attributes)
    {
        element.setAttribute(new Attribute(attribute.getName(),attribute.getValue().toString()));
    }
    List<ConfigurationNode> children = node.getChildren();
    for (ConfigurationNode child: children)
    {
        element.addContent(makeElement(child));
    }
    return element;
}
项目:KernelHive    文件:KernelRepository.java   
@Override
public List<KernelRepositoryEntry> getEntries()
        throws ConfigurationException {
    config.load(resource);

    List<KernelRepositoryEntry> entries = new ArrayList<>();

    List<ConfigurationNode> entryNodes = config.getRoot().getChildren(ENTRY_NODE);
    for(ConfigurationNode node : entryNodes){
        entries.add(getEntryFromConfigurationNode(node));
    }       
    return entries;
}
项目:KernelHive    文件:KernelRepository.java   
private List<KernelPathEntry> getKernelPathEntries(ConfigurationNode node) throws ConfigurationException{
    List<ConfigurationNode> kernelsList = node.getChildren(KERNEL_NODE);
    List<KernelPathEntry> list = new ArrayList<KernelPathEntry>(kernelsList.size());
    for(ConfigurationNode kNode : kernelsList){
        String name;
        URL src;
        String id;

        List<ConfigurationNode> idAttrList = kNode.getAttributes(KERNEL_NODE_ID_ATTRIBUTE);
        List<ConfigurationNode> nameAttrList = kNode.getAttributes(KERNEL_NODE_NAME_ATTRIBUTE);
        List<ConfigurationNode> srcAttrList = kNode.getAttributes(KERNEL_NODE_SRC_ATTRIBUTE);

        if(nameAttrList.size()>0){
            name = (String) nameAttrList.get(0).getValue();
        } else{
            throw new ConfigurationException("KH: no required '"+KERNEL_NODE_NAME_ATTRIBUTE+"' attribute in "+KERNEL_NODE+" node");
        }

        if(srcAttrList.size()>0){
            src = KernelRepository.class.getResource((String) srcAttrList.get(0).getValue());
            if(src==null){
                throw new ConfigurationException("KH: the resource path: '"+srcAttrList.get(0).getValue()+"' cound not be found");
            }
        } else{
            throw new ConfigurationException("KH: no required '"+KERNEL_NODE_SRC_ATTRIBUTE+"' attribute in "+KERNEL_NODE+" node");
        }

        if(idAttrList.size()>0){
            id = (String) idAttrList.get(0).getValue();
        } else{
            throw new ConfigurationException("KH: no required '"+KERNEL_NODE_ID_ATTRIBUTE+"' attribute in "+KERNEL_NODE+" node");
        }

        Map<String, Object> properties = getKernelProperties(kNode);

        list.add(new KernelPathEntry(id, name, src, properties));
    }
    return list;
}
项目:KernelHive    文件:KernelRepository.java   
private Map<String, Object> getKernelProperties(ConfigurationNode node) throws ConfigurationException{
    List<ConfigurationNode> propertiesNodeList = node.getChildren(KERNEL_PROPERTY_NODE);
    Map<String, Object> properties = new HashMap<String, Object>(propertiesNodeList.size());

    for(ConfigurationNode pNode : propertiesNodeList){
        String key;
        Object value;

        List<ConfigurationNode> keyAttrList = pNode.getAttributes(KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE);
        List<ConfigurationNode> valueAttrList = pNode.getAttributes(KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE);

        if(keyAttrList.size()>0){
            key = (String) keyAttrList.get(0).getValue();
        } else{
            throw new ConfigurationException("KH: no required '"+KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE+"' attribute in "+KERNEL_PROPERTY_NODE+" node");
        }

        if(valueAttrList.size()>0){
            value = valueAttrList.get(0).getValue();
        } else{
            throw new ConfigurationException("KH: no required '"+KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE+"' attribute in "+KERNEL_PROPERTY_NODE+" node");
        }

        properties.put(key, value);
    }
    return properties;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
@Override
public String getInputDataURL() throws ConfigurationException {
    final List<ConfigurationNode> dataNodes = config.getRoot().getChildren(
            INPUT_DATA_NODE);
    if (dataNodes.size() > 0) {
        final List<ConfigurationNode> urlAttrList = dataNodes.get(0)
                .getAttributes(INPUT_DATA_NODE_URL_ATTRIBUTE);
        if (urlAttrList.size() > 0) {
            return (String) urlAttrList.get(0).getValue();
        }
    }
    return null;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
private EngineGraphNodeDecorator loadGraphNodeForEngine(
        final ConfigurationNode node) throws ConfigurationException {
    final IGraphNode graphNode = loadGraphNode(node);
    final EngineGraphNodeDecorator engineNode = new EngineGraphNodeDecorator(
            graphNode);
    return engineNode;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
private List<EngineGraphNodeDecorator> loadGraphNodesForEngine()
        throws ConfigurationException {
    final List<EngineGraphNodeDecorator> nodes = new ArrayList<EngineGraphNodeDecorator>();
    for (final ConfigurationNode node : config.getRoot().getChildren(NODE)) {
        final EngineGraphNodeDecorator engineNode = loadGraphNodeForEngine(node);
        final List<IKernelString> kernels = loadKernels(node);
        engineNode.setKernels(kernels);
        final Map<String, Object> nodeProperties = loadGraphNodeProperties(node);
        engineNode.getGraphNode().setProperties(nodeProperties);
        nodes.add(engineNode);
    }
    return nodes;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
private Map<String, Object> loadKernelProperties(
        final ConfigurationNode node) throws ConfigurationException {
    final List<ConfigurationNode> propList = node
            .getChildren(KERNEL_PROPERTY_NODE);
    final Map<String, Object> properties = new HashMap<String, Object>();
    for (final ConfigurationNode propNode : propList) {
        String key;
        Object value;

        final List<ConfigurationNode> keyAttrList = propNode
                .getAttributes(KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE);
        if (keyAttrList.size() > 0) {
            key = (String) keyAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required attribute '"
                    + KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE + "' in "
                    + KERNEL_PROPERTY_NODE + " node");
        }
        final List<ConfigurationNode> valueAttrList = propNode
                .getAttributes(KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE);
        if (valueAttrList.size() > 0) {
            value = valueAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required attribute '"
                    + KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE + "' in "
                    + KERNEL_PROPERTY_NODE + " node");
        }
        properties.put(key, value);
    }
    return properties;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
private List<IKernelString> loadKernels(final ConfigurationNode node)
        throws ConfigurationException {
    final List<IKernelString> kernels = new ArrayList<IKernelString>();

    List<ConfigurationNode> kernelNodes = node.getChildren(NODE_KERNELS);
    if (kernelNodes.size() > 0) {
        final ConfigurationNode kernelNode = kernelNodes.get(0);
        kernelNodes = kernelNode.getChildren(KERNEL);
        for (final ConfigurationNode n : kernelNodes) {
            kernels.add(loadKernel(n));
        }
    }
    return kernels;
}
项目:KernelHive    文件:EngineGraphConfiguration.java   
@Override
public void saveGraphForEngine(
        final List<EngineGraphNodeDecorator> graphNodes, final Writer writer)
        throws ConfigurationException {
    final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
    final File tempFile = config.getFile();
    try {
        config.clear();
        final List<ConfigurationNode> rootAttrs = tempConfig.getRootNode()
                .getAttributes();
        config.setRootNode((ConfigurationNode) tempConfig.getRootNode()
                .clone());
        config.getRootNode().removeChildren();
        for (final ConfigurationNode n : rootAttrs) {
            config.getRootNode()
                    .addAttribute((ConfigurationNode) n.clone());
        }
        final List<ConfigurationNode> inputDataURLNodes = tempConfig
                .getRoot().getChildren(INPUT_DATA_NODE);
        for (final ConfigurationNode node : inputDataURLNodes) {
            config.getRootNode().addChild(node);
        }
        for (final EngineGraphNodeDecorator engineNode : graphNodes) {
            config.getRoot().addChild(createGraphNodeForEngine(engineNode));
        }
        config.save(writer);
    } catch (final ConfigurationException e) {
        config = tempConfig;
        config.save(tempFile);
    }

}
项目:KernelHive    文件:GUIGraphConfiguration.java   
private List<GUIGraphNodeDecorator> loadGraphNodesForGUI()
        throws ConfigurationException {
    List<GUIGraphNodeDecorator> nodes = new ArrayList<GUIGraphNodeDecorator>();
    for (ConfigurationNode node : config.getRoot().getChildren(NODE)) {
        GUIGraphNodeDecorator guiNode = loadGraphNodeForGUI(node);
        List<IKernelFile> sourceFiles = loadSourceFiles(node);
        guiNode.setSourceFiles(sourceFiles);
        Map<String, Object> nodeProperties = loadGraphNodeProperties(node);
        guiNode.getGraphNode().setProperties(nodeProperties);
        nodes.add(guiNode);
    }
    return nodes;
}
项目:KernelHive    文件:GUIGraphConfiguration.java   
private Map<String, Object> loadSourceFileProperties(ConfigurationNode node)
        throws ConfigurationException {
    List<ConfigurationNode> propList = node
            .getChildren(SOURCE_FILE_PROPERTY_NODE);
    Map<String, Object> properties = new HashMap<String, Object>();
    for (ConfigurationNode propNode : propList) {
        String key;
        Object value;

        List<ConfigurationNode> keyAttrList = propNode
                .getAttributes(SOURCE_FILE_PROPERTY_NODE_KEY_ATTRIBUTE);
        if (keyAttrList.size() > 0) {
            key = (String) keyAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required attribute '"
                    + SOURCE_FILE_PROPERTY_NODE_KEY_ATTRIBUTE + "' in "
                    + SOURCE_FILE_PROPERTY_NODE + " node");
        }
        List<ConfigurationNode> valueAttrList = propNode
                .getAttributes(SOURCE_FILE_PROPERTY_NODE_VALUE_ATTRIBUTE);
        if (valueAttrList.size() > 0) {
            value = valueAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required attribute '"
                    + SOURCE_FILE_PROPERTY_NODE_VALUE_ATTRIBUTE + "' in "
                    + SOURCE_FILE_PROPERTY_NODE + " node");
        }
        properties.put(key, value);
    }
    return properties;
}
项目:KernelHive    文件:GUIGraphConfiguration.java   
private List<IKernelFile> loadSourceFiles(ConfigurationNode node)
        throws ConfigurationException {
    List<IKernelFile> sourceFiles = new ArrayList<IKernelFile>();

    List<ConfigurationNode> sourceFilesList = node
            .getChildren(NODE_SOURCE_FILES);
    if (sourceFilesList.size() > 0) {
        ConfigurationNode sourcesNode = sourceFilesList.get(0);
        sourceFilesList = sourcesNode.getChildren(SOURCE_FILE);
        for (ConfigurationNode src : sourceFilesList) {
            sourceFiles.add(loadSourceFile(src));
        }
    }
    return sourceFiles;
}
项目:KernelHive    文件:AbstractGraphConfiguration.java   
@Override
public String getProjectName() throws ConfigurationException {
    String projectName;
    final List<ConfigurationNode> attrList = config.getRoot()
            .getAttributes(ROOT_NODE_NAME_ATTRIBUTE);
    if (attrList.size() > 0) {
        projectName = (String) attrList.get(0).getValue();
        return projectName;
    } else {
        throw new ConfigurationException("no attribute '"
                + ROOT_NODE_NAME_ATTRIBUTE
                + "' in root node of the configuration");
    }
}
项目:KernelHive    文件:AbstractGraphConfiguration.java   
protected IGraphNode loadGraphNode(final ConfigurationNode node)
        throws ConfigurationException {
    String id = null, name = null;
    GraphNodeType type = null;

    final List<ConfigurationNode> idAttrList = node
            .getAttributes(NODE_ID_ATTRIBUTE);
    final List<ConfigurationNode> nameAttrList = node
            .getAttributes(NODE_NAME_ATTRIBUTE);
    final List<ConfigurationNode> typeAttrList = node
            .getAttributes(NODE_TYPE_ATTRIBUTE);

    if (idAttrList.size() > 0)
        id = (String) idAttrList.get(0).getValue();
    if (nameAttrList.size() > 0)
        name = (String) nameAttrList.get(0).getValue();
    if (typeAttrList.size() > 0)
        type = GraphNodeType.getType((String) typeAttrList.get(0)
                .getValue());

    IGraphNode graphNode;
    final IGraphNodeBuilder gnBuilder = new GraphNodeBuilder();
    try {
        graphNode = gnBuilder.setType(type).setId(id).setName(name).build();
    } catch (final GraphNodeBuilderException e) {
        e.printStackTrace();
        throw new ConfigurationException(e);
    }
    return graphNode;
}
项目:KernelHive    文件:AbstractGraphConfiguration.java   
protected Map<String, Object> loadGraphNodeProperties(
        final ConfigurationNode node) throws ConfigurationException {
    final Map<String, Object> props = new HashMap<String, Object>();

    List<ConfigurationNode> propertiesList = node
            .getChildren(PROPERTIES_NODE);
    if (propertiesList.size() > 0) {
        final ConfigurationNode propsNode = propertiesList.get(0);
        propertiesList = propsNode.getChildren(PROPERTY_NODE);
        for (final ConfigurationNode prop : propertiesList) {
            String key;
            Object value;

            final List<ConfigurationNode> keyAttrList = prop
                    .getAttributes(PROPERTY_NODE_KEY_ATTRIBUTE);
            final List<ConfigurationNode> valueAttrList = prop
                    .getAttributes(PROPERTY_NODE_VALUE_ATTRIBUTE);

            if (keyAttrList.size() > 0) {
                key = (String) keyAttrList.get(0).getValue();
            } else {
                throw new ConfigurationException(
                        "KH: no required 'key' attribute in "
                                + PROPERTY_NODE + " node");
            }

            if (valueAttrList.size() > 0) {
                value = valueAttrList.get(0).getValue();
            } else {
                throw new ConfigurationException(
                        "KH: no required 'value' attribute in "
                                + PROPERTY_NODE + " node");
            }

            props.put(key, value);
        }
    }
    return props;
}
项目:KernelHive    文件:AbstractGraphConfiguration.java   
protected List<IGraphNode> loadGraphNodes() throws ConfigurationException {
    final List<IGraphNode> nodes = new ArrayList<IGraphNode>();
    for (final ConfigurationNode node : config.getRoot().getChildren(NODE)) {
        final IGraphNode graphNode = loadGraphNode(node);
        final Map<String, Object> nodeProperties = loadGraphNodeProperties(node);
        graphNode.setProperties(nodeProperties);
        nodes.add(graphNode);
    }
    return nodes;
}
项目:KernelHive    文件:AbstractGraphConfiguration.java   
@Override
public void setProjectName(final String name) throws ConfigurationException {
    final List<ConfigurationNode> attributes = config.getRoot()
            .getAttributes(ROOT_NODE_NAME_ATTRIBUTE);
    if (attributes.size() > 0) {
        attributes.get(0).setValue(name);
    } else {
        final Node attr = new Node(ROOT_NODE_NAME_ATTRIBUTE);
        attr.setAttribute(true);
        attr.setValue(name);
        config.getRoot().addAttribute(attr);
    }
}
项目:KernelHive    文件:KernelRepository.java   
@Override
public IKernelRepositoryEntry getEntryForGraphNodeType(
        final GraphNodeType type) throws KernelRepositoryException {
    try {
        resource = repoConfig
                .getKernelRepositoryDescriptorFileURL(jarFileLocation);
        config.load(resource);
        final List<ConfigurationNode> entryNodes = config.getRootNode()
                .getChildren(ENTRY_NODE);
        for (final ConfigurationNode node : entryNodes) {
            final List<ConfigurationNode> typeAttrList = node
                    .getAttributes(ENTRY_NODE_TYPE_ATTRIBUTE);

            if (typeAttrList.size() > 0) {
                final String val = (String) typeAttrList.get(0).getValue();

                if (type.equals(GraphNodeType.getType(val))) {
                    return getEntryFromConfigurationNode(node);
                }
            } else {
                throw new ConfigurationException("KH: no required '"
                        + ENTRY_NODE_TYPE_ATTRIBUTE + "' attribute in "
                        + ENTRY_NODE + " node");
            }
        }
        return null;
    } catch (final ConfigurationException e) {
        throw new KernelRepositoryException(e);
    }
}
项目:KernelHive    文件:KernelRepository.java   
private IKernelRepositoryEntry getEntryFromConfigurationNode(
        final ConfigurationNode node) throws ConfigurationException {
    final List<ConfigurationNode> typeAttrList = node
            .getAttributes(ENTRY_NODE_TYPE_ATTRIBUTE);
    final List<ConfigurationNode> descAttrList = node
            .getAttributes(ENTRY_NODE_DESCRIPTION_ATTRIBUTE);
    String typeStr;
    String desc = null;

    if (typeAttrList.size() > 0) {
        typeStr = (String) typeAttrList.get(0).getValue();
    } else {
        throw new ConfigurationException("KH: no required '"
                + ENTRY_NODE_TYPE_ATTRIBUTE + "' attribute in "
                + ENTRY_NODE + " node");
    }

    if (descAttrList.size() > 0) {
        desc = (String) descAttrList.get(0).getValue();
    }

    final List<IKernelPathEntry> kernelPathEntries = getKernelPathEntries(node);
    Map<String, Object> kernelProperties = getKernelProperties(node);

    return new KernelRepositoryEntry(GraphNodeType.getType(typeStr), desc,
            kernelPathEntries, kernelProperties);
}
项目:KernelHive    文件:KernelRepository.java   
private Map<String, Object> getKernelProperties(final ConfigurationNode node)
        throws ConfigurationException {
    final List<ConfigurationNode> propertiesNodeList = node
            .getChildren(KERNEL_PROPERTY_NODE);
    final Map<String, Object> properties = new HashMap<String, Object>(
            propertiesNodeList.size());

    for (final ConfigurationNode pNode : propertiesNodeList) {
        String key;
        Object value;

        final List<ConfigurationNode> keyAttrList = pNode
                .getAttributes(KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE);
        final List<ConfigurationNode> valueAttrList = pNode
                .getAttributes(KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE);

        if (keyAttrList.size() > 0) {
            key = (String) keyAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required '"
                    + KERNEL_PROPERTY_NODE_KEY_ATTRIBUTE
                    + "' attribute in " + KERNEL_PROPERTY_NODE + " node");
        }

        if (valueAttrList.size() > 0) {
            value = valueAttrList.get(0).getValue();
        } else {
            throw new ConfigurationException("KH: no required '"
                    + KERNEL_PROPERTY_NODE_VALUE_ATTRIBUTE
                    + "' attribute in " + KERNEL_PROPERTY_NODE + " node");
        }

        properties.put(key, value);
    }
    return properties;
}
项目:athena    文件:YangXmlUtils.java   
/**
 * Retrieves a valid XML configuration for a specific XML path for multiple
 * instance of YangElements objects.
 *
 * @param file     path of the file to be used.
 * @param elements List of YangElements that are to be set.
 * @return Hierachical configuration containing XML with values.
 */
public XMLConfiguration getXmlConfiguration(String file, List<YangElement> elements) {
    InputStream stream = getCfgInputStream(file);
    HierarchicalConfiguration cfg = loadXml(stream);
    XMLConfiguration complete = new XMLConfiguration();
    Multimap<String, YangElement> commonElements = ArrayListMultimap.create();

    //saves the elements in a Multimap based on the computed key.
    elements.forEach(element -> {
        String completeKey = nullIsNotFound(findPath(cfg, element.getBaseKey()),
                                            "Yang model does not contain desired path");
        commonElements.put(completeKey, element);
    });

    //iterates over the elements and constructs the configuration
    commonElements.keySet().forEach(key -> {
        // if there is more than one element for a given path
        if (commonElements.get(key).size() > 1) {
            //creates a list of nodes that have to be added for that specific path
            ArrayList<ConfigurationNode> nodes = new ArrayList<>();
            //creates the nodes
            commonElements.get(key).forEach(element -> nodes.add(getInnerNode(element).getRootNode()));
            //computes the parent path
            String parentPath = key.substring(0, key.lastIndexOf("."));
            //adds the nodes to the complete configuration
            complete.addNodes(parentPath, nodes);
        } else {
            //since there is only a single element we can assume it's the first one.
            Map<String, String> keysAndValues = commonElements.get(key).stream().
                    findFirst().get().getKeysAndValues();
            keysAndValues.forEach((k, v) -> complete.setProperty(key + "." + k, v));
        }
    });
    addProperties(cfg, complete);
    return complete;
}
项目:athena    文件:XmlConfigParser.java   
public static String createControllersConfig(HierarchicalConfiguration cfg,
                                             HierarchicalConfiguration actualCfg,
                                             String target, String netconfOperation,
                                             String controllerOperation,
                                             List<ControllerInfo> controllers) {
    //cfg.getKeys().forEachRemaining(key -> System.out.println(key));
    cfg.setProperty("edit-config.target", target);
    cfg.setProperty("edit-config.default-operation", netconfOperation);
    cfg.setProperty("edit-config.config.capable-switch.id",
                    parseCapableSwitchId(actualCfg));
    cfg.setProperty("edit-config.config.capable-switch." +
                            "logical-switches.switch.id", parseSwitchId(actualCfg));
    List<ConfigurationNode> newControllers = new ArrayList<>();
    for (ControllerInfo ci : controllers) {
        XMLConfiguration controller = new XMLConfiguration();
        controller.setRoot(new HierarchicalConfiguration.Node("controller"));
        String id = ci.type() + ":" + ci.ip() + ":" + ci.port();
        controller.setProperty("id", id);
        controller.setProperty("ip-address", ci.ip());
        controller.setProperty("port", ci.port());
        controller.setProperty("protocol", ci.type());
        newControllers.add(controller.getRootNode());
    }
    cfg.addNodes("edit-config.config.capable-switch.logical-switches." +
                         "switch.controllers", newControllers);
    XMLConfiguration editcfg = (XMLConfiguration) cfg;
    StringWriter stringWriter = new StringWriter();
    try {
        editcfg.save(stringWriter);
    } catch (ConfigurationException e) {
        log.error("createControllersConfig()", e);
    }
    String s = stringWriter.toString()
            .replaceAll("<controller>",
                        "<controller nc:operation=\"" + controllerOperation + "\">");
    s = s.replace("<target>" + target + "</target>",
                  "<target><" + target + "/></target>");
    return s;

}
项目:yfiton    文件:Yfiton.java   
private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration, Notifier notifier) {
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).
                            getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}
项目:qaf    文件:XMLScenarioFactory.java   
@Override
protected Collection<Object[]> parseFile(String xmlFile) {
    ArrayList<Object[]> statements = new ArrayList<Object[]>();
    try {
        HierarchicalConfiguration processor = new XMLConfiguration(xmlFile);
        List<?> definations = processor.getRoot().getChildren();
        for (Object definationObj : definations) {
            ConfigurationNode defination = (ConfigurationNode) definationObj;
            String type = defination.getName();
            String[] entry = new String[3];

            if (type.equalsIgnoreCase("SCENARIO") || type.equalsIgnoreCase("STEP-DEF")) {
                entry[0] = type;

                Map<?, ?> metaData = getMetaData(defination);
                entry[1] = (String) metaData.get("name");
                metaData.remove("name");
                entry[2] = gson.toJson(metaData);
                statements.add(entry);
                System.out.println("META-DATA:" + entry[2]);
                addSteps(defination, statements);
                statements.add(new String[] { "END", "", "" });
            }
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }

    return statements;
}