private void initProperties() { List<ConfigurationNode> nodes = getRootNode().getChildren(); if (nodes == null || nodes.isEmpty()) { return; } for (ConfigurationNode p : nodes) { String name = (String) p.getChildren("name").get(0).getValue(); String value = (String) p.getChildren("value").get(0).getValue(); if (!StringUtils.isEmpty(name)) { properties.put(name, value); } } }
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else { final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } } }
protected void loadHierarchy(final ConfigurationNode parentNode, final Object obj) { final String parentName = parentNode.getName(); if (obj instanceof Map<?, ?>) { for (Map.Entry<String, Object> entry : ((Map<String, Object>) obj).entrySet()) { final Node childNode = new Node(entry.getKey()); // if parent node is look like "tableS", "userS" or "groupS" if (this.xmlCompatibility && parentName != null && parentName.endsWith("s")) { //this is done to have "users.user[@name='smith'] instead of "users.smith" childNode.setName(parentName.substring(0, parentName.length() - 1)); childNode.addAttribute(new Node("name", entry.getKey())); } childNode.setReference(entry); loadHierarchy(childNode, entry.getValue()); parentNode.addChild(childNode); } } else if (obj instanceof Collection) { for (Object child : (Collection) obj) { final Node childNode = new Node("item"); childNode.setReference(child); loadHierarchy(childNode, child); parentNode.addChild(childNode); } } parentNode.setValue(obj); }
/** * Adds a new child to this node. * * @param child the new child */ public void addChild(ConfigurationNode child) { children.addNode(child); child.setAttribute(false); child.setParentNode(this); }
/** * Returns a flag if this node is defined. This means that the node contains * some data. * * @return a flag whether this node is defined */ public boolean isDefined() { return getValue() != null || getChildrenCount() > 0 || getAttributeCount() > 0; }
/** * This method is called whenever a sub node is removed from this * object. It ensures that the removed node's parent is reset and its * {@code removeReference()} method gets called. * * @param subNode the node to be removed */ protected void detachNode(ConfigurationNode subNode) { subNode.setParentNode(null); if (subNode instanceof DefaultConfigurationNode) { ((DefaultConfigurationNode) subNode).removeReference(); } }
/** * Returns a flag if the current key is an attribute. This method can be * called after {@code next()}. * * @return a flag if the current key is an attribute */ public boolean isAttribute() { // if attribute emulation mode is active, the last part of a key is // always an attribute key, too return attribute || (isAttributeEmulatingMode() && !hasNext()); }
/** * Checks whether this node pointer refers to an attribute node. This method * checks the attribute flag of the associated configuration node. * * @return the attribute flag */ @Override public boolean isAttribute() { return node.isAttribute(); }
/** * Returns a list with all children of this node. * * @return a list with all child nodes */ public List<ConfigurationNode> getChildren() { return children.getSubNodes(); }
/** * Print out the data in the configuration. * @param stream The OutputStream. * @param result The root node of the tree. */ public static void printTree(PrintStream stream, ConfigurationNode result) { if (stream != null) { printTree(stream, "", result); } }
/** * Returns the next key part of this configuration key. This is a short * form of {@code nextKey(false)}. * * @return the next key part */ public String nextKey() { return nextKey(false); }
/** * Returns the current key of the iteration (without skipping to the * next element). This is the same key the previous {@code next()} * call had returned. (Short form of {@code currentKey(false)}. * * @return the current key */ public String currentKey() { return currentKey(false); }
/** * Marks a configuration node as a section node. This means that this node * represents a section header. This implementation uses the node's * reference property to store a flag. * * @param node the node to be marked */ private static void markSectionNode(ConfigurationNode node) { node.setReference(Boolean.TRUE); }
public static void main(String[] args) throws ConfigurationException, InterruptedException { E.checkArgument(args.length == 1, "Init store only accept one config file."); E.checkArgument(args[0].endsWith(".yaml"), "Init store only accept yaml config file."); String confFile = args[0]; RegisterUtil.registerBackends(); YamlConfiguration config = new YamlConfiguration(); config.load(confFile); List<ConfigurationNode> nodes = config.getRootNode() .getChildren(GRAPHS); E.checkArgument(nodes.size() == 1, "Must contain one '%s' in config file '%s'", GRAPHS, confFile); List<ConfigurationNode> graphNames = nodes.get(0).getChildren(); E.checkArgument(!graphNames.isEmpty(), "Must contain at least one graph"); for (ConfigurationNode graphName : graphNames) { String configPath = graphName.getValue().toString(); initGraph(configPath); } HugeGraph.shutdown(30L); }
/** * Adds a new child to this node. * * @param child the new child */ public void addChild(ConfigurationNode child) { children.addNode(child); child.setAttribute(false); child.setParentNode(this); }
/** * Checks whether this node pointer refers to an attribute node. This method * checks the attribute flag of the associated configuration node. * * @return the attribute flag */ @Override public boolean isAttribute() { return node.isAttribute(); }
/** * Returns a list with all attributes of this node with the given name. * * @param name the attribute's name * @return all attributes with this name */ public List<ConfigurationNode> getAttributes(String name) { return attributes.getSubNodes(name); }
/** * Adds the specified attribute to this node. * * @param attr the attribute to be added */ public void addAttribute(ConfigurationNode attr) { attributes.addNode(attr); attr.setAttribute(true); attr.setParentNode(this); }
/** * Adds the specified attribute to this node. * * @param attr the attribute to be added */ public void addAttribute(ConfigurationNode attr) { attributes.addNode(attr); attr.setAttribute(true); attr.setParentNode(this); }