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 2003/04/23 14:29:34 UTC

cvs commit: jakarta-tapestry/junit/mock-scripts TestCycleActivatePage.xml

hlship      2003/04/23 05:29:33

  Modified:    framework/src/org/apache/tapestry TapestryStrings.properties
                        IRequestCycle.java
               framework/src/org/apache/tapestry/engine AbstractEngine.java
                        RequestCycle.java ActionService.java
               .        .classpath
               junit/mock-scripts TestCycleActivatePage.xml
  Log:
  Change services to use IRequestCycle.activate(); move handling of PageRedirectException into AbstractEngine.
  
  Revision  Changes    Path
  1.16      +2 -2      jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties
  
  Index: TapestryStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TapestryStrings.properties	21 Apr 2003 15:40:00 -0000	1.15
  +++ TapestryStrings.properties	23 Apr 2003 12:29:33 -0000	1.16
  @@ -127,6 +127,7 @@
   AbstractEngine.unable-to-create-cleanup-context=Unable to create an instance of RequestContext to process end-of-session page cleanups.
   AbstractEngine.exception-during-cleanup=Exception during post-request cleanup.
   AbstractEngine.exception-during-cache-clear=Exception while clearing caches after request.
  +AbstractEngine.validate-cycle=A validate cycle during page activation was detected: {0}.
   
   ActionService.context-parameters=Service action requires either three or four service contect parameters.
   ActionService.action-component-wrong-type=Component {0} dopes not implement the IAction interface.
  @@ -158,7 +159,6 @@
   
   RequestCycle.invalid-null-name=Parameter name may not be null in RequestCycle.getPage(String).
   RequestCycle.form-rewind-failure=Failure to rewind form {0}.
  -RequestCycle.validate-cycle=A validation cycle during page activation was detected: {0}
   
   ResourceResolver.unable-to-load-class=Could not load class {0} from {1}: {2}
   
  
  
  
  1.6       +2 -2      jakarta-tapestry/framework/src/org/apache/tapestry/IRequestCycle.java
  
  Index: IRequestCycle.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/IRequestCycle.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- IRequestCycle.java	21 Apr 2003 15:40:00 -0000	1.5
  +++ IRequestCycle.java	23 Apr 2003 12:29:33 -0000	1.6
  @@ -144,7 +144,7 @@
       public String getNextActionId();
   
       /**
  -     *  Identifies the page being rendered.
  +     *  Identifies the active page, the page which will ultimately render the response.
        *
        **/
   
  
  
  
  1.10      +100 -29   jakarta-tapestry/framework/src/org/apache/tapestry/engine/AbstractEngine.java
  
  Index: AbstractEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/AbstractEngine.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractEngine.java	21 Apr 2003 15:39:59 -0000	1.9
  +++ AbstractEngine.java	23 Apr 2003 12:29:33 -0000	1.10
  @@ -59,6 +59,7 @@
   import java.io.IOException;
   import java.io.ObjectInput;
   import java.io.ObjectOutput;
  +import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Collections;
   import java.util.HashMap;
  @@ -885,7 +886,7 @@
               }
               catch (PageRedirectException ex)
               {
  -                redirect(ex.getTargetPageName(), cycle, output, ex);
  +                handlePageRedirectException(ex, cycle, output);
               }
               catch (RedirectException ex)
               {
  @@ -966,6 +967,76 @@
       }
   
       /**
  +     *  Handles {@link PageRedirectException} which involves
  +     *  executing {@link IPage#validate(IRequestCycle)} on the target page
  +     *  (of the exception), until either a loop is found, or a page
  +     *  succesfully validates and can be activated.
  +     * 
  +     *  <p>This should generally not be overriden in subclasses.
  +     * 
  +     *  @since 3.0
  +     */
  +
  +    protected void handlePageRedirectException(
  +        PageRedirectException ex,
  +        IRequestCycle cycle,
  +        ResponseOutputStream output)
  +        throws IOException, ServletException
  +    {
  +        List pageNames = new ArrayList();
  +
  +        String pageName = ex.getTargetPageName();
  +
  +        while (true)
  +        {
  +            if (pageNames.contains(pageName))
  +            {
  +                // Add the offending page to pageNames so it shows in the
  +                // list.
  +
  +                pageNames.add(pageName);
  +
  +                StringBuffer buffer = new StringBuffer();
  +                int count = pageNames.size();
  +
  +                for (int i = 0; i < count; i++)
  +                {
  +                    if (i > 0)
  +                        buffer.append("; ");
  +
  +                    buffer.append(pageNames.get(i));
  +                }
  +
  +                throw new ApplicationRuntimeException(
  +                    Tapestry.getString("AbstractEngine.validate-cycle", buffer.toString()));
  +            }
  +
  +            // Record that this page has been a target.
  +
  +            pageNames.add(pageName);
  +
  +            try
  +            {
  +                // Attempt to activate the new page.
  +
  +                cycle.activate(pageName);
  +
  +                break;
  +            }
  +            catch (PageRedirectException ex2)
  +            {
  +                pageName = ex2.getTargetPageName();
  +            }
  +        }
  +
  +        // Discard any output from the previous page.
  +
  +        output.reset();
  +
  +        renderResponse(cycle, output);
  +    }
  +
  +    /**
        *  Invoked from {@link #service(RequestContext)} to create an instance of
        *  {@link IRequestCycle} for the current request.  This implementation creates
        *  an returns an instance of {@link RequestCycle}.
  @@ -1917,20 +1988,20 @@
           if (context.getRequest().getAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE) != null)
               return Tapestry.TAGSUPPORT_SERVICE;
   
  -        String serviceData =  context.getParameter(Tapestry.SERVICE_QUERY_PARAMETER_NAME);
  -        
  -      	if (serviceData == null)
  -      		return Tapestry.HOME_SERVICE;
  -      	
  -      	// The service name is anything before the first slash,
  -      	// if there is one.
  -      		
  -      	int slashx = serviceData.indexOf('/');
  -      	
  -      	if (slashx < 0)
  -      		return serviceData;
  -      		
  -      	return serviceData.substring(0, slashx);
  +        String serviceData = context.getParameter(Tapestry.SERVICE_QUERY_PARAMETER_NAME);
  +
  +        if (serviceData == null)
  +            return Tapestry.HOME_SERVICE;
  +
  +        // The service name is anything before the first slash,
  +        // if there is one.
  +
  +        int slashx = serviceData.indexOf('/');
  +
  +        if (slashx < 0)
  +            return serviceData;
  +
  +        return serviceData.substring(0, slashx);
       }
   
       /** @since 2.3 **/
  @@ -1940,25 +2011,25 @@
           return _propertySource;
       }
   
  -	/** @since 3.0 **/
  +    /** @since 3.0 **/
   
  -	protected String getExceptionPageName()
  -	{
  -		return EXCEPTION_PAGE;
  +    protected String getExceptionPageName()
  +    {
  +        return EXCEPTION_PAGE;
       }
   
  -	/** @since 3.0 **/
  +    /** @since 3.0 **/
   
  -	protected String getStaleLinkPageName()
  -	{
  -		return STALE_LINK_PAGE;
  -	}
  +    protected String getStaleLinkPageName()
  +    {
  +        return STALE_LINK_PAGE;
  +    }
   
  -	/** @since 3.0 **/
  +    /** @since 3.0 **/
   
  -	protected String getStaleSessionPageName()
  -	{
  -		return STALE_SESSION_PAGE;
  +    protected String getStaleSessionPageName()
  +    {
  +        return STALE_SESSION_PAGE;
       }
   
       /**
  
  
  
  1.5       +8 -47     jakarta-tapestry/framework/src/org/apache/tapestry/engine/RequestCycle.java
  
  Index: RequestCycle.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/RequestCycle.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RequestCycle.java	21 Apr 2003 15:39:59 -0000	1.4
  +++ RequestCycle.java	23 Apr 2003 12:29:33 -0000	1.5
  @@ -55,10 +55,8 @@
   
   package org.apache.tapestry.engine;
   
  -import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.List;
   import java.util.Map;
   
   import javax.servlet.http.HttpServletResponse;
  @@ -72,7 +70,6 @@
   import org.apache.tapestry.IMarkupWriter;
   import org.apache.tapestry.IPage;
   import org.apache.tapestry.IRequestCycle;
  -import org.apache.tapestry.PageRedirectException;
   import org.apache.tapestry.RenderRewoundException;
   import org.apache.tapestry.StaleLinkException;
   import org.apache.tapestry.Tapestry;
  @@ -713,59 +710,23 @@
       public void activate(String name)
       {
           IPage page = getPage(name);
  +
           activate(page);
       }
   
  +    /** @since 3.0 */
  +
       public void activate(IPage page)
       {
           if (LOG.isDebugEnabled())
               LOG.debug("Activating page " + page);
   
  -        // using a list is not as fast as using a set, but we need the loop sequence
  -        List activatedPages = new ArrayList();
  -
  -        while (true)
  -        {
  -            // detect loops
  -            int pageIndex = activatedPages.indexOf(page);
  -            if (pageIndex >= 0)
  -            {
  -                StringBuffer pageLoop = new StringBuffer();
  -                int count = activatedPages.size();
  -
  -                for (int i = pageIndex; i < count; i++)
  -                {
  -                    IPage loopPage = (IPage) activatedPages.get(i);
  -                    pageLoop.append(loopPage.getPageName());
  -                    pageLoop.append("; ");
  -                }
  -                pageLoop.append(page.getExtendedId());
  -
  -                throw new ApplicationRuntimeException(
  -                    Tapestry.getString("RequestCycle.validate-cycle", pageLoop.toString()));
  -            }
  -
  -            activatedPages.add(page);
  -
  -            try
  -            {
  -                Tapestry.clearMethodInvocations();
  -
  -                page.validate(this);
  +        Tapestry.clearMethodInvocations();
   
  -                Tapestry.checkMethodInvocation(
  -                    Tapestry.IPAGE_VALIDATE_METHOD_ID,
  -                    "validate()",
  -                    page);
  +        page.validate(this);
   
  -                setPage(page);
  -                break;
  -            }
  -            catch (PageRedirectException ex)
  -            {
  -                page = getPage(ex.getTargetPageName());
  -            }
  -        }
  +        Tapestry.checkMethodInvocation(Tapestry.IPAGE_VALIDATE_METHOD_ID, "validate()", page);
   
  +        setPage(page);
       }
   }
  
  
  
  1.5       +5 -4      jakarta-tapestry/framework/src/org/apache/tapestry/engine/ActionService.java
  
  Index: ActionService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/engine/ActionService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ActionService.java	21 Apr 2003 15:39:59 -0000	1.4
  +++ ActionService.java	23 Apr 2003 12:29:33 -0000	1.5
  @@ -165,6 +165,10 @@
   
           IPage page = cycle.getPage(pageName);
   
  +		// Setup the page for the rewind, then do the rewind.
  +
  +		cycle.activate(page);
  +		
           IPage componentPage = cycle.getPage(componentPageName);
           IComponent component = componentPage.getNestedComponent(targetIdPath);
   
  @@ -192,9 +196,6 @@
                   throw new StaleSessionException();
           }
   
  -        // Setup the page for the rewind, then do the rewind.
  -
  -        cycle.activate(page);
           cycle.rewindPage(targetActionId, action);
   
           // During the rewind, a component may change the page.  This will take
  
  
  
  1.32      +13 -13    jakarta-tapestry/.classpath
  
  Index: .classpath
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/.classpath,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- .classpath	31 Mar 2003 21:47:32 -0000	1.31
  +++ .classpath	23 Apr 2003 12:29:33 -0000	1.32
  @@ -9,23 +9,23 @@
       <classpathentry kind="src" path="examples/Vlib/src"/>
       <classpathentry kind="src" path="examples/Workbench/src"/>
       <classpathentry kind="src" path="examples/wap/src"/>
  -    <classpathentry kind="lib" path="lib/ext/jakarta-oro-2.0.6.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-logging-1.0.2.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/jakarta-oro-2.0.6.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-logging-1.0.2.jar"/>
       <classpathentry kind="var" path="JBOSS_DIR/client/jboss-j2ee.jar"/>
       <classpathentry kind="var" path="JBOSS_DIR/server/all/lib/mail.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-lang-1.0.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/bsf-2.3.0.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/bcel-5.0.jar"/>
  -    <classpathentry kind="var" path="JETTY_DIR/lib/javax.servlet.jar"/>
  -    <classpathentry kind="var" path="JETTY_DIR/ext/javax.xml.jaxp.jar"/>
  -    <classpathentry kind="var" path="JETTY_DIR/ext/crimson.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-lang-1.0.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/bsf-2.3.0.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/bcel-5.0.jar"/>
  +    <classpathentry exported="true" kind="var" path="JETTY_DIR/lib/javax.servlet.jar"/>
  +    <classpathentry exported="true" kind="var" path="JETTY_DIR/ext/javax.xml.jaxp.jar"/>
  +    <classpathentry exported="true" kind="var" path="JETTY_DIR/ext/crimson.jar"/>
       <classpathentry kind="lib" path="ext-dist/jdom-b8.jar"/>
       <classpathentry kind="lib" path="ext-dist/junit.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-beanutils-1.6.1.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-digester-1.4.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-beanutils-1.6.1.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-digester-1.4.jar"/>
       <classpathentry kind="lib" path="examples/Workbench/lib/jCharts-0.6.0.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-collections-2.1.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/commons-fileupload-1.0-beta-1.jar"/>
  -    <classpathentry kind="lib" path="lib/ext/ognl-2.4.2.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-collections-2.1.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/commons-fileupload-1.0-beta-1.jar"/>
  +    <classpathentry exported="true" kind="lib" path="lib/ext/ognl-2.4.2.jar"/>
       <classpathentry kind="output" path="bin"/>
   </classpath>
  
  
  
  1.2       +2 -2      jakarta-tapestry/junit/mock-scripts/TestCycleActivatePage.xml
  
  Index: TestCycleActivatePage.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/mock-scripts/TestCycleActivatePage.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCycleActivatePage.xml	20 Apr 2003 19:10:04 -0000	1.1
  +++ TestCycleActivatePage.xml	23 Apr 2003 12:29:33 -0000	1.2
  @@ -28,7 +28,7 @@
   		</assert-output>
   		
   		<assert-output name="Message">
  -		A validation cycle during page activation was detected: Five; Six; Five
  +		A validate cycle during page activation was detected: Six; Five; Six.
   		</assert-output>
   	</request>