From: <fg...@us...> - 2009-11-26 12:29:59
|
Revision: 1501 http://openutils.svn.sourceforge.net/openutils/?rev=1501&view=rev Author: fgiust Date: 2009-11-26 12:29:48 +0000 (Thu, 26 Nov 2009) Log Message: ----------- DEPLOY-2 Nested property support for Property annotation Modified Paths: -------------- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java trunk/openutils-deployment/src/site/changes/changes.xml trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/SampleBean.java trunk/openutils-deployment/src/test/resources/environment.properties trunk/openutils-deployment/src/test/resources/spring-tests.xml Added Paths: ----------- trunk/openutils-deployment/src/test/resources/environment-base.properties Property Changed: ---------------- trunk/openutils-deployment/ Property changes on: trunk/openutils-deployment ___________________________________________________________________ Modified: svn:ignore - .wtpmodules target .classpath .project .settings .checkstyle pom.xml.releaseBackup release.properties + .wtpmodules target .classpath .project .settings .checkstyle pom.xml.releaseBackup release.properties test-output temp-testng-customsuite.xml Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2009-11-26 12:29:48 UTC (rev 1501) @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; +import java.util.HashSet; import java.util.Iterator; import java.util.Properties; @@ -42,6 +43,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.util.ResourceUtils; +import org.springframework.util.StringValueResolver; import org.springframework.web.context.WebApplicationContext; @@ -95,6 +97,8 @@ */ private boolean exposeSystemProperties; + private String nullValue; + /** * Setter for <code>fileLocation</code>. * @param fileLocation The fileLocation to set. @@ -133,6 +137,13 @@ this.exposeSystemProperties = exposeSystemProperties; } + @Override + public void setNullValue(String nullValue) + { + this.nullValue = nullValue; + super.setNullValue(nullValue); + } + /** * {@inheritDoc} */ @@ -373,7 +384,7 @@ public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { - PropertyAnnotationsUtils.autowireProperties(bean, properties); + PropertyAnnotationsUtils.autowireProperties(bean, new PlaceholderResolvingStringValueResolver(properties)); return true; } @@ -413,4 +424,25 @@ { return bean; } + + /** + * BeanDefinitionVisitor that resolves placeholders in String values, delegating to the + * <code>parseStringValue</code> method of the containing class. + */ + protected class PlaceholderResolvingStringValueResolver implements StringValueResolver + { + + private final Properties props; + + public PlaceholderResolvingStringValueResolver(Properties props) + { + this.props = props; + } + + public String resolveStringValue(String strVal) throws BeansException + { + String value = parseStringValue(strVal, this.props, new HashSet()); + return (value.equals(nullValue) ? null : value); + } + } } Modified: trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java 2009-11-26 12:29:48 UTC (rev 1501) @@ -17,10 +17,10 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.Properties; import org.springframework.beans.SimpleTypeConverter; import org.springframework.util.ReflectionUtils; +import org.springframework.util.StringValueResolver; /** @@ -38,7 +38,7 @@ // don't instantiate } - public static void autowireProperties(final Object bean, final Properties properties) + public static void autowireProperties(final Object bean, final StringValueResolver valueResolver) { ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() { @@ -54,7 +54,7 @@ "PropertyAutowired annotation is not supported on static fields"); } - Object strValue = properties.get(annotation.value()); + Object strValue = valueResolver.resolveStringValue("${" + annotation.value() + "}"); if (strValue != null) { @@ -64,6 +64,8 @@ } } } + }); } + } Modified: trunk/openutils-deployment/src/site/changes/changes.xml =================================================================== --- trunk/openutils-deployment/src/site/changes/changes.xml 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/site/changes/changes.xml 2009-11-26 12:29:48 UTC (rev 1501) @@ -8,7 +8,12 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> - <release version="2.1.2" date="in svn" description=""> + + <!-- + MOVED To JIRA + don't update this file anymore, just create issues and mark versions in jira + --> + <release version="2.1.2" date="2009-05-09" description=""> <action type="update" dev="fgiust">EnvironmentLog4jConfigListener now exposes a "server" System property also when log4jExposeWebAppRoot is set to false</action> </release> Modified: trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java =================================================================== --- trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java 2009-11-26 12:29:48 UTC (rev 1501) @@ -52,4 +52,10 @@ Assert.assertEquals("property", System.getProperty("stringProperty")); } + @Test + public void testNestedProperty() + { + Assert.assertEquals("property replaced doublenested", testBean.getNestedProperty()); + } + } Modified: trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/SampleBean.java =================================================================== --- trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/SampleBean.java 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/test/java/it/openutils/deployment/spring/SampleBean.java 2009-11-26 12:29:48 UTC (rev 1501) @@ -32,6 +32,9 @@ @Property("stringProperty") private String stringProperty; + @Property("nested") + private String nestedProperty; + /** * Returns the intProperty. * @return the intProperty @@ -49,4 +52,14 @@ { return stringProperty; } + + /** + * Returns the nestedProperty. + * @return the nestedProperty + */ + public String getNestedProperty() + { + return nestedProperty; + } + } Added: trunk/openutils-deployment/src/test/resources/environment-base.properties =================================================================== --- trunk/openutils-deployment/src/test/resources/environment-base.properties (rev 0) +++ trunk/openutils-deployment/src/test/resources/environment-base.properties 2009-11-26 12:29:48 UTC (rev 1501) @@ -0,0 +1 @@ +base=doublenested \ No newline at end of file Property changes on: trunk/openutils-deployment/src/test/resources/environment-base.properties ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-deployment/src/test/resources/environment.properties =================================================================== --- trunk/openutils-deployment/src/test/resources/environment.properties 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/test/resources/environment.properties 2009-11-26 12:29:48 UTC (rev 1501) @@ -1,2 +1,4 @@ intProperty=2 stringProperty=property +sub= replaced +nested= property ${sub} ${base} \ No newline at end of file Modified: trunk/openutils-deployment/src/test/resources/spring-tests.xml =================================================================== --- trunk/openutils-deployment/src/test/resources/spring-tests.xml 2009-10-27 15:06:20 UTC (rev 1500) +++ trunk/openutils-deployment/src/test/resources/spring-tests.xml 2009-11-26 12:29:48 UTC (rev 1501) @@ -5,7 +5,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean id="environmentProperties" class="it.openutils.deployment.spring.EnvironmentPropertyConfigurer"> - <property name="fileLocation" value="classpath:environment.properties" /> + <property name="fileLocation" value="classpath:environment-base.properties, classpath:environment.properties" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="exposeSystemProperties" value="true" /> </bean> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |