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); }
if (ref != null) insertNode.setReference(ref);
if (ref != null) insertNode.setReference(ref);
/** * 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 node Node to process. */ void traverseTreeAndLoad(ConfigurationNode parent, Object node) { 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()) { HierarchicalConfiguration.Node child = new HierarchicalConfiguration.Node(entry.getKey()); child.setReference(entry); // Walk the complete tree. traverseTreeAndLoad(child, entry.getValue()); parent.addChild(child); } } else { // This works for both primitives and lists. parent.setValue(node); } } }
/** * Creates a new instance of {@code Node} based on the given * source node. All properties of the source node, including its * children and attributes, will be copied. * * @param src the node to be copied */ public Node(ConfigurationNode src) { this(src.getName(), src.getValue()); setReference(src.getReference()); for (ConfigurationNode nd : src.getChildren()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addChild(nd); nd.setParentNode(parent); } for (ConfigurationNode nd : src.getAttributes()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addAttribute(nd); nd.setParentNode(parent); } }
/** * Creates a new instance of {@code Node} based on the given * source node. All properties of the source node, including its * children and attributes, will be copied. * * @param src the node to be copied */ public Node(ConfigurationNode src) { this(src.getName(), src.getValue()); setReference(src.getReference()); for (ConfigurationNode nd : src.getChildren()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addChild(nd); nd.setParentNode(parent); } for (ConfigurationNode nd : src.getAttributes()) { // Don't change the parent node ConfigurationNode parent = nd.getParentNode(); addAttribute(nd); nd.setParentNode(parent); } }
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); }
/** * Initializes this configuration from an XML document. * * @param document the document to be parsed * @param elemRefs a flag whether references to the XML elements should be set */ public void initProperties(Document document, boolean elemRefs) { if (document.getDoctype() != null) { setPublicID(document.getDoctype().getPublicId()); setSystemID(document.getDoctype().getSystemId()); } constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs, true); getRootNode().setName(document.getDocumentElement().getNodeName()); if (elemRefs) { getRoot().setReference(document.getDocumentElement()); } }
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); }
/** * Initializes this configuration from an XML document. * * @param document the document to be parsed * @param elemRefs a flag whether references to the XML elements should be set */ public void initProperties(Document document, boolean elemRefs) { if (document.getDoctype() != null) { setPublicID(document.getDoctype().getPublicId()); setSystemID(document.getDoctype().getSystemId()); } constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs, true); getRootNode().setName(document.getDocumentElement().getNodeName()); if (elemRefs) { getRoot().setReference(document.getDocumentElement()); } }
@Override public void setReference(Object reference) { super.setReference(reference); // also set the reference at the original node viewNode.setReference(reference); } };
@Override public void setReference(Object reference) { super.setReference(reference); // also set the reference at the original node viewNode.setReference(reference); } };