You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/05/08 06:59:38 UTC

svn commit: r536055 - in /tapestry/tapestry5/trunk/tapestry-spring: ./ src/main/java/org/apache/tapestry/internal/spring/ src/main/java/org/apache/tapestry/spring/ src/main/resources/org/apache/tapestry/spring/ src/site/apt/ src/test/java/org/apache/ta...

Author: hlship
Date: Mon May  7 21:59:37 2007
New Revision: 536055

URL: http://svn.apache.org/viewvc?view=rev&rev=536055
Log:
Marge changes from the temporary branch

Added:
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/internal/spring/SpringModuleDef.java
      - copied unchanged from r536054, tapestry/tapestry5/branches/hlship-20070503/tapestry-spring/src/main/java/org/apache/tapestry/internal/spring/SpringModuleDef.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/TapestrySpringFilter.java
      - copied unchanged from r536054, tapestry/tapestry5/branches/hlship-20070503/tapestry-spring/src/main/java/org/apache/tapestry/spring/TapestrySpringFilter.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringFilterTest.java
      - copied unchanged from r536054, tapestry/tapestry5/branches/hlship-20070503/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringFilterTest.java
Removed:
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringBean.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringModule.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/SampleBean.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/SpringModuleTest.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/AppModule.java
Modified:
    tapestry/tapestry5/trunk/tapestry-spring/   (props changed)
    tapestry/tapestry5/trunk/tapestry-spring/.classpath
    tapestry/tapestry5/trunk/tapestry-spring/pom.xml
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringMessages.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/resources/org/apache/tapestry/spring/SpringStrings.properties
    tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt
    tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/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/WEB-INF/Start.html
    tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/web.xml

Propchange: tapestry/tapestry5/trunk/tapestry-spring/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon May  7 21:59:37 2007
@@ -3,3 +3,4 @@
 temp-testng-customsuite.xml
 cobertura.ser
 null
+bin-test

