You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by dr...@apache.org on 2010/04/21 08:31:37 UTC
svn commit: r936172 - in /tapestry/tapestry5/trunk/tapestry-spring: ./
src/main/java/org/apache/tapestry5/internal/spring/
src/main/java/org/apache/tapestry5/spring/ src/site/apt/
src/test/java/org/apache/tapestry5/spring/ src/test/java/org/example/tes...
Author: drobiazko
Date: Wed Apr 21 06:31:36 2010
New Revision: 936172
URL: http://svn.apache.org/viewvc?rev=936172&view=rev
Log:
TAP5-1077: Merge symbol values into property values from a bean definition
Added:
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java (with props)
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-spring/ (props changed)
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java
tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
Propchange: tapestry/tapestry5/trunk/tapestry-spring/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Apr 21 06:31:36 2010
@@ -7,3 +7,5 @@ bin-test
.classpath
.project
.settings
+
+test-output
Added: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java?rev=936172&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java (added)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java Wed Apr 21 06:31:36 2010
@@ -0,0 +1,42 @@
+// Copyright 2010 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.internal.spring;
+
+import java.util.Properties;
+
+import org.apache.tapestry5.ioc.services.SymbolSource;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+
+public class SymbolBeanFactoryPostProcessor extends PropertyPlaceholderConfigurer
+{
+
+ private SymbolSource symbolSource;
+
+ public SymbolBeanFactoryPostProcessor(SymbolSource symbolSource)
+ {
+ super();
+ this.symbolSource = symbolSource;
+ }
+
+ @Override
+ protected String resolvePlaceholder(String placeholder, Properties props)
+ {
+ String value = symbolSource.valueForSymbol(placeholder);
+
+ if(value != null ) return value;
+
+ return super.resolvePlaceholder(placeholder, props);
+ }
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SymbolBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java Wed Apr 21 06:31:36 2010
@@ -14,19 +14,24 @@
package org.apache.tapestry5.spring;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tapestry5.internal.spring.SymbolBeanFactoryPostProcessor;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.annotations.Marker;
import org.apache.tapestry5.ioc.annotations.Primary;
import org.apache.tapestry5.ioc.services.ChainBuilder;
+import org.apache.tapestry5.ioc.services.SymbolSource;
import org.apache.tapestry5.services.ApplicationInitializer;
import org.apache.tapestry5.services.ApplicationInitializerFilter;
import org.apache.tapestry5.services.Context;
import org.slf4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.core.SpringVersion;
-
-import java.util.List;
+import org.springframework.web.context.ConfigurableWebApplicationContext;
/**
* Module for Tapestry/Spring Integration. This module exists to force the load of the Spring ApplicationContext as part
@@ -78,4 +83,22 @@ public class SpringModule
{
return builder.build(ApplicationContextCustomizer.class, configuration);
}
+
+ public static void contributeApplicationContextCustomizer(
+ OrderedConfiguration<ApplicationContextCustomizer> configuration,
+ final SymbolSource symbolSource)
+ {
+ ApplicationContextCustomizer beanFactoryPostProcessorCustomizer = new ApplicationContextCustomizer()
+ {
+
+ public void customizeApplicationContext(ServletContext servletContext,
+ ConfigurableWebApplicationContext applicationContext)
+ {
+ applicationContext.addBeanFactoryPostProcessor(new SymbolBeanFactoryPostProcessor(symbolSource));
+
+ }
+ };
+
+ configuration.add("BeanFactoryPostProcessorCustomizer", beanFactoryPostProcessorCustomizer);
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt Wed Apr 21 06:31:36 2010
@@ -73,6 +73,18 @@ Usage
Searching for Spring beans is threaded into the {{{../tapestry-ioc/injection.html}MasterObjectProvider service}}. The Spring context becomes one
more place that Tapestry searches when determining the injection for a injected field or method parameter.
+
+* Configuring Spring with Tapestry Symbols
+
+ As of version 5.2.0 it is possible to configure individual bean property values from Tapestry symbols. This is accomplished by a BeanFactoryPostProcessors
+ that resolves the values of 'placeholders' from symbol values. In the following example the value of the Bean's property 'productionMode' is the value of the Tapestry's
+ symbol {{{..apidocs/org/apache/tapestry5/SymbolConstants.html#PRODUCTION_MODE}tapestry.production-mode}}
+
++----+
+ <bean id="myBean" class="org.example.MyBean">
+ <property name="productionMode" value="${tapestry.production-mode}"/>
+ </bean>
++----+
ApplicationContext Service
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java Wed Apr 21 06:31:36 2010
@@ -68,4 +68,12 @@ public class TapestrySpringIntegrationTe
assertEquals(getText("viaFactory"), "Instantiated via a factory bean.");
}
+
+ @Test
+ public void symbol_bean_factory_post_processor() throws Exception
+ {
+ open(BASE_URL);
+
+ assertEquals(getText("symbolValueHolder"), "Start page is 'start'");
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java Wed Apr 21 06:31:36 2010
@@ -14,17 +14,18 @@
package org.example.testapp.pages;
+import java.util.Arrays;
+
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Retain;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.example.testapp.services.SpringStatusProvider;
+import org.example.testapp.services.SymbolValueHolder;
import org.example.testapp.services.Upcase;
import org.example.testapp.services.ViaFactory;
import org.springframework.context.ApplicationContext;
-import java.util.Arrays;
-
public class Start
{
@Retain
@@ -44,6 +45,10 @@ public class Start
@Inject
@Property
private ViaFactory viaFactory;
+
+ @Inject
+ @Property
+ private SymbolValueHolder symbolValueHolder;
void onSuccess()
{
Added: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java?rev=936172&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java (added)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java Wed Apr 21 06:31:36 2010
@@ -0,0 +1,29 @@
+// Copyright 2010 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.example.testapp.services;
+
+public class SymbolValueHolder
+{
+ private String value;
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SymbolValueHolder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml Wed Apr 21 06:31:36 2010
@@ -21,6 +21,8 @@
<dd id="message">${statusProvider.status}</dd>
<dt>Via factory:</dt>
<dd id="viaFactory">${viaFactory.message}</dd>
+ <dt>Symbol Value Holder:</dt>
+ <dd id="symbolValueHolder">Start page is '${symbolValueHolder.value}'</dd>
</dl>
</body>
Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml?rev=936172&r1=936171&r2=936172&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml Wed Apr 21 06:31:36 2010
@@ -31,5 +31,9 @@
<bean id="barney" class="org.example.testapp.services.FlintstoneImpl"/>
<bean id="viaFactory" class="org.example.testapp.services.ViaFactoryFactory"/>
+
+ <bean id="symbolValueHolder" class="org.example.testapp.services.SymbolValueHolder">
+ <property name="value" value="${tapestry.start-page-name}"/>
+ </bean>
</beans>