tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r694745 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/ main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/structure/ test/app1/ test/java/org/apache/tapestry5/integra...
Date Fri, 12 Sep 2008 17:19:31 GMT
Author: hlship
Date: Fri Sep 12 10:19:30 2008
New Revision: 694745

URL: http://svn.apache.org/viewvc?rev=694745&view=rev
Log:
TAPESTRY-2644: Add a ComponentResources.createPageLink(...) method that uses page class instead
of page name

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCache.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/Page.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
Fri Sep 12 10:19:30 2008
@@ -212,10 +212,24 @@
      *                 providing a context, when the provided context is empty)
      * @param context  the activation context for the page. If omitted, the activation context
is obtained from the
      *                 target page
+     * @return link for a render request to the targetted page
      */
     Link createPageLink(String pageName, boolean override, Object... context);
 
     /**
+     * Creates a page render request link to render a specific page. Using a page class,
rather than a page name, is
+     * more refactoring safe (in the even the page is renamed or moved).
+     *
+     * @param pageClass identifies the page to link to
+     * @param override  if true, the context is used even if empty (normally, the target
page is allowed to passivate,
+     *                  providing a context, when the provided context is empty)
+     * @param context   the activation context for the page. If omitted, the activation context
is obtained from the
+     *                  target page
+     * @return link for a render request to the targetted page
+     */
+    Link createPageLink(Class pageClass, boolean override, Object... context);
+
+    /**
      * Discards all persistent field changes for the page containing the component.  Changes
are eliminated from
      * persistent storage (such as the {@link org.apache.tapestry5.services.Session}) which
will take effect in the
      * <em>next</em> request (the attached page instance is not affected).

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderImpl.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderImpl.java
Fri Sep 12 10:19:30 2008
@@ -32,17 +32,17 @@
 
     private final PersistentFieldManager persistentFieldManager;
 
-    private final ComponentClassResolver resolver;
+    private final ComponentClassResolver componentClassResolver;
 
     public PageLoaderImpl(ComponentTemplateSource templateSource,
                           PageElementFactory pageElementFactory, LinkFactory linkFactory,
-                          PersistentFieldManager persistentFieldManager, ComponentClassResolver
resolver)
+                          PersistentFieldManager persistentFieldManager, ComponentClassResolver
componentClassResolver)
     {
         this.templateSource = templateSource;
         this.pageElementFactory = pageElementFactory;
         this.linkFactory = linkFactory;
         this.persistentFieldManager = persistentFieldManager;
-        this.resolver = resolver;
+        this.componentClassResolver = componentClassResolver;
     }
 
     public Page loadPage(String logicalPageName, Locale locale)
@@ -52,9 +52,9 @@
 
         PageLoaderProcessor processor = new PageLoaderProcessor(templateSource,
                                                                 pageElementFactory, linkFactory,
-                                                                persistentFieldManager);
+                                                                persistentFieldManager, componentClassResolver);
 
-        String pageClassName = resolver.resolvePageNameToClassName(logicalPageName);
+        String pageClassName = componentClassResolver.resolvePageNameToClassName(logicalPageName);
 
         return processor.loadPage(logicalPageName, pageClassName, locale);
     }
@@ -67,5 +67,4 @@
     {
         fireInvalidationEvent();
     }
-
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
Fri Sep 12 10:19:30 2008
@@ -35,6 +35,7 @@
 import org.apache.tapestry5.model.EmbeddedComponentModel;
 import org.apache.tapestry5.runtime.RenderQueue;
 import org.apache.tapestry5.services.BindingSource;
+import org.apache.tapestry5.services.ComponentClassResolver;
 import org.slf4j.Logger;
 
 import java.util.List;
@@ -90,6 +91,8 @@
 
     private final LinkFactory linkFactory;
 
+    private final ComponentClassResolver componentClassResolver;
+
     private ComponentModel loadingComponentModel;
 
     private ComponentPageElement loadingElement;
@@ -144,12 +147,14 @@
     }
 
     PageLoaderProcessor(ComponentTemplateSource templateSource, PageElementFactory pageElementFactory,
-                        LinkFactory linkFactory, PersistentFieldManager persistentFieldManager)
+                        LinkFactory linkFactory, PersistentFieldManager persistentFieldManager,
+                        ComponentClassResolver componentClassResolver)
     {
         this.templateSource = templateSource;
         this.pageElementFactory = pageElementFactory;
         this.linkFactory = linkFactory;
         this.persistentFieldManager = persistentFieldManager;
+        this.componentClassResolver = componentClassResolver;
     }
 
     private void bindParameterFromTemplate(ComponentPageElement component, AttributeToken
token)
@@ -386,7 +391,10 @@
 
         this.locale = locale;
 
-        page = new PageImpl(logicalPageName, this.locale, linkFactory, persistentFieldManager);
+        // Todo: Need a resources object for Pages, not just ComponentPageElement ... too
many
+        // parameters here.
+
+        page = new PageImpl(logicalPageName, this.locale, linkFactory, persistentFieldManager,
componentClassResolver);
 
         loadRootComponent(pageClassName);
 
@@ -705,7 +713,6 @@
                 {
                     handleInformalParameters(loadingElement, embeddedModel, newComponent,
newComponentModel,
                                              newComponentBindings);
-
                 }
             };
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCache.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCache.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCache.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCache.java
Fri Sep 12 10:19:30 2008
@@ -20,7 +20,6 @@
  * Per-thread service that caches page instances for the duration of the request, and is
also responsible for tracking
  * the active page (the page which will ultimately render the response).
  * <p/>
- * <p/>
  * Since {@link org.apache.tapestry5.internal.structure.Page} is internal, most user-code
should use the {@link
  * org.apache.tapestry5.services.ComponentSource} service instead.
  */

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
Fri Sep 12 10:19:30 2008
@@ -145,6 +145,11 @@
         return page.createPageRenderLink(pageName, override, context);
     }
 