Modified: tapestry/tapestry5/trunk/tapestry-spring/.classpath
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/.classpath?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/.classpath (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/.classpath Mon May  7 21:59:37 2007
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src/main/java"/>
-	<classpathentry kind="src" path="src/test/java"/>
+	<classpathentry kind="src" output="bin-test" path="src/test/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="lib" path="src/main/resources"/>

Modified: tapestry/tapestry5/trunk/tapestry-spring/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/pom.xml?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/pom.xml Mon May  7 21:59:37 2007
@@ -7,12 +7,12 @@
   <artifactId>tapestry-spring</artifactId>
   <name>Tapestry/Spring Integration Library</name>
   <packaging>jar</packaging>
-  <version>5.0.4</version>
+  <version>5.0.5-SNAPSHOT</version>
   <description>Provides integration of Tapestry with the Spring IoC container.</description>
   <parent>
     <groupId>org.apache.tapestry</groupId>
     <artifactId>tapestry-project</artifactId>
-    <version>5.0.4</version>
+    <version>5.0.5-SNAPSHOT</version>
     <relativePath>../tapestry-project/pom.xml</relativePath>
   </parent>
 
@@ -31,6 +31,10 @@
       <version>1.2.8</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.easymock</groupId>
@@ -67,19 +71,6 @@
           </execution>
         </executions>
       </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <configuration>
-          <archive>
-            <manifestEntries>
-              <Tapestry-Module-Classes>org.apache.tapestry.spring.SpringModule</Tapestry-Module-Classes>
-            </manifestEntries>
-          </archive>
-        </configuration>
-      </plugin>
-
     </plugins>
   </build>
   <reporting>
@@ -115,15 +106,6 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-report-plugin</artifactId>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.tapestry</groupId>
-        <artifactId>tapestry-component-report</artifactId>
-        <version>5.0.2</version>
-        <configuration>
-          <rootPackage>org.apache.tapestry.corelib</rootPackage>
-        </configuration>
       </plugin>
     </plugins>
   </reporting>

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringMessages.java?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry/spring/SpringMessages.java Mon May  7 21:59:37 2007
@@ -14,34 +14,21 @@
 
 package org.apache.tapestry.spring;
 
-import java.util.Collection;
-
 import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.apache.tapestry.ioc.internal.util.MessagesImpl;
 import org.springframework.web.context.ContextLoaderListener;
 
 class SpringMessages
 {
-  private static final Messages MESSAGES = MessagesImpl.forClass(SpringMessages.class);
-
-  static String failureObtainingContext(Throwable cause)
-  {
-    return MESSAGES.format("failure-obtaining-context", cause);
-  }
-
-  static String missingContext()
-  {
-    return MESSAGES.format("missing-context", ContextLoaderListener.class.getName());
-  }
-
-  static String contextStartup(Collection<String> beanNames)
-  {
-    return MESSAGES.format("context-startup", InternalUtils.joinSorted(beanNames));
-  }
+    private static final Messages MESSAGES = MessagesImpl.forClass(SpringMessages.class);
 
-  static String beanAccessFailure(String beanName, Class beanType, Throwable cause)
-  {
-    return MESSAGES.format("bean-access-failure", beanName, beanType.getName(), cause);
-  }
+    static String failureObtainingContext(Throwable cause)
+    {
+        return MESSAGES.format("failure-obtaining-context", cause);
+    }
+
+    static String missingContext()
+    {
+        return MESSAGES.format("missing-context", ContextLoaderListener.class.getName());
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/resources/org/apache/tapestry/spring/SpringStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/resources/org/apache/tapestry/spring/SpringStrings.properties?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/resources/org/apache/tapestry/spring/SpringStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/resources/org/apache/tapestry/spring/SpringStrings.properties Mon May  7 21:59:37 2007
@@ -14,5 +14,3 @@
 
 failure-obtaining-context=An exception occurred obtaining the Spring WebApplicationContext: %s
 missing-context=The Spring WebApplicationContext is not present. The likely cause is that the %s listener was not declared inside the application's web.xml deployment descriptor.
-context-startup=Using Spring WebApplicationContext containing beans: %s
-bean-access-failure=A failure occured obtaining Spring bean '%s' (of type %s): %s

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?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt Mon May  7 21:59:37 2007
@@ -34,7 +34,20 @@
   
 * web.xml changes
   
-  The short form is that you must make a small change to your application's web.xml:
+  The short form is that you must make two small changes to your application's web.xml.
+  
+  First, a special filter is used in replace of the standard TapestryFilter:
+  
++---+
+  <filter>
+    <filter-name>app</filter-name>
+    <!-- Special filter that adds in a T5 IoC module derived from the Spring WebApplicationContext. -->
+    <filter-class>org.apache.tapestry.spring.TapestrySpringFilter</filter-class>
+  </filter>
++---+  
+ 
+   Secondly, you must add the normal Spring configuration, consisting of a \<listener\> element,
+   and (optionally) a \<context-param\> identifying which Spring bean configuration file(s) to load:
  
 +---+
 <context-param>
@@ -55,30 +68,47 @@
 * Injecting beans
 
   Inside your component classes, you may use the 
-  {{{http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/Inject.html}Inject}} annotation in combination with
-  the {{{apidocs/org/apache/tapestry/spring/SpringBean.html}SpringBean}} annotation (to define the name of the bean).
+  {{{http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/Inject.html}Inject}} annotation.  Typically, just the field 
+  type is sufficient to identify the Spring bean to inject:
   
 +----+
   @Inject
-  @SpringBean("userDAO")
   private UserDAO _userDAO;
 +----+
 
-  This also works with parameters to service builder methods.
-
+  If you have multiple beans that implement the same interface (for instance, if you have wrapped your bean using a transaction interceptor), you must disambiguate.  The easiest way
+  to accomplish this is to add a 
+  {{{http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/Service.html}Service}}
+  annotation to identify the name of the
+  Spring bean:
+  
++----+
+  @Inject
+  @Service("UserDAO")
+  private UserDAO _userDAO;
++----+  
+  
+  Injection of Spring beans via service builder methods or autobuilding occurs just the same: the Spring beans masquerade as Tapestry IoC services and all is well.
+ 
 Case Insensitivity
 
-  At startup, the names of all the beans provided by the Spring application context is obtained and use to build a case-insensitive map.
-  When a bean is requested, it is filtered through this map to get the case-sensitive name required by Spring. The upshot of this is that
-  you should not have to be concerned with case: in the above example "Spring:UserDAO" or "SPRING:userdao" would work equally well.
+  Spring beans names are treated exactly as Tapestry IoC service ids.  Since service ids are case insensitive, access to Spring beans by bean name will also
+  be case insensitive.
+  
+WebApplicationContext Service
+
+  The Spring WebApplicationContext is also added as a service, in addition to any services defined within the context.
   
 Limitations
 
-  Case insensitivity is limited to beans whose names are available at application startup; it is possible to programatically add bean definitions
-  at runtime, but these will not be available case-insensitively (but using exactly matching case will still work).
+  The names of beans are obtained at application start up. If new beans are programattically added to the Spring application context at runtime,
+  these will not be visible for injection.
+  
+  Only the bean <name> is used, not any of the bean's <aliases>.
   
-  No check is made for name clashes that would occur when two beans have names that differ only in case.
+  No check is made for name clashes that would occur when two beans have names that differ only in terms of capitalization.  If you're going to go around naming beans "userDAO" and "UserDao",
+  you're just asking for trouble.
   
   Non-singleton beans are not handled properly. Tapestry will request the beans from the application context in a manner unsuitable for their lifecycle.
-  For the moment, you should consider the non-singleton beans to be not-injectable.  Instead, inject the tapestry.spring.WebApplicationContext service and
+  For the moment, you should consider the non-singleton beans to be not-injectable.  Instead, inject the WebApplicationContext service and
   obtain the non-singleton beans as needed.

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringIntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringIntegrationTest.java?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringIntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry/spring/TapestrySpringIntegrationTest.java Mon May  7 21:59:37 2007
@@ -19,14 +19,22 @@
 
 public class TapestrySpringIntegrationTest extends AbstractIntegrationTestSuite
 {
-  @Test
-  public void integration_test() throws Exception
-  {
-    open(BASE_URL);
+    @Test
+    public void integration_test() throws Exception
+    {
+        open(BASE_URL);
 
-    type("input", "paris in the springtime");
-    clickAndWait("//input[@value='Convert']");
+        type("input", "paris in the springtime");
+        clickAndWait("//input[@value='Convert']");
 
-    assertFieldValue("input", "PARIS IN THE SPRINGTIME");
-  }
+        assertFieldValue("input", "PARIS IN THE SPRINGTIME");
+    }
+
+    @Test
+    public void access_to_spring_context() throws Exception
+    {
+        open(BASE_URL);
+
+        assertTextPresent("[upcase]");
+    }
 }

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?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- 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 Mon May  7 21:59:37 2007
@@ -14,21 +14,26 @@
 
 package org.example.testapp.pages;
 
+import java.util.Arrays;
+
 import org.apache.tapestry.annotations.Inject;
 import org.apache.tapestry.annotations.Retain;
-import org.apache.tapestry.spring.SpringBean;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.example.testapp.services.Upcase;
+import org.springframework.web.context.WebApplicationContext;
 
 public class Start
 {
     @Retain
     private String _input;
 
-    // Demonstrating case insensitivity
+    // We're matching on type here, just as we would a service provided in a T5 IoC module.
     @Inject
-    @SpringBean("Upcase")
     private Upcase _upcaseBean;
 
+    @Inject
+    private WebApplicationContext _context;
+
     void onSuccess()
     {
         _input = _upcaseBean.toUpperCase(_input);
@@ -42,6 +47,11 @@
     public void setInput(String input)
     {
         _input = input;
+    }
+
+    public String getSpringBeans()
+    {
+        return InternalUtils.join(Arrays.asList(_context.getBeanDefinitionNames()));
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/Start.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/Start.html?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/Start.html (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/Start.html Mon May  7 21:59:37 2007
@@ -13,5 +13,9 @@
       <br/>
       <input type="submit" value="Convert"/>
     </t:form>
+    
+    <p>
+      Spring beans: [${springBeans}]
+    </p>
   </body>
 </html>

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/web.xml?view=diff&rev=536055&r1=536054&r2=536055
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/web.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/web.xml Mon May  7 21:59:37 2007
@@ -23,7 +23,8 @@
   </context-param>
   <filter>
     <filter-name>app</filter-name>
-    <filter-class>org.apache.tapestry.TapestryFilter</filter-class>
+    <!-- Special filter that adds in a T5 IoC module derived from the Spring WebApplicationContext. -->
+    <filter-class>org.apache.tapestry.spring.TapestrySpringFilter</filter-class>
   </filter>
   <filter-mapping>
     <filter-name>app</filter-name>