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
This commit is contained in:
Stephen Colebourne 2006-07-18 22:44:49 +00:00
parent f8aa3e033c
commit 3f09772b74
3 changed files with 62 additions and 6 deletions

View File

@ -55,6 +55,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
<center><h3>BUG FIXES</h3></center>
<ul>
<li>Flat3Map - Fix setValue in MapIterator and EntrySetIterator to work correctly [COLLECTIONS-217]</li>
<li>ExtendedProperties - Include property name had confused static/instance semantics [COLLECTIONS-214]</li>
</ul>
<center><h3>JAVADOC</h3></center>

View File

@ -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".
* <p>
* 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".
* <p>
* 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;

View File

@ -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());
}
}