You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/02/19 04:13:57 UTC

svn commit: r628972 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry/corelib/components/ tapestry-core/src/main/java/org/apache/tapestry/internal/services/ tapestry-core/src/site/apt/guide/ tapestry-core/src/test/java/org...

Author: hlship
Date: Mon Feb 18 19:12:58 2008
New Revision: 628972

URL: http://svn.apache.org/viewvc?rev=628972&view=rev
Log:
TAPESTRY-2173: When Tapestry must instantiate an Application State Object without an explicit ApplicationStateCreator, it should autobuild the object rather than just use the default constructor

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanDisplay.xdoc
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/appstate.apt
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanDisplay.xdoc
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanDisplay.xdoc?rev=628972&r1=628971&r2=628972&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanDisplay.xdoc (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanDisplay.xdoc Mon Feb 18 19:12:58 2008
@@ -111,8 +111,7 @@
 
                 <p>
                     Here we are leveraging the ability to invoke methods as part of a property expression.
-                    We are also highlighting Tapestry's case insensitivity ("lastname" vs. "lastName"), though
-                    that does not yet apply to method names of beans.
+                    We are also highlighting Tapestry's case insensitivity ("lastname" vs. "lastName").
                 </p>
 
             </subsection>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java?rev=628972&r1=628971&r2=628972&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java Mon Feb 18 19:12:58 2008
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry.internal.services;
 
+import org.apache.tapestry.ioc.ObjectLocator;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newConcurrentMap;
 import org.apache.tapestry.services.*;
 
@@ -63,11 +64,14 @@
 
     private final ApplicationStatePersistenceStrategySource _source;
 
+    private final ObjectLocator _locator;
+
     @SuppressWarnings("unchecked")
     public ApplicationStateManagerImpl(Map<Class, ApplicationStateContribution> configuration,
-                                       ApplicationStatePersistenceStrategySource source)
+                                       ApplicationStatePersistenceStrategySource source, ObjectLocator locator)
     {
         _source = source;
+        _locator = locator;
 
         for (Class asoClass : configuration.keySet())
         {
@@ -85,21 +89,16 @@
     private <T> ApplicationStateAdapter<T> newAdapter(final Class<T> asoClass, String strategyName,
                                                       ApplicationStateCreator<T> creator)
     {
-        if (creator == null) creator = new ApplicationStateCreator<T>()
+        if (creator == null)
         {
-            public T create()
+            creator = new ApplicationStateCreator<T>()
             {
-                try
-                {
-                    return asoClass.newInstance();
-                }
-                catch (Exception ex)
+                public T create()
                 {
-                    throw new RuntimeException(ex);
+                    return _locator.autobuild(asoClass);
                 }
-            }
-
-        };
+            };
+        }
 
         ApplicationStatePersistenceStrategy strategy = _source.get(strategyName);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/appstate.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/appstate.apt?rev=628972&r1=628971&r2=628972&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/appstate.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/appstate.apt Mon Feb 18 19:12:58 2008
@@ -35,7 +35,8 @@
   do you provide a logical name.
   Tapestry 5 uses the class name to identify the ASO, so there's no need for a logical name.
   
-  The first time you access an ASO, it is created automatically, using the ASO class's default constructor (public, no arguments).
+  The first time you access an ASO, it is created automatically.  Typically, the ASO will have a public no-args constructor ... but you may
+  inject dependencies into the ASO via its constructor, as you can with a Tapestry IoC service implementation.
   
   Assigning a value to an ASO field will store that value.  Assigning null to an ASO field will remove the ASO (reading the field subsequently
   will force a new ASO instance to be created).
@@ -82,7 +83,7 @@
   as necessary.  This is also the technique to use when you want your ASO to be represented by an <interface> rather than a <class>: you need to provide
   a creator that knows about the class that implements the interface.
   
-  Contributions to the tapestry.ApplicationStateManager are used to configure an ASO.  From you application's module:
+  Contributions to the tapestry.ApplicationStateManager are used to configure an ASO.  From your application's module:
   
 +----+
   public void contributeApplicationStateManager(MappedConfiguration<Class, ApplicationStateContribution> configuration)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java?rev=628972&r1=628971&r2=628972&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java Mon Feb 18 19:12:58 2008
@@ -17,6 +17,7 @@
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.internal.transform.ReadOnlyBean;
 import org.apache.tapestry.internal.util.Holder;
+import org.apache.tapestry.ioc.ObjectLocator;
 import org.apache.tapestry.services.*;
 import org.easymock.EasyMock;
 import static org.easymock.EasyMock.eq;
@@ -51,7 +52,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         assertSame(manager.get(asoClass), aso);
 
@@ -78,7 +79,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         assertFalse(manager.exists(asoClass));
 
@@ -105,7 +106,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         assertTrue(manager.exists(asoClass));
 
@@ -132,7 +133,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         manager.set(asoClass, aso);
 
@@ -147,9 +148,11 @@
         ApplicationStatePersistenceStrategySource source = mockApplicationStatePersistenceStrategySource();
         Class asoClass = ReadOnlyBean.class;
         final Holder holder = new Holder();
+        ObjectLocator locator = mockObjectLocator();
 
         train_get(source, ApplicationStateManagerImpl.DEFAULT_STRATEGY, strategy);
 
+
         IAnswer answer = new IAnswer()
         {
             public Object answer() throws Throwable
@@ -167,11 +170,13 @@
 
         expect(strategy.get(eq(asoClass), isA(ApplicationStateCreator.class))).andAnswer(answer);
 
+        train_autobuild(locator, asoClass, new ReadOnlyBean());
+
         replay();
 
         Map<Class, ApplicationStateContribution> configuration = Collections.emptyMap();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, locator);
 
         Object actual = manager.get(asoClass);
 
@@ -199,7 +204,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         assertNull(manager.getIfExists(asoClass));
 
@@ -227,7 +232,7 @@
 
         replay();
 
-        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source);
+        ApplicationStateManager manager = new ApplicationStateManagerImpl(configuration, source, null);
 
         assertSame(manager.getIfExists(asoClass), aso);
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java?rev=628972&r1=628971&r2=628972&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java Mon Feb 18 19:12:58 2008
@@ -388,4 +388,9 @@
     {
         return newMock(PropertyAccess.class);
     }
+
+    protected final <T> void train_autobuild(ObjectLocator locator, Class<T> beanClass, T instance)
+    {
+        expect(locator.autobuild(beanClass)).andReturn(instance);
+    }
 }