Skip to content

Commit

Permalink
allow for converting a property value based on the corresponding prop…
Browse files Browse the repository at this point in the history
…erty name (SPR-7386)
  • Loading branch information
jhoeller committed Jul 21, 2010
1 parent 11886f2 commit 4d5a9c4
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,16 +92,29 @@ protected void convertProperties(Properties props) {
while (propertyNames.hasMoreElements()) {
String propertyName = (String) propertyNames.nextElement();
String propertyValue = props.getProperty(propertyName);
String convertedValue = convertPropertyValue(propertyValue);
String convertedValue = convertProperty(propertyName, propertyValue);
if (!ObjectUtils.nullSafeEquals(propertyValue, convertedValue)) {
props.setProperty(propertyName, convertedValue);
}
}
}

/**
* Convert the given property value from the properties source
* to the value that should be applied.
* Convert the given property from the properties source to the value
* which should be applied.
* <p>The default implementation calls {@link #convertPropertyValue(String)}.
* @param propertyName the name of the property that the value is defined for
* @param propertyValue the original value from the properties source
* @return the converted value, to be used for processing
* @see #convertPropertyValue(String)
*/
protected String convertProperty(String propertyName, String propertyValue) {
return convertPropertyValue(propertyValue);
}

/**
* Convert the given property value from the properties source to the value
* which should be applied.
* <p>The default implementation simply returns the original value.
* Can be overridden in subclasses, for example to detect
* encrypted values and decrypt them accordingly.
Expand All @@ -111,14 +124,16 @@ protected void convertProperties(Properties props) {
* @see #setProperties
* @see #setLocations
* @see #setLocation
* @see #convertProperty(String, String)
*/
protected String convertPropertyValue(String originalValue) {
return originalValue;
}


/**
* Apply the given Properties to the given BeanFactory.
* @param beanFactory the BeanFactory used by the application context
* @param beanFactory the BeanFactory used by the application context
* @param props the Properties to apply
* @throws org.springframework.beans.BeansException in case of errors
*/
Expand Down

0 comments on commit 4d5a9c4

Please sign in to comment.