epugh 2003/03/19 02:32:23
Modified: configuration/src/java/org/apache/commons/configuration
CompositeConfiguration.java JNDIConfiguration.java
Log:
Fixes to support being able to setProperties and clearProperties.
Revision Changes Path
1.5 +23 -5
jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java
Index: CompositeConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CompositeConfiguration.java 18 Mar 2003 21:41:56 -0000 1.4
+++ CompositeConfiguration.java 19 Mar 2003 10:32:23 -0000 1.5
@@ -74,14 +74,23 @@
*/
public class CompositeConfiguration implements Configuration
{
+ /** Array holding all the configuration */
private ArrayList configList = new ArrayList();
+ /** Configuration that holds in memory stuff. Inserted as first so any
+ * setProperty() override anything else added.
+ */
+ private BaseConfiguration inMemoryConfiguration;
+
/**
* Creates an empty CompositeConfiguration object which can then
* be added some other Configuration files
*/
public CompositeConfiguration()
- {}
+ {
+ inMemoryConfiguration = new BaseConfiguration();
+ addConfiguration(inMemoryConfiguration);
+ }
public void addConfiguration(Configuration config)
{
@@ -104,6 +113,10 @@
public void clear()
{
configList.clear();
+ // recreate the inmemory configuration
+ inMemoryConfiguration = new BaseConfiguration();
+ addConfiguration(inMemoryConfiguration);
+
}
/**
@@ -114,7 +127,7 @@
*/
public void addProperty(String key, Object token)
{
- throw new Error("This operation is not supported");
+ inMemoryConfiguration.addProperty(key, token);
}
/**
@@ -212,7 +225,8 @@
*/
public void setProperty(String key, Object value)
{
- getFirstMatchingConfig(key).setProperty(key, value);
+ clearProperty(key);
+ addProperty(key,value);
}
/**
@@ -222,7 +236,11 @@
*/
public void clearProperty(String key)
{
- throw new Error("This operation is not supported");
+ for (ListIterator i = configList.listIterator(); i.hasNext();)
+ {
+ Configuration config = (Configuration) i.next();
+ config.clearProperty(key);
+ }
}
/**
1.3 +17 -4
jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java
Index: JNDIConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JNDIConfiguration.java 18 Mar 2003 21:41:56 -0000 1.2
+++ JNDIConfiguration.java 19 Mar 2003 10:32:23 -0000 1.3
@@ -58,6 +58,7 @@
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Vector;
+import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -75,6 +76,7 @@
private String prefix;
private Context envCtx;
+ private Map clearedProperties = new HashMap();
/**
* Creates an empty JNDIConfiguration object which can then
@@ -166,20 +168,26 @@
}
/**
- * Clear a property in the configuration.
+ * Clear a property in the configuration. Just marks it as cleared,
+ * doesn't change the underlying JNDI data source.
*
* @param key the key to remove along with corresponding value.
*/
public void clearProperty(String key)
{
- throw new Error("This operation is not supported");
+ clearedProperties.put(key, key);
}
/**
- * check if the configuration contains the key
+ * check if the configuration contains the key, or the key
+ * has been removed.
*/
public boolean containsKey(String key)
{
+ if (clearedProperties.containsKey(key)){
+ return false;
+ }
+
key = StringUtils.replace(key, ".", "/");
try
{
@@ -643,6 +651,10 @@
private String getValueFromJNDI(String key)
{
+ if (clearedProperties.containsKey(key))
+ {
+ return null;
+ }
try
{
key = StringUtils.replace(key, ".", "/");
@@ -662,4 +674,5 @@
}
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]