Skip to content
Snippets Groups Projects
Commit 291d28a0 authored by Damian Minkov's avatar Damian Minkov
Browse files

Fixes removing properties with partial match, and adds tests for it.

parent 3ca63030
No related branches found
No related tags found
No related merge requests found
...@@ -332,9 +332,34 @@ public void removeProperty(String propertyName) ...@@ -332,9 +332,34 @@ public void removeProperty(String propertyName)
//remove all properties //remove all properties
for (String pName : childPropertyNames) for (String pName : childPropertyNames)
{ {
removeProperty(pName); removePropertyInternal(pName);
} }
try
{
storeConfiguration();
}
catch (IOException ex)
{
logger.error("Failed to store configuration after "
+ "a property change");
}
}
/**
* Removes the property with the specified name. Calling
* this method would first trigger a PropertyChangeEvent that will
* be dispatched to all VetoableChangeListeners. In case no complaints
* (PropertyVetoException) have been received, the property will be actually
* changed and a PropertyChangeEvent will be dispatched.
* All properties with prefix propertyName will also be removed.
* <p>
* Does not store anything.
*
* @param propertyName the name of the property to change.
*/
private void removePropertyInternal(String propertyName)
{
Object oldValue = getProperty(propertyName); Object oldValue = getProperty(propertyName);
//first check whether the change is ok with everyone //first check whether the change is ok with everyone
if (changeEventDispatcher.hasVetoableChangeListeners(propertyName)) if (changeEventDispatcher.hasVetoableChangeListeners(propertyName))
...@@ -352,16 +377,6 @@ public void removeProperty(String propertyName) ...@@ -352,16 +377,6 @@ public void removeProperty(String propertyName)
if (changeEventDispatcher.hasPropertyChangeListeners(propertyName)) if (changeEventDispatcher.hasPropertyChangeListeners(propertyName))
changeEventDispatcher.firePropertyChange( changeEventDispatcher.firePropertyChange(
propertyName, oldValue, null); propertyName, oldValue, null);
try
{
storeConfiguration();
}
catch (IOException ex)
{
logger.error("Failed to store configuration after "
+ "a property change");
}
} }
/** /**
...@@ -508,21 +523,21 @@ private Set<String> getPropertyNamesByPrefix( ...@@ -508,21 +523,21 @@ private Set<String> getPropertyNamesByPrefix(
{ {
for (String key : names) for (String key : names)
{ {
int ix = key.lastIndexOf('.'); if(exactPrefixMatch)
{
int ix = key.lastIndexOf('.');
if(ix == -1) if(ix == -1)
continue; continue;
String keyPrefix = key.substring(0, ix); String keyPrefix = key.substring(0, ix);
if(exactPrefixMatch)
{
if(prefix.equals(keyPrefix)) if(prefix.equals(keyPrefix))
resultSet.add(key); resultSet.add(key);
} }
else else
{ {
if(keyPrefix.startsWith(prefix)) if(key.startsWith(prefix))
resultSet.add(key); resultSet.add(key);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment