/** * 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(); } }
/** * 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(); } }
/** * 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); }
/** * 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 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); }
/** * 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 a child node to this view node. The new child's parent node will be * saved. * * @param child the child node to be added */ @Override public void addChild(ConfigurationNode child) { ConfigurationNode parent = null; if (child != null) { parent = child.getParentNode(); super.addChild(child); child.setParentNode(parent); } else { throw new IllegalArgumentException("Child node must not be null!"); } }
/** * Adds a new sub node. * * @param node the node to add */ public void addNode(ConfigurationNode node) { if (node == null || node.getName() == null) { throw new IllegalArgumentException( "Node to add must have a defined name!"); } node.setParentNode(null); // reset, will later be set if (nodes == null) { nodes = new ArrayList<ConfigurationNode>(); namedNodes = new HashMap<String, List<ConfigurationNode>>(); } nodes.add(node); List<ConfigurationNode> lst = namedNodes.get(node.getName()); if (lst == null) { lst = new LinkedList<ConfigurationNode>(); namedNodes.put(node.getName(), lst); } lst.add(node); }
/** * Changes the name of a {@code ConfigurationNode}. This is a utility method * which is probably needed by each concrete tree model implementation. * Normally, the name of a configuration node cannot be changed if it is * part of a node hierarchy. Therefore, this method uses some tricks to * achieve this goal. The return value indicates if a change was done. If * the passed in new name equals the current name, nothing is changed, and * result is <b>false</b>. * * @param node the {@code ConfigurationNode} to be changed * @param newName the new name of this node * @return <b>true</b> if a name change was necessary, <b>false</b> * otherwise */ public boolean changeNodeName(ConfigurationNode node, String newName) { if (!StringUtils.equals(node.getName(), newName)) { ConfigurationNode parent = node.getParentNode(); node.setParentNode(null); node.setName(newName); node.setParentNode(parent); return true; } return false; }
/** * Adds a child node to this view node. The new child's parent node will be * saved. * * @param child the child node to be added */ @Override public void addChild(ConfigurationNode child) { ConfigurationNode parent = null; if (child != null) { parent = child.getParentNode(); super.addChild(child); child.setParentNode(parent); } else { throw new IllegalArgumentException("Child node must not be null!"); } }
/** * Adds a new sub node. * * @param node the node to add */ public void addNode(ConfigurationNode node) { if (node == null || node.getName() == null) { throw new IllegalArgumentException( "Node to add must have a defined name!"); } node.setParentNode(null); // reset, will later be set if (nodes == null) { nodes = new ArrayList<ConfigurationNode>(); namedNodes = new HashMap<String, List<ConfigurationNode>>(); } nodes.add(node); List<ConfigurationNode> lst = namedNodes.get(node.getName()); if (lst == null) { lst = new LinkedList<ConfigurationNode>(); namedNodes.put(node.getName(), lst); } lst.add(node); }
/** * Adds an attribute to this view node. The new attribute's parent node will * be saved. * * @param attr the attribute node to be added */ @Override public void addAttribute(ConfigurationNode attr) { ConfigurationNode parent = null; if (attr != null) { parent = attr.getParentNode(); super.addAttribute(attr); attr.setParentNode(parent); } else { throw new IllegalArgumentException("Attribute node must not be null!"); } }
/** * Adds an attribute to this view node. The new attribute's parent node will * be saved. * * @param attr the attribute node to be added */ @Override public void addAttribute(ConfigurationNode attr) { ConfigurationNode parent = null; if (attr != null) { parent = attr.getParentNode(); super.addAttribute(attr); attr.setParentNode(parent); } else { throw new IllegalArgumentException("Attribute node must not be null!"); } }
/** * Visits and copies the specified node. * * @param node the node */ @Override public void visitBeforeChildren(ConfigurationNode node) { ConfigurationNode copy = (ConfigurationNode) node.clone(); copy.setParentNode(null); if (!copyStack.isEmpty()) { if (node.isAttribute()) { copyStack.peek().addAttribute(copy); } else { copyStack.peek().addChild(copy); } } copyStack.push(copy); }
/** * Visits and copies the specified node. * * @param node the node */ @Override public void visitBeforeChildren(ConfigurationNode node) { ConfigurationNode copy = (ConfigurationNode) node.clone(); copy.setParentNode(null); if (!copyStack.isEmpty()) { if (node.isAttribute()) { copyStack.peek().addAttribute(copy); } else { copyStack.peek().addChild(copy); } } copyStack.push(copy); }
/** * 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); } }