当前位置: 首页>>代码示例>>Java>>正文


Java XMLConfiguration类代码示例

本文整理汇总了Java中org.apache.commons.configuration.XMLConfiguration的典型用法代码示例。如果您正苦于以下问题:Java XMLConfiguration类的具体用法?Java XMLConfiguration怎么用?Java XMLConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XMLConfiguration类属于org.apache.commons.configuration包,在下文中一共展示了XMLConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveGraphForEngine

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@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;
	}

}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:26,代码来源:EngineGraphConfiguration.java

示例2: loadGraphForGUI

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
public List<GUIGraphNodeDecorator> loadGraphForGUI(File file)
		throws ConfigurationException {
	XMLConfiguration temp = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setFile(file);
		config.load();
		// config.validate();//TODO attach schema
		return loadGraphFromXMLForGUI();
	} catch (ConfigurationException e) {
		LOG.severe("KH: could not load gui graph from file: "
				+ file.getPath() + " " + e.getMessage());
		config = temp;
		config.save();
		throw e;
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:19,代码来源:GUIGraphConfiguration.java

示例3: saveGraphForGUI

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
public void saveGraphForGUI(List<GUIGraphNodeDecorator> guiGraphNodes,
		File file) throws ConfigurationException {
	XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		for (GUIGraphNodeDecorator guiNode : guiGraphNodes) {
			config.getRoot().addChild(createGraphNodeForGUI(guiNode, file));
		}
		config.save(file);
	} catch (ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:19,代码来源:GUIGraphConfiguration.java

示例4: saveGraph

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
public void saveGraph(final List<IGraphNode> nodes, final File file)
		throws ConfigurationException {
	final XMLConfiguration tempConfig = (XMLConfiguration) config.clone();
	try {
		config.clear();
		config.setRootNode(tempConfig.getRootNode());
		config.getRootNode().removeChildren();
		for (final IGraphNode node : nodes) {
			config.getRoot().addChild(createGraphNode(node));
		}
		config.save(file);
	} catch (final ConfigurationException e) {
		config = tempConfig;
		config.save(file);
		throw e;
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:19,代码来源:AbstractGraphConfiguration.java

示例5: ResultUploader

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
public ResultUploader(Results r, XMLConfiguration conf, CommandLine argsLine) {
    this.expConf = conf;
    this.results = r;
    this.argsLine = argsLine;

    dbUrl = expConf.getString("DBUrl");
    dbType = expConf.getString("dbtype");
    username = expConf.getString("username");
    password = expConf.getString("password");
    benchType = argsLine.getOptionValue("b");
    windowSize = Integer.parseInt(argsLine.getOptionValue("s"));
    uploadCode = expConf.getString("uploadCode");
    uploadUrl = expConf.getString("uploadUrl");

    this.collector = DBParameterCollectorGen.getCollector(dbType, dbUrl, username, password);
}
 
开发者ID:faclc4,项目名称:HTAPBench,代码行数:17,代码来源:ResultUploader.java

示例6: getXmlConfiguration

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
/**
 * Retrieves a valid XML configuration for a specific XML path for a single
 * instance of the Map specified key-value pairs.
 *
 * @param file   path of the file to be used.
 * @param values map of key and values to set under the generic path.
 * @return Hierarchical configuration containing XML with values.
 */
public XMLConfiguration getXmlConfiguration(String file, Map<String, String> values) {
    InputStream stream = getCfgInputStream(file);
    XMLConfiguration cfg = loadXml(stream);
    XMLConfiguration complete = new XMLConfiguration();
    List<String> paths = new ArrayList<>();
    Map<String, String> valuesWithKey = new HashMap<>();
    values.keySet().stream().forEach(path -> {
        List<String> allPaths = findPaths(cfg, path);
        String key = nullIsNotFound(allPaths.isEmpty() ? null : allPaths.get(0),
                                    "Yang model does not contain desired path");
        paths.add(key);
        valuesWithKey.put(key, values.get(path));
    });
    Collections.sort(paths, new StringLengthComparator());
    paths.forEach(key -> complete.setProperty(key, valuesWithKey.get(key)));
    addProperties(cfg, complete);
    return complete;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:YangXmlUtils.java

示例7: testGetXmlConfigurationFromMap

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
/**
 * Tests getting a single object configuration via passing the path and the map of the desired values.
 *
 * @throws ConfigurationException if the testing xml file is not there.
 */
@Test
public void testGetXmlConfigurationFromMap() throws ConfigurationException {
    Map<String, String> pathAndValues = new HashMap<>();
    pathAndValues.put("capable-switch.id", "openvswitch");
    pathAndValues.put("switch.id", "ofc-bridge");
    pathAndValues.put("controller.id", "tcp:1.1.1.1:1");
    pathAndValues.put("controller.ip-address", "1.1.1.1");
    XMLConfiguration cfg = utils.getXmlConfiguration(OF_CONFIG_XML_PATH, pathAndValues);
    testCreateConfig.load(getClass().getResourceAsStream("/testCreateSingleYangConfig.xml"));
    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);

    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));

    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:YangXmlUtilsTest.java

示例8: getXmlConfigurationFromYangElements

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
/**
 * Tests getting a multiple object nested configuration via passing the path
 * and a list of YangElements containing with the element and desired value.
 *
 * @throws ConfigurationException
 */
@Test
public void getXmlConfigurationFromYangElements() throws ConfigurationException {

    assertNotEquals("Null testConfiguration", new XMLConfiguration(), testCreateConfig);
    testCreateConfig.load(getClass().getResourceAsStream("/testYangConfig.xml"));
    List<YangElement> elements = new ArrayList<>();
    elements.add(new YangElement("capable-switch", ImmutableMap.of("id", "openvswitch")));
    elements.add(new YangElement("switch", ImmutableMap.of("id", "ofc-bridge")));
    List<ControllerInfo> controllers =
            ImmutableList.of(new ControllerInfo(IpAddress.valueOf("1.1.1.1"), 1, "tcp"),
                             new ControllerInfo(IpAddress.valueOf("2.2.2.2"), 2, "tcp"));
    controllers.stream().forEach(cInfo -> {
        elements.add(new YangElement("controller", ImmutableMap.of("id", cInfo.target(),
                                                                   "ip-address", cInfo.ip().toString())));
    });
    XMLConfiguration cfg =
            new XMLConfiguration(YangXmlUtils.getInstance()
                                         .getXmlConfiguration(OF_CONFIG_XML_PATH, elements));
    assertEquals("Wrong configuaration", IteratorUtils.toList(testCreateConfig.getKeys()),
                 IteratorUtils.toList(cfg.getKeys()));
    assertEquals("Wrong string configuaration", utils.getString(testCreateConfig),
                 utils.getString(cfg));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:30,代码来源:YangXmlUtilsTest.java

示例9: validate

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        DateFormat format = new SimpleDateFormat(DATE_STRING_FORMAT);
        format.parse(value);
        return true;
    } catch (ParseException e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:18,代码来源:ConfigUtil.java

示例10: loadExtraConfigration

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_RELATED_LSP_FIELD_NAME)) {
                setRelatedRsvplspFieldName((String) node.getValue());
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:21,代码来源:NmsCorePseudoWireConfiguration.java

示例11: loadExtraConfigration

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
protected boolean loadExtraConfigration() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        for (Object obj : config.getRootNode().getChildren()) {
            Node node = (Node) obj;
            if (node.getName().equals(KEY_HOP_IP_PATH_FIELD_NAME)) {
                List<String> values = new ArrayList<String>();

                for (Object value : node.getChildren()) {
                    values.add((String) ((Node) value).getValue());
                }
                setHopIpPathFieldsName(values);
                return true;
            }
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + getConfigFile());
    }
    return false;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:26,代码来源:NmsCoreRsvpLspConfiguration.java

示例12: reloadConfigurationInner

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
@Override
protected synchronized void reloadConfigurationInner() throws IOException {
    try {
        XMLConfiguration config = new XMLConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.load(getConfigFile());

        String __isSystemUserUpdateEnabled = config.getString(KEY_ENABLE_SYSTEM_USER_UPDATE);
        boolean _isSystemUserUpdateEnabled = (__isSystemUserUpdateEnabled == null ? false :
                Boolean.parseBoolean(__isSystemUserUpdateEnabled));

        this.isSystemUserUpdateEnabled = _isSystemUserUpdateEnabled;

        log().info("isSystemUserUpdateEnabled=" + this.isSystemUserUpdateEnabled);
        log().info("reload finished.");
    } catch (ConfigurationException e) {
        log().error(e.getMessage(), e);
        throw new IOException("failed to reload config: " + FILE_NAME);
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:21,代码来源:BuilderConfiguration.java

示例13: load

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
/**
 * Loads and parse CME MDP Configuration.
 *
 * @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP)
 * @throws ConfigurationException if failed to parse configuration file
 * @throws MalformedURLException  if URI to Configuration is malformed
 */
private void load(final URI uri) throws ConfigurationException, MalformedURLException {
    // todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);
    configuration.load(uri.toURL());
    for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) {
        final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]"));

        for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) {
            final String id = connCfg.getString("[@id]");
            final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]"));
            final TransportProtocol protocol = TransportProtocol.valueOf(connCfg.getString("protocol").substring(0, 3));
            final Feed feed = Feed.valueOf(connCfg.getString("feed"));
            final String ip = connCfg.getString("ip");
            final int port = connCfg.getInt("port");
            final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip"));

            final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port);
            channel.addConnection(connection);
            connCfgs.put(connection.getId(), connection);
        }
        channelCfgs.put(channel.getId(), channel);
    }
}
 
开发者ID:epam,项目名称:java-cme-mdp3-handler,代码行数:32,代码来源:Configuration.java

示例14: getConfiguration

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
private static Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
        throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
        final String fileName = configurationFile.getName();
        final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

        switch (fileExtension) {
            case "yml":
            case "yaml":
                final YamlConfiguration config = new YamlConfiguration();
                config.load(configurationFile);
                return config;
            case "xml":
                return new XMLConfiguration(configurationFile);
            default:
                return new PropertiesConfiguration(configurationFile);
        }
    } catch (final ConfigurationException e) {
        throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:24,代码来源:GraphFactory.java

示例15: main

import org.apache.commons.configuration.XMLConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration("CourseManagementSystem.xml");
    List techIdList = config.getList("Teachers.Teacher.id");
    for (Object id : techIdList) {
        System.out.println(id);
    }
}
 
开发者ID:vagabond1-1983,项目名称:javaDemo,代码行数:8,代码来源:readMultiNode.java


注:本文中的org.apache.commons.configuration.XMLConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。