+    public Link createPageLink(Class pageClass, boolean override, Object... context)
+    {
+        return page.createPageRenderLink(pageClass, override, context);
+    }
+
     public void discardPersistentFieldChanges()
     {
         page.discardPersistentFieldChanges();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/Page.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/Page.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/Page.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/Page.java
Fri Sep 12 10:19:30 2008
@@ -127,6 +127,13 @@
     Link createPageRenderLink(String pageName, boolean override, Object... context);
 
     /**
+     * Creates a link to the named page.
+     *
+     * @see org.apache.tapestry5.ComponentResources#createPageLink(Class, boolean, Object[])
+     */
+    Link createPageRenderLink(Class pageClass, boolean override, Object... context);
+
+    /**
      * Posts a change to a persistent field.
      *
      * @param resources the component resources for the component or mixin containing the
field whose value changed

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
Fri Sep 12 10:19:30 2008
@@ -19,10 +19,12 @@
 import org.apache.tapestry5.internal.services.LinkFactory;
 import org.apache.tapestry5.internal.services.PersistentFieldManager;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import static org.apache.tapestry5.ioc.internal.util.Defense.notNull;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.runtime.Component;
 import org.apache.tapestry5.runtime.PageLifecycleListener;
+import org.apache.tapestry5.services.ComponentClassResolver;
 import org.apache.tapestry5.services.PersistentFieldBundle;
 import org.slf4j.Logger;
 
@@ -39,6 +41,8 @@
 
     private final PersistentFieldManager persistentFieldManager;
 
+    private final ComponentClassResolver componentClassResolver;
+
     private ComponentPageElement rootElement;
 
     private final List<PageLifecycleListener> listeners = CollectionFactory.newList();
@@ -52,12 +56,13 @@
     private PersistentFieldBundle fieldBundle;
 
     public PageImpl(String logicalPageName, Locale locale, LinkFactory linkFactory,
-                    PersistentFieldManager persistentFieldManager)
+                    PersistentFieldManager persistentFieldManager, ComponentClassResolver
componentClassResolver)
     {
         this.logicalPageName = logicalPageName;
         this.locale = locale;
         this.linkFactory = linkFactory;
         this.persistentFieldManager = persistentFieldManager;
+        this.componentClassResolver = componentClassResolver;
     }
 
     @Override
@@ -161,6 +166,15 @@
         return linkFactory.createPageLink(pageName, override, context);
     }
 
+    public Link createPageRenderLink(Class pageClass, boolean override, Object... context)
+    {
+        Defense.notNull(pageClass, "pageClass");
+
+        String pageName = componentClassResolver.resolvePageClassNameToPageName(pageClass.getName());
+
+        return linkFactory.createPageLink(pageName, override, context);
+    }
+
     public void persistFieldChange(ComponentResources resources, String fieldName, Object
newValue)
     {
         persistentFieldManager.postChange(logicalPageName, resources, fieldName, newValue);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Fri Sep 12 10:19:30 2008
@@ -17,6 +17,12 @@
 
     <ul>
         <li>
+            <a href="${injectDemoLink}">PageLink via Class Demo</a>
+            -- use ComponentResources to generate a link to a page using target
+            page class, not logical page name
+        </li>
+
+        <li>
             <a href="BadTemplate">BadTemplate Page</a>
             -- More exception reporting
         </li>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Fri Sep 12 10:19:30 2008
@@ -2256,4 +2256,14 @@
         assertTextPresent(
                 "Error obtaining injected value for field org.apache.tapestry5.integration.app1.pages.FailedInjectDemo.buffer:
No service implements the interface java.lang.StringBuffer.");
     }
+
+    /**
+     * TAPESTRTY-2644
+     */
+    public void create_page_link_via_page_class()
+    {
+        start("PageLink via Class Demo");
+
+        assertTextPresent("Demonstrates the use of the @Inject annotation.");
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
Fri Sep 12 10:19:30 2008
@@ -14,7 +14,10 @@
 
 package org.apache.tapestry5.integration.app1.pages;
 
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.Link;
 import org.apache.tapestry5.annotations.InjectPage;
+import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 
 import java.util.Arrays;
@@ -25,7 +28,7 @@
  * Have to start somewhere!
  */
 public class Start
-{    
+{
     public static class Item implements Comparable<Item>
     {
         private final String pageName;
@@ -293,6 +296,9 @@
     @InjectPage
     private SecurePage securePage;
 
+    @Inject
+    private ComponentResources resources;
+
     public List<Item> getItems()
     {
         return ITEMS;
@@ -313,6 +319,11 @@
         return securePage.initialize("Triggered from Start");
     }
 
+    public Link getInjectDemoLink()
+    {
+        return resources.createPageLink(InjectDemo.class, false);
+    }
+
     public List getDemoContext()
     {
         return Arrays.asList(1, 2, 3);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java?rev=694745&r1=694744&r2=694745&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java
Fri Sep 12 10:19:30 2008
@@ -36,7 +36,7 @@
 
         replay();
 
-        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null);
+        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null, null);
 
         assertNull(page.getRootElement());
 
@@ -60,7 +60,7 @@
 
         replay();
 
-        Page page = new PageImpl(null, locale, null, null);
+        Page page = new PageImpl(null, locale, null, null, null);
 
         page.addLifecycleListener(listener1);
         page.addLifecycleListener(listener2);
@@ -82,7 +82,7 @@
 
         replay();
 
-        Page page = new PageImpl(null, locale, null, null);
+        Page page = new PageImpl(null, locale, null, null, null);
 
         page.addLifecycleListener(listener);
 
@@ -116,7 +116,7 @@
 
         replay();
 
-        Page page = new PageImpl(null, locale, null, null);
+        Page page = new PageImpl(null, locale, null, null, null);
         page.setRootElement(element);
 
         page.addLifecycleListener(listener1);
@@ -125,7 +125,6 @@
         assertTrue(page.detached());
 
         verify();
-
     }
 
     protected final void train_getLogger(ComponentPageElement element, Logger logger)
@@ -145,7 +144,7 @@
 
         replay();
 
-        Page page = new PageImpl(null, locale, null, null);
+        Page page = new PageImpl(null, locale, null, null, null);
 
         page.addLifecycleListener(listener1);
         page.addLifecycleListener(listener2);
@@ -171,7 +170,7 @@
 
         replay();
 
-        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null);
+        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null, null);
 
         page.addLifecycleListener(listener1);
         page.addLifecycleListener(listener2);
@@ -188,7 +187,7 @@
 
         replay();
 
-        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null);
+        Page page = new PageImpl(LOGICAL_PAGE_NAME, locale, null, null, null);
 
         page.setRootElement(root);
 



Mime
View raw message