本文整理汇总了Java中org.apache.commons.configuration.tree.ConfigurationNode.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationNode.addChild方法的具体用法?Java ConfigurationNode.addChild怎么用?Java ConfigurationNode.addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.configuration.tree.ConfigurationNode
的用法示例。
在下文中一共展示了ConfigurationNode.addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructHierarchy
import org.apache.commons.configuration.tree.ConfigurationNode; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例2: traverseTreeAndLoad
import org.apache.commons.configuration.tree.ConfigurationNode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例3: updateRuleParentNode
import org.apache.commons.configuration.tree.ConfigurationNode; //导入方法依赖的package包/类
public static void updateRuleParentNode(Set<ConfigInclusionExclusionRule> rule, ConfigurationNode parentNode) {
for (ConfigInclusionExclusionRule configInclusionExclusionRule : rule) {
ConfigurationNode ruleNode = getConfNode("rule", configInclusionExclusionRule.getValue(), false);
ConfigurationNode checkNode = getConfNode("check", configInclusionExclusionRule.getTransactionPart()
.toString(), true);
ConfigurationNode matchNode = getConfNode("match", configInclusionExclusionRule.getMatch().toString(), true);
ConfigurationNode headerNode = getConfNode("header", configInclusionExclusionRule.getHeader(), true);
ruleNode.addAttribute(checkNode);
ruleNode.addAttribute(matchNode);
ruleNode.addAttribute(headerNode);
parentNode.addChild(ruleNode);
}
}
示例4: save
import org.apache.commons.configuration.tree.ConfigurationNode; //导入方法依赖的package包/类
public static boolean save(int port, boolean followRedirect, String outputFile,
Set<ConfigInclusionExclusionRule> inclusions,
Set<ConfigInclusionExclusionRule> exclusions,
Set<ConfigInclusionExclusionRule> bodyInclusions,
Set<ConfigInclusionExclusionRule> bodyExclusions,
String fileName) {
ConfigurationNode node = getConfNode("recording-proxy-config", "", false);
ConfigurationNode portNode = getConfNode("proxy-port", String.valueOf(port), false);
ConfigurationNode followRedirectNode = getConfNode("follow-redirects", Boolean.toString(followRedirect), false);
ConfigurationNode outputFileNode = getConfNode("output-file", outputFile, false);
ConfigurationNode inclusionsNode = getConfNode("inclusions", "", false);
ConfigurationNode exclusionsNode = getConfNode("exclusions", "", false);
ConfigurationNode bodyInclusionsNode = getConfNode("body-inclusions", "", false);
ConfigurationNode bodyExclusionsNode = getConfNode("body-exclusions", "", false);
updateRuleParentNode(inclusions, inclusionsNode);
updateRuleParentNode(exclusions, exclusionsNode);
updateRuleParentNode(bodyInclusions, bodyInclusionsNode);
updateRuleParentNode(bodyExclusions, bodyExclusionsNode);
node.addChild(portNode);
node.addChild(followRedirectNode);
node.addChild(outputFileNode);
node.addChild(inclusionsNode);
node.addChild(exclusionsNode);
node.addChild(bodyInclusionsNode);
node.addChild(bodyExclusionsNode);
HierarchicalConfiguration hc = new HierarchicalConfiguration();
hc.setRootNode(node);
XMLConfiguration xmlConfiguration = new XMLConfiguration(hc);
xmlConfiguration.setRootNode(node);
try {
xmlConfiguration.save(new File(fileName));
} catch (ConfigurationException e) {
e.printStackTrace();
}
return true;
}