From 3f09772b742d7886c5a18427c9838fb267cc335b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 18 Jul 2006 22:44:49 +0000 Subject: [PATCH] COLLECTIONS-214 - ExtendedProperties - Include property name had confused static/instance semantics git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@423272 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE-NOTES.html | 1 + .../collections/ExtendedProperties.java | 41 ++++++++++++++++--- .../collections/TestExtendedProperties.java | 26 +++++++++++- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES.html b/RELEASE-NOTES.html index 65618bfba..2f9c74f7f 100644 --- a/RELEASE-NOTES.html +++ b/RELEASE-NOTES.html @@ -55,6 +55,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a

BUG FIXES

JAVADOC

diff --git a/src/java/org/apache/commons/collections/ExtendedProperties.java b/src/java/org/apache/commons/collections/ExtendedProperties.java index ab66e2653..7046bc8dd 100644 --- a/src/java/org/apache/commons/collections/ExtendedProperties.java +++ b/src/java/org/apache/commons/collections/ExtendedProperties.java @@ -175,6 +175,15 @@ public class ExtendedProperties extends Hashtable { * This is the name of the property that can point to other * properties file for including other properties files. */ + private String includePropertyName = null; + + /** + * This is the default name of the property that can point to other + * properties file for including other properties files. + * + * @deprecated Use getInclude() and setInclude() methods which operate + * on an instance variable from v3.3. Due to be removed in v4.0. + */ protected static String include = "include"; /** @@ -491,21 +500,42 @@ public class ExtendedProperties extends Hashtable { /** * Gets the property value for including other properties files. * By default it is "include". + *

+ * NOTE: Prior to v3.3 this method accessed a static variable. + * It now accesses an instance variable. For compatability, if the + * instance variable has not been set then the previous static + * variable is then accessed. However, the protected static variable + * can now only be set by subclasses. + * In v4.0, the static variable will be removed. * - * @return A String. + * @return the property name which includes another property */ public String getInclude() { - return include; + if (includePropertyName == null) { + return include; // backwards compatability + } + if ("".equals(includePropertyName)) { + return null; // hack to allow backwards compatability + } + return includePropertyName; } /** * Sets the property value for including other properties files. * By default it is "include". + *

+ * NOTE: Prior to v3.3 this method set a static variable and affected all + * users of the class. It now sets an instance variable. + * An empty string is also now converted to null internally. + * In v4.0, the static variable will be removed. * - * @param inc A String. + * @param inc the property name which includes another property, empty converted to null */ public void setInclude(String inc) { - include = inc; + if (inc == null) { + inc = ""; // hack to allow backwards compatability + } + includePropertyName = inc; } /** @@ -549,6 +579,7 @@ public class ExtendedProperties extends Hashtable { } try { + String includeProperty = getInclude(); while (true) { String line = reader.readProperty(); if (line == null) { @@ -565,7 +596,7 @@ public class ExtendedProperties extends Hashtable { continue; } - if (getInclude() != null && key.equalsIgnoreCase(getInclude())) { + if (includeProperty != null && key.equalsIgnoreCase(includeProperty)) { // Recursively load properties files. File file = null; diff --git a/src/test/org/apache/commons/collections/TestExtendedProperties.java b/src/test/org/apache/commons/collections/TestExtendedProperties.java index ab093c0f1..26d5b9224 100644 --- a/src/test/org/apache/commons/collections/TestExtendedProperties.java +++ b/src/test/org/apache/commons/collections/TestExtendedProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 The Apache Software Foundation + * Copyright 2001-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -313,4 +313,28 @@ public class TestExtendedProperties extends TestCase { assertEquals("class", extended.getString("resource.loader")); } + public void testInclude() { + ExtendedProperties a = new ExtendedProperties(); + ExtendedProperties b = new ExtendedProperties(); + + assertEquals("include", a.getInclude()); + assertEquals("include", b.getInclude()); + + a.setInclude("import"); + assertEquals("import", a.getInclude()); + assertEquals("include", b.getInclude()); + + a.setInclude(""); + assertEquals(null, a.getInclude()); + assertEquals("include", b.getInclude()); + + a.setInclude("hi"); + assertEquals("hi", a.getInclude()); + assertEquals("include", b.getInclude()); + + a.setInclude(null); + assertEquals(null, a.getInclude()); + assertEquals("include", b.getInclude()); + } + }