Author: oheger Date: Sat Feb 23 12:18:51 2008 New Revision: 630530 URL: http://svn.apache.org/viewvc?rev=630530&view=rev Log: Removed the inner Node class of HierarchicalConfiguration. It existed only for reasons of backwards compatiblity. Its functionality is fully covered by the ConfigurationNode interface and the DefaultConfigurationNode class. Some deprecated methods in HierarchicalConfiguration have also been removed.
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DefaultConfigurationBuilder.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.java commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.jj commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestXMLBeanDeclaration.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DefaultConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DefaultConfigurationBuilder.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DefaultConfigurationBuilder.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DefaultConfigurationBuilder.java Sat Feb 23 12:18:51 2008 @@ -639,9 +639,9 @@ { List<ConfigurationNode> children = node.getChildren(); List<SubnodeConfiguration> result = new ArrayList<SubnodeConfiguration>(children.size()); - for (Iterator it = children.iterator(); it.hasNext();) + for (ConfigurationNode child : children) { - result.add(createSubnodeConfiguration((Node) it.next())); + result.add(createSubnodeConfiguration(child)); } return result; } Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfiguration.java Sat Feb 23 12:18:51 2008 @@ -153,11 +153,6 @@ /** Stores the default expression engine to be used for new objects.*/ private static ExpressionEngine defaultExpressionEngine; - /** Stores the root node of this configuration. This field is required for - * backwards compatibility only. - */ - private Node root; - /** Stores the root configuration node.*/ private ConfigurationNode rootNode; @@ -169,7 +164,7 @@ */ public HierarchicalConfiguration() { - setRootNode(new Node()); + setRootNode(new DefaultConfigurationNode()); } /** @@ -193,37 +188,6 @@ } /** - * Returns the root node of this hierarchical configuration. This method - * exists for backwards compatibility only. New code should use the - * <code>[EMAIL PROTECTED] #getRootNode()}</code> method instead, which operates on - * the preferred data type <code>ConfigurationNode</code>. - * - * @return the root node - */ - public Node getRoot() - { - return root; - } - - /** - * Sets the root node of this hierarchical configuration. This method - * exists for backwards compatibility only. New code should use the - * <code>[EMAIL PROTECTED] #setRootNode(ConfigurationNode)}</code> method instead, - * which operates on the preferred data type <code>ConfigurationNode</code>. - * - * @param node the root node - */ - public void setRoot(Node node) - { - if (node == null) - { - throw new IllegalArgumentException("Root node must not be null!"); - } - root = node; - rootNode = null; - } - - /** * Returns the root node of this hierarchical configuration. * * @return the root node @@ -231,7 +195,7 @@ */ public ConfigurationNode getRootNode() { - return (rootNode != null) ? rootNode : root; + return rootNode; } /** @@ -247,9 +211,6 @@ throw new IllegalArgumentException("Root node must not be null!"); } this.rootNode = rootNode; - - // For backward compatibility also set the old root field. - root = (rootNode instanceof Node) ? (Node) rootNode : new Node(rootNode); } /** @@ -934,20 +895,6 @@ * removed. * * @param node the node to be removed - * @deprecated Use the method <code>[EMAIL PROTECTED] #removeNode(ConfigurationNode)}</code> - * instead. - */ - protected void removeNode(Node node) - { - removeNode((ConfigurationNode) node); - } - - /** - * Removes the specified node from this configuration. This method ensures - * that parent nodes that become undefined by this operation are also - * removed. - * - * @param node the node to be removed */ protected void removeNode(ConfigurationNode node) { @@ -967,19 +914,6 @@ * this operation, it is removed from the hierarchy. * * @param node the node to be cleared - * @deprecated Use the method <code>[EMAIL PROTECTED] #clearNode(ConfigurationNode)}</code> - * instead - */ - protected void clearNode(Node node) - { - clearNode((ConfigurationNode) node); - } - - /** - * Clears the value of the specified node. If the node becomes undefined by - * this operation, it is removed from the hierarchy. - * - * @param node the node to be cleared */ protected void clearNode(ConfigurationNode node) { @@ -991,63 +925,6 @@ } /** - * Returns a reference to the parent node of an add operation. Nodes for new - * properties can be added as children of this node. If the path for the - * specified key does not exist so far, it is created now. - * - * @param keyIt the iterator for the key of the new property - * @param startNode the node to start the search with - * @return the parent node for the add operation - * @deprecated Adding new properties is now to a major part delegated to the - * <code>ExpressionEngine</code> associated with this configuration instance. - * This method will no longer be called. Developers who want to modify the - * process of adding new properties should consider implementing their own - * expression engine. - */ - protected Node fetchAddNode(ConfigurationKey.KeyIterator keyIt, Node startNode) - { - return null; - } - - /** - * Finds the last existing node for an add operation. This method traverses - * the configuration tree along the specified key. The last existing node on - * this path is returned. - * - * @param keyIt the key iterator - * @param node the actual node - * @return the last existing node on the given path - * @deprecated Adding new properties is now to a major part delegated to the - * <code>ExpressionEngine</code> associated with this configuration instance. - * This method will no longer be called. Developers who want to modify the - * process of adding new properties should consider implementing their own - * expression engine. - */ - protected Node findLastPathNode(ConfigurationKey.KeyIterator keyIt, Node node) - { - return null; - } - - /** - * Creates the missing nodes for adding a new property. This method ensures - * that there are corresponding nodes for all components of the specified - * configuration key. - * - * @param keyIt the key iterator - * @param root the base node of the path to be created - * @return the last node of the path - * @deprecated Adding new properties is now to a major part delegated to the - * <code>ExpressionEngine</code> associated with this configuration instance. - * This method will no longer be called. Developers who want to modify the - * process of adding new properties should consider implementing their own - * expression engine. - */ - protected Node createAddPath(ConfigurationKey.KeyIterator keyIt, Node root) - { - return null; - } - - /** * Creates a new <code>Node</code> object with the specified name. This * method can be overloaded in derived classes if a specific node type is * needed. This base implementation always returns a new object of the @@ -1056,9 +933,9 @@ * @param name the name of the new node * @return the new node */ - protected Node createNode(String name) + protected ConfigurationNode createNode(String name) { - return new Node(name); + return new DefaultConfigurationNode(name); } /** @@ -1117,135 +994,6 @@ } /** - * A data class for storing (hierarchical) property information. A property - * can have a value and an arbitrary number of child properties. From - * version 1.3 on this class is only a thin wrapper over the - * <code>[EMAIL PROTECTED] org.apache.commons.configuration2.tree.DefaultConfigurationNode DefaultconfigurationNode}</code> - * class that exists mainly for the purpose of backwards compatibility. - */ - public static class Node extends DefaultConfigurationNode implements Serializable - { - /** - * The serial version UID. - */ - private static final long serialVersionUID = -6357500633536941775L; - - /** - * Creates a new instance of <code>Node</code>. - */ - public Node() - { - super(); - } - - /** - * Creates a new instance of <code>Node</code> and sets the name. - * - * @param name the node's name - */ - public Node(String name) - { - super(name); - } - - /** - * Creates a new instance of <code>Node</code> and sets the name and the value. - * - * @param name the node's name - * @param value the value - */ - public Node(String name, Object value) - { - super(name, value); - } - - /** - * Creates a new instance of <code>Node</code> 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 child : src.getChildren()) - { - addChild(child); - } - for (ConfigurationNode attr : src.getAttributes()) - { - addAttribute(attr); - } - } - - /** - * Returns the parent of this node. - * - * @return this node's parent (can be <b>null</b>) - */ - public Node getParent() - { - return (Node) getParentNode(); - } - - /** - * Sets the parent of this node. - * - * @param node the parent node - */ - public void setParent(Node node) - { - setParentNode(node); - } - - /** - * Adds the given node to the children of this node. - * - * @param node the child to be added - */ - public void addChild(Node node) - { - addChild((ConfigurationNode) node); - } - - /** - * Returns a flag whether this node has child elements. - * - * @return <b>true</b> if there is a child node, <b>false</b> otherwise - */ - public boolean hasChildren() - { - return getChildrenCount() > 0 || getAttributeCount() > 0; - } - - /** - * Removes the specified child from this node. - * - * @param child the child node to be removed - * @return a flag if the child could be found - */ - public boolean remove(Node child) - { - return child.isAttribute() ? removeAttribute(child) : removeChild(child); - } - - /** - * Removes all children with the given name. - * - * @param name the name of the children to be removed - * @return a flag if children with this name existed - */ - public boolean remove(String name) - { - boolean childrenRemoved = removeChild(name); - boolean attrsRemoved = removeAttribute(name); - return childrenRemoved || attrsRemoved; - } - } - - /** * A specialized visitor that checks if a node is defined. * "Defined" in this terms means that the node or at least one of * its sub nodes is associated with a value. @@ -1464,8 +1212,8 @@ Collection<ConfigurationNode> subNodes = new LinkedList<ConfigurationNode>(node.getChildren()); subNodes.addAll(node.getAttributes()); Iterator<ConfigurationNode> children = subNodes.iterator(); - Node sibling1 = null; - Node nd = null; + ConfigurationNode sibling1 = null; + ConfigurationNode nd = null; while (children.hasNext()) { @@ -1473,17 +1221,17 @@ do { sibling1 = nd; - nd = (Node) children.next(); + nd = children.next(); } while (nd.getReference() != null && children.hasNext()); if (nd.getReference() == null) { // find all following new nodes - List<Node> newNodes = new LinkedList<Node>(); + List<ConfigurationNode> newNodes = new LinkedList<ConfigurationNode>(); newNodes.add(nd); while (children.hasNext()) { - nd = (Node) children.next(); + nd = children.next(); if (nd.getReference() == null) { newNodes.add(nd); @@ -1495,8 +1243,8 @@ } // Insert all new nodes - Node sibling2 = (nd.getReference() == null) ? null : nd; - for (Node insertNode : newNodes) + ConfigurationNode sibling2 = (nd.getReference() == null) ? null : nd; + for (ConfigurationNode insertNode : newNodes) { if (insertNode.getReference() == null) { Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/HierarchicalConfigurationXMLReader.java Sat Feb 23 12:18:51 2008 @@ -99,7 +99,7 @@ */ protected void processKeys() { - getConfiguration().getRoot().visit(new SAXVisitor()); + getConfiguration().getRootNode().visit(new SAXVisitor()); } /** Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java Sat Feb 23 12:18:51 2008 @@ -301,7 +301,8 @@ * @param name the node's name * @return the new node */ - protected Node createNode(String name) + @Override + protected ConfigurationNode createNode(String name) { return getParent().createNode(name); } Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java Sat Feb 23 12:18:51 2008 @@ -44,6 +44,7 @@ import javax.xml.transform.stream.StreamResult; import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; @@ -420,10 +421,10 @@ setSystemID(document.getDoctype().getSystemId()); } - constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs); + constructHierarchy(getRootNode(), document.getDocumentElement(), elemRefs); if (elemRefs) { - getRoot().setReference(document.getDocumentElement()); + getRootNode().setReference(document.getDocumentElement()); } } @@ -435,7 +436,7 @@ * @param element the actual XML element * @param elemRefs a flag whether references to the XML elements should be set */ - private void constructHierarchy(Node node, Element element, boolean elemRefs) + private void constructHierarchy(ConfigurationNode node, Element element, boolean elemRefs) { processAttributes(node, element, elemRefs); StringBuilder buffer = new StringBuilder(); @@ -446,7 +447,7 @@ if (w3cNode instanceof Element) { Element child = (Element) w3cNode; - Node childNode = new XMLNode(child.getTagName(), elemRefs ? child : null); + ConfigurationNode childNode = new XMLNode(child.getTagName(), elemRefs ? child : null); constructHierarchy(childNode, child, elemRefs); node.addChild(childNode); handleDelimiters(node, childNode); @@ -458,13 +459,24 @@ } } String text = buffer.toString().trim(); - if (text.length() > 0 || !node.hasChildren()) + if (text.length() > 0 || !hasChildren(node)) { node.setValue(text); } } /** + * Tests whether the specified node has some child elements. + * + * @param node the node to check + * @return a flag whether there are child elements + */ + private boolean hasChildren(ConfigurationNode node) + { + return node.getChildrenCount() > 0 || node.getAttributeCount() > 0; + } + + /** * Helper method for constructing node objects for the attributes of the * given XML element. * @@ -472,7 +484,7 @@ * @param element the actual XML element * @param elemRefs a flag whether references to the XML elements should be set */ - private void processAttributes(Node node, Element element, boolean elemRefs) + private void processAttributes(ConfigurationNode node, Element element, boolean elemRefs) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); ++i) @@ -486,7 +498,7 @@ for (String value : values) { - Node child = new XMLNode(attr.getName(), elemRefs ? element : null); + ConfigurationNode child = new XMLNode(attr.getName(), elemRefs ? element : null); child.setValue(value); node.addAttribute(child); } @@ -501,7 +513,7 @@ * @param parent the parent element * @param child the child element */ - private void handleDelimiters(Node parent, Node child) + private void handleDelimiters(ConfigurationNode parent, ConfigurationNode child) { if (child.getValue() != null) { @@ -520,7 +532,7 @@ { Iterator<String> it = values.iterator(); // Create new node for the original child's first value - Node c = createNode(child.getName()); + ConfigurationNode c = createNode(child.getName()); c.setValue(it.next()); // Copy original attributes to the new node for (ConfigurationNode ndAttr : child.getAttributes()) @@ -528,7 +540,7 @@ ndAttr.setReference(null); c.addAttribute(ndAttr); } - parent.remove(child); + parent.removeChild(child); parent.addChild(c); // add multiple new children @@ -611,7 +623,7 @@ XMLBuilderVisitor builder = new XMLBuilderVisitor(document, isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter()); - builder.processDocument(getRoot()); + builder.processDocument(getRootNode()); return document; } /* try */ catch (DOMException domEx) @@ -631,7 +643,7 @@ * @param name the node's name * @return the new node */ - protected Node createNode(String name) + protected ConfigurationNode createNode(String name) { return new XMLNode(name, null); } @@ -947,7 +959,7 @@ * A specialized <code>Node</code> class that is connected with an XML * element. Changes on a node are also performed on the associated element. */ - class XMLNode extends Node + class XMLNode extends DefaultConfigurationNode { /** * The serial version UID. @@ -1060,7 +1072,7 @@ */ private void updateAttribute() { - XMLBuilderVisitor.updateAttribute(getParent(), getName(), getListDelimiter()); + XMLBuilderVisitor.updateAttribute(getParentNode(), getName(), getListDelimiter()); } /** @@ -1140,7 +1152,7 @@ * * @param rootNode the root node */ - public void processDocument(Node rootNode) + public void processDocument(ConfigurationNode rootNode) { rootNode.visit(this); } Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListConfiguration.java Sat Feb 23 12:18:51 2008 @@ -37,6 +37,7 @@ import org.apache.commons.configuration2.HierarchicalConfiguration; import org.apache.commons.configuration2.MapConfiguration; import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.lang.StringUtils; /** @@ -196,7 +197,7 @@ try { HierarchicalConfiguration config = parser.parse(); - setRoot(config.getRoot()); + setRootNode(config.getRootNode()); } catch (ParseException e) { @@ -207,14 +208,14 @@ public void save(Writer out) throws ConfigurationException { PrintWriter writer = new PrintWriter(out); - printNode(writer, 0, getRoot()); + printNode(writer, 0, getRootNode()); writer.flush(); } /** * Append a node to the writer, indented according to a specific level. */ - private void printNode(PrintWriter out, int indentLevel, Node node) + private void printNode(PrintWriter out, int indentLevel, ConfigurationNode node) { String padding = StringUtils.repeat(" ", indentLevel * INDENT_SIZE); @@ -225,10 +226,10 @@ // get all non trivial nodes List<ConfigurationNode> children = new ArrayList<ConfigurationNode>(node.getChildren()); - Iterator it = children.iterator(); + Iterator<ConfigurationNode> it = children.iterator(); while (it.hasNext()) { - Node child = (Node) it.next(); + ConfigurationNode child = it.next(); if (child.getValue() == null && (child.getChildren() == null || child.getChildren().isEmpty())) { it.remove(); @@ -249,7 +250,7 @@ it = children.iterator(); while (it.hasNext()) { - Node child = (Node) it.next(); + ConfigurationNode child = it.next(); printNode(out, indentLevel + 1, child); @@ -270,7 +271,7 @@ out.print(padding + "}"); // line feed if the dictionary is not in an array - if (node.getParent() != null) + if (node.getParentNode() != null) { out.println(); } @@ -306,7 +307,7 @@ } else if (value instanceof HierarchicalConfiguration) { - printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRoot()); + printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRootNode()); } else if (value instanceof Configuration) { @@ -319,7 +320,7 @@ while (it.hasNext()) { String key = (String) it.next(); - Node node = new Node(key); + ConfigurationNode node = new DefaultConfigurationNode(key); node.setValue(config.getProperty(key)); printNode(out, indentLevel + 1, node); Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.java Sat Feb 23 12:18:51 2008 @@ -6,7 +6,8 @@ import java.util.ArrayList; import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.HierarchicalConfiguration.Node; +import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.lang.StringUtils; @@ -97,7 +98,7 @@ final public PropertyListConfiguration Dictionary() throws ParseException { PropertyListConfiguration configuration = new PropertyListConfiguration(); List children = new ArrayList(); - Node child = null; + ConfigurationNode child = null; jj_consume_token(DICT_BEGIN); label_1: while (true) { @@ -115,7 +116,7 @@ { // prune & graft the nested configuration to the parent configuration HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue(); - Node root = conf.getRoot(); + ConfigurationNode root = conf.getRootNode(); root.setName(child.getName()); children.add(root); } @@ -127,18 +128,18 @@ jj_consume_token(DICT_END); for (int i = 0; i < children.size(); i++) { - child = (Node) children.get(i); - configuration.getRoot().addChild(child); + child = (ConfigurationNode) children.get(i); + configuration.getRootNode().addChild(child); } {if (true) return configuration;} throw new Error("Missing return statement in function"); } - final public Node Property() throws ParseException { + final public ConfigurationNode Property() throws ParseException { String key = null; Object value = null; - Node node = new Node(); + ConfigurationNode node = new DefaultConfigurationNode(); key = String(); node.setName(key); jj_consume_token(EQUAL); Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.jj URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.jj?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.jj (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/PropertyListParser.jj Sat Feb 23 12:18:51 2008 @@ -29,7 +29,8 @@ import java.util.ArrayList; import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.HierarchicalConfiguration.Node; +import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.lang.StringUtils; @@ -157,7 +158,7 @@ { PropertyListConfiguration configuration = new PropertyListConfiguration(); List children = new ArrayList(); - Node child = null; + ConfigurationNode child = null; } { <DICT_BEGIN> @@ -168,7 +169,7 @@ { // prune & graft the nested configuration to the parent configuration HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue(); - Node root = conf.getRoot(); + ConfigurationNode root = conf.getRootNode(); root.setName(child.getName()); children.add(root); } @@ -182,19 +183,19 @@ { for (int i = 0; i < children.size(); i++) { - child = (Node) children.get(i); - configuration.getRoot().addChild(child); + child = (ConfigurationNode) children.get(i); + configuration.getRootNode().addChild(child); } return configuration; } } -Node Property() : +ConfigurationNode Property() : { String key = null; Object value = null; - Node node = new Node(); + ConfigurationNode node = new DefaultConfigurationNode(); } { key = String() Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java Sat Feb 23 12:18:51 2008 @@ -43,6 +43,7 @@ import org.apache.commons.configuration2.HierarchicalConfiguration; import org.apache.commons.configuration2.MapConfiguration; import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; @@ -233,7 +234,7 @@ }; // parse the file - XMLPropertyListHandler handler = new XMLPropertyListHandler(getRoot()); + XMLPropertyListHandler handler = new XMLPropertyListHandler(getRootNode()); try { SAXParserFactory factory = SAXParserFactory.newInstance(); @@ -266,7 +267,7 @@ writer.println("<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">"); writer.println("<plist version=\"1.0\">"); - printNode(writer, 1, getRoot()); + printNode(writer, 1, getRootNode()); writer.println("</plist>"); writer.flush(); @@ -358,7 +359,7 @@ } else if (value instanceof HierarchicalConfiguration) { - printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRoot()); + printNode(out, indentLevel, ((HierarchicalConfiguration) value).getRootNode()); } else if (value instanceof Configuration) { @@ -371,7 +372,7 @@ { // create a node for each property String key = (String) it.next(); - Node node = new Node(key); + ConfigurationNode node = new DefaultConfigurationNode(key); node.setValue(config.getProperty(key)); // print the node @@ -410,9 +411,9 @@ private StringBuilder buffer = new StringBuilder(); /** The stack of configuration nodes */ - private List<Node> stack = new ArrayList<Node>(); + private List<ConfigurationNode> stack = new ArrayList<ConfigurationNode>(); - public XMLPropertyListHandler(Node root) + public XMLPropertyListHandler(ConfigurationNode root) { push(root); } @@ -420,11 +421,11 @@ /** * Return the node on the top of the stack. */ - private Node peek() + private ConfigurationNode peek() { if (!stack.isEmpty()) { - return (Node) stack.get(stack.size() - 1); + return stack.get(stack.size() - 1); } else { @@ -435,11 +436,11 @@ /** * Remove and return the node on the top of the stack. */ - private Node pop() + private ConfigurationNode pop() { if (!stack.isEmpty()) { - return (Node) stack.remove(stack.size() - 1); + return stack.remove(stack.size() - 1); } else { @@ -450,7 +451,7 @@ /** * Put a node on the top of the stack. */ - private void push(Node node) + private void push(ConfigurationNode node) { stack.add(node); } @@ -473,7 +474,7 @@ node.addValue(config); // push the root on the stack - push(config.getRoot()); + push(config.getRootNode()); } } } @@ -549,7 +550,7 @@ /** * Node extension with addXXX methods to parse the typed data passed by the SAX handler. */ - private static class PListNode extends Node + private static class PListNode extends DefaultConfigurationNode { /** * The serial version UID. Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java Sat Feb 23 12:18:51 2008 @@ -26,8 +26,6 @@ import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.ConfigurationKey; -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.HierarchicalConfiguration.Node; import org.apache.commons.configuration2.event.ConfigurationEvent; import org.apache.commons.configuration2.event.ConfigurationListener; import org.apache.commons.configuration2.tree.ConfigurationNode; @@ -70,14 +68,14 @@ * name */ config = new HierarchicalConfiguration(); - HierarchicalConfiguration.Node nodeTables = createNode("tables", null); + ConfigurationNode nodeTables = createNode("tables", null); for(int i = 0; i < tables.length; i++) { - HierarchicalConfiguration.Node nodeTable = createNode("table", null); + ConfigurationNode nodeTable = createNode("table", null); nodeTables.addChild(nodeTable); - HierarchicalConfiguration.Node nodeName = createNode("name", tables[i]); + ConfigurationNode nodeName = createNode("name", tables[i]); nodeTable.addChild(nodeName); - HierarchicalConfiguration.Node nodeFields = createNode("fields", null); + ConfigurationNode nodeFields = createNode("fields", null); nodeTable.addChild(nodeFields); for (int j = 0; j < fields[i].length; j++) @@ -86,33 +84,13 @@ } } - config.getRoot().addChild(nodeTables); - } - - public void testSetRoot() - { - try - { - config.setRoot(null); - fail("Could set null root node!"); - } - catch(IllegalArgumentException iex) - { - //ok - } - - config.setRoot(new HierarchicalConfiguration.Node("test")); - assertTrue(config.isEmpty()); + config.getRootNode().addChild(nodeTables); } public void testSetRootNode() { - config.setRootNode(new DefaultConfigurationNode("testNode")); - assertNotSame("Same root node", config.getRootNode(), config.getRoot()); - assertEquals("Wrong name of root node", "testNode", config.getRoot().getName()); - - config.setRootNode(new HierarchicalConfiguration.Node("test")); - assertSame("Wrong root node", config.getRootNode(), config.getRoot()); + config.setRootNode(new DefaultConfigurationNode("test")); + assertTrue(config.isEmpty()); } public void testSetRootNodeNull() @@ -133,10 +111,10 @@ assertFalse(config.isEmpty()); HierarchicalConfiguration conf2 = new HierarchicalConfiguration(); assertTrue(conf2.isEmpty()); - HierarchicalConfiguration.Node child1 = new HierarchicalConfiguration.Node("child1"); - HierarchicalConfiguration.Node child2 = new HierarchicalConfiguration.Node("child2"); + ConfigurationNode child1 = new DefaultConfigurationNode("child1"); + ConfigurationNode child2 = new DefaultConfigurationNode("child2"); child1.addChild(child2); - conf2.getRoot().addChild(child1); + conf2.getRootNode().addChild(child1); assertTrue(conf2.isEmpty()); } @@ -607,7 +585,7 @@ public void testAddNodes() { - Collection<HierarchicalConfiguration.Node> nodes = new ArrayList<HierarchicalConfiguration.Node>(); + Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(); nodes.add(createFieldNode("birthDate")); nodes.add(createFieldNode("lastLogin")); nodes.add(createFieldNode("language")); @@ -627,9 +605,9 @@ */ public void testAddNodesForNonExistingKey() { - Collection<HierarchicalConfiguration.Node> nodes = new ArrayList<HierarchicalConfiguration.Node>(); + Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(); nodes.add(createNode("usr", "scott")); - Node nd = createNode("pwd", "tiger"); + ConfigurationNode nd = createNode("pwd", "tiger"); nd.setAttribute(true); nodes.add(nd); config.addNodes("database.connection.settings", nodes); @@ -646,7 +624,7 @@ */ public void testAddNodesWithAttributeKey() { - Collection<HierarchicalConfiguration.Node> nodes = new ArrayList<HierarchicalConfiguration.Node>(); + Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(); nodes.add(createNode("testNode", "yes")); try { @@ -688,40 +666,35 @@ */ public void testNodeRemove() { - HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node( + ConfigurationNode node = new DefaultConfigurationNode( "parent", "test"); - assertFalse(node.hasChildren()); node.removeChildren(); // should have no effect - assertFalse(node.remove("child")); + assertFalse(node.removeChild("child")); node.addChild(createNode("test", "test")); - assertTrue(node.hasChildren()); - assertTrue(node.remove("test")); - assertFalse(node.hasChildren()); + assertTrue(node.removeChild("test")); for (int i = 0; i < 10; i++) { node.addChild(createNode("child" + i, "test" + i)); } - assertTrue(node.hasChildren()); - assertFalse(node.remove("child")); - assertTrue(node.remove("child2")); + assertFalse(node.removeChild("child")); + assertTrue(node.removeChild("child2")); assertTrue(node.getChildren("child2").isEmpty()); - HierarchicalConfiguration.Node child = createNode("child0", "testChild"); - assertFalse(node.remove(child)); + ConfigurationNode child = createNode("child0", "testChild"); + assertFalse(node.removeChild(child)); node.addChild(child); - assertTrue(node.remove(child)); + assertTrue(node.removeChild(child)); assertEquals(1, node.getChildren("child0").size()); - assertEquals("test0", ((HierarchicalConfiguration.Node) node - .getChildren("child0").get(0)).getValue()); + assertEquals("test0", node.getChildren("child0").get(0).getValue()); - assertTrue(node.remove("child0")); - assertFalse(node.remove(child)); + assertTrue(node.removeChild("child0")); + assertFalse(node.removeChild(child)); node.removeChildren(); assertTrue(node.getChildren().isEmpty()); - assertFalse(node.remove(child)); + assertFalse(node.removeChild(child)); } /** @@ -730,7 +703,7 @@ public void testNodeVisitor() { CountVisitor v = new CountVisitor(); - config.getRoot().visit(v); + config.getRootNode().visit(v); assertEquals(28, v.beforeCount); assertEquals(v.beforeCount, v.afterCount); } @@ -1017,9 +990,9 @@ * @param name the name of the field * @return the field node */ - private static HierarchicalConfiguration.Node createFieldNode(String name) + private static ConfigurationNode createFieldNode(String name) { - HierarchicalConfiguration.Node fld = createNode("field", null); + ConfigurationNode fld = createNode("field", null); fld.addChild(createNode("name", name)); return fld; } @@ -1030,9 +1003,9 @@ * @param value the node's value * @return the new node */ - private static HierarchicalConfiguration.Node createNode(String name, Object value) + private static ConfigurationNode createNode(String name, Object value) { - HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name); + ConfigurationNode node = new DefaultConfigurationNode(name); node.setValue(value); return node; } Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java Sat Feb 23 12:18:51 2008 @@ -93,7 +93,7 @@ { setUpSubnodeConfig(); assertSame("Wrong root node in subnode", getSubnodeRoot(parent), config - .getRoot()); + .getRootNode()); assertSame("Wrong parent config", parent, config.getParent()); } @@ -482,7 +482,8 @@ { // Provide a special implementation of createNode() to check // if it is called by the subnode config - protected Node createNode(String name) + @Override + protected ConfigurationNode createNode(String name) { nodeCounter++; return super.createNode(name); @@ -509,7 +510,7 @@ */ protected ConfigurationNode getSubnodeRoot(HierarchicalConfiguration conf) { - ConfigurationNode root = conf.getRoot(); + ConfigurationNode root = conf.getRootNode(); return root.getChild(0).getChild(0); } Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java Sat Feb 23 12:18:51 2008 @@ -45,6 +45,7 @@ import org.apache.commons.configuration2.reloading.FileAlwaysReloadingStrategy; import org.apache.commons.configuration2.reloading.InvariantReloadingStrategy; import org.apache.commons.configuration2.tree.ConfigurationNode; +import org.apache.commons.configuration2.tree.DefaultConfigurationNode; import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -1207,9 +1208,9 @@ { conf.setFile(testSaveConf); conf.setAutoSave(true); - HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node( + ConfigurationNode node = new DefaultConfigurationNode( "addNodesTest", Boolean.TRUE); - Collection nodes = new ArrayList(1); + Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(1); nodes.add(node); conf.addNodes("test.autosave", nodes); XMLConfiguration c2 = new XMLConfiguration(testSaveConf); @@ -1223,13 +1224,13 @@ */ public void testAddNodesAndSave() throws ConfigurationException { - ConfigurationNode node = new HierarchicalConfiguration.Node("test"); - ConfigurationNode child = new HierarchicalConfiguration.Node("child"); + ConfigurationNode node = new DefaultConfigurationNode("test"); + ConfigurationNode child = new DefaultConfigurationNode("child"); node.addChild(child); - ConfigurationNode attr = new HierarchicalConfiguration.Node("attr"); + ConfigurationNode attr = new DefaultConfigurationNode("attr"); node.addAttribute(attr); ConfigurationNode node2 = conf.createNode("test2"); - Collection nodes = new ArrayList(2); + Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(2); nodes.add(node); nodes.add(node2); conf.addNodes("add.nodes", nodes); Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestXMLBeanDeclaration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestXMLBeanDeclaration.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestXMLBeanDeclaration.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestXMLBeanDeclaration.java Sat Feb 23 12:18:51 2008 @@ -133,7 +133,7 @@ try { decl = new XMLBeanDeclaration(null, new HierarchicalConfiguration() - .getRoot()); + .getRootNode()); fail("Could init declaration with null configuration and node!"); } catch (IllegalArgumentException iex) Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java Sat Feb 23 12:18:51 2008 @@ -161,7 +161,7 @@ assertEquals("Wrong field", "docname", c .getString("fields.field(1).name")); - List nds = config.getExpressionEngine().query(config.getRoot(), + List nds = config.getExpressionEngine().query(config.getRootNode(), "database.tables.table"); assertFalse("No node found", nds.isEmpty()); return (ConfigurationNode) nds.get(0); Modified: commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml?rev=630530&r1=630529&r2=630530&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml (original) +++ commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Sat Feb 23 12:18:51 2008 @@ -57,6 +57,12 @@ <action dev="ebourg" type="update"> DefaultConfigurationBuilder no longer requires commons-beanutils. </action> + <action dev="oheger" type="remove"> + The inner classes Node and NodeVisitor of HierarchicalConfiguration have + been removed. They existed only for reasons of backwards compatibility. + Their functionality is completely covered by classes in the tree + package. + </action> </release> <release version="1.6" date="in SVN" description="">