From commits-return-20848-apmail-commons-commits-archive=commons.apache.org@commons.apache.org Mon Aug 1 20:28:31 2011 Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8FF5E7567 for ; Mon, 1 Aug 2011 20:28:31 +0000 (UTC) Received: (qmail 97764 invoked by uid 500); 1 Aug 2011 20:28:30 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 97657 invoked by uid 500); 1 Aug 2011 20:28:30 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 97649 invoked by uid 99); 1 Aug 2011 20:28:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Aug 2011 20:28:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Aug 2011 20:28:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 98BF623888CD for ; Mon, 1 Aug 2011 20:28:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1152923 - in /commons/proper/configuration/trunk/src: changes/changes.xml java/org/apache/commons/configuration/HierarchicalConfiguration.java test/org/apache/commons/configuration/TestHierarchicalConfiguration.java Date: Mon, 01 Aug 2011 20:28:05 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110801202805.98BF623888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Mon Aug 1 20:28:03 2011 New Revision: 1152923 URL: http://svn.apache.org/viewvc?rev=1152923&view=rev Log: [CONFIGURATION-458] Provide a specific implementation of clear() in HierarchicalConfiguration. Modified: commons/proper/configuration/trunk/src/changes/changes.xml commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java Modified: commons/proper/configuration/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1152923&r1=1152922&r2=1152923&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/changes/changes.xml (original) +++ commons/proper/configuration/trunk/src/changes/changes.xml Mon Aug 1 20:28:03 2011 @@ -23,6 +23,11 @@ + + HierarchicalConfiguration now provides a specific implementation of the + clear() method. This is more efficient and also solves some other + problems related to clearing a SubnodeConfiguration. + XPathExpressionEngine now provides better support for the setProperty() method. Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=1152923&r1=1152922&r2=1152923&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java Mon Aug 1 20:28:03 2011 @@ -770,6 +770,20 @@ public class HierarchicalConfiguration e } /** + * Clears this configuration. This is a more efficient implementation than + * the one inherited from the base class. It directly removes all data from + * the root node. + */ + public void clear() + { + fireEvent(EVENT_CLEAR, null, null, true); + getRootNode().removeAttributes(); + getRootNode().removeChildren(); + getRootNode().setValue(null); + fireEvent(EVENT_CLEAR, null, null, false); + } + + /** * Removes all values of the property with the given name and of keys that * start with this name. So if there is a property with the key * "foo" and a property with the key "foo.bar", a call Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=1152923&r1=1152922&r2=1152923&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java (original) +++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java Mon Aug 1 20:28:03 2011 @@ -189,6 +189,14 @@ public class TestHierarchicalConfigurati assertEquals(42, config.getInt("test.items.item")); } + public void testClear() + { + config.setProperty(null, "value"); + config.addProperty("[@attr]", "defined"); + config.clear(); + assertTrue("Configuration not empty", config.isEmpty()); + } + public void testClearProperty() { config.clearProperty("tables.table(0).fields.field(0).name"); @@ -580,6 +588,24 @@ public class TestHierarchicalConfigurati } /** + * Tests whether a sub configuration obtained by configurationAt() can be + * cleared. + */ + public void testConfigurationAtClear() + { + config.addProperty("test.sub.test", "fail"); + assertEquals("Wrong index (1)", 0, config.getMaxIndex("test")); + SubnodeConfiguration sub = config.configurationAt("test.sub"); + assertEquals("Wrong value", "fail", sub.getString("test")); + sub.clear(); + assertNull("Key still found", config.getString("test.sub.key")); + sub.setProperty("test", "success"); + assertEquals("Property not set", "success", + config.getString("test.sub.test")); + assertEquals("Wrong index (2)", 0, config.getMaxIndex("test")); + } + + /** * Tests the configurationsAt() method. */ public void testConfigurationsAt()