Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 113   Methods: 4
NCLOC: 23   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
PageCallback.java - 100% 100% 100%
coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.callback;
 16   
 
 17   
 import org.apache.tapestry.IPage;
 18   
 import org.apache.tapestry.IRequestCycle;
 19   
 
 20   
 /**
 21   
  *  Simple callback for returning to a page.
 22   
  *  <p>
 23   
  *  Example usage of <tt>PageCallback</tt>:
 24   
  *  <p>
 25   
  *  The Home page ensure a user is 
 26   
  *  authenticated in the {@link org.apache.tapestry.IPage#validate(IRequestCycle)} 
 27   
  *  method.  If the user is not authenticated, they are redirected to the Login 
 28   
  *  page, after setting a callback in the Login page.
 29   
  *  <p>
 30   
  *  The Login page <tt>formSubmit()</tt> {@link org.apache.tapestry.IActionListener} 
 31   
  *  authenticates the user and then invokes {@link ICallback#performCallback(IRequestCycle)} 
 32   
  *  to the Home page.
 33   
  *  <pre>
 34   
  *  public class Home extends BasePage {
 35   
  * 
 36   
  *      public void validate(IRequestCycle cycle) {            
 37   
  *          Visit visit = (Visit) getVisit();
 38   
  *      
 39   
  *          if (!visit.isAuthenticated()) {
 40   
  *              Login login = (Login) cycle.getPage("Login");
 41   
  *
 42   
  *              login.setCallback(new PageCallback(this));
 43   
  *              
 44   
  *              throw new PageRedirectException(login);
 45   
  *          }            
 46   
  *      }
 47   
  *  }
 48   
  *
 49   
  *  public Login extends BasePage {
 50   
  * 
 51   
  *      private ICallback _callback;
 52   
  *
 53   
  *      public void setCallback(ICallback _callback) {
 54   
  *          _callback = callback;
 55   
  *      }
 56   
  *
 57   
  *      public void formSubmit(IRequestCycle cycle) {
 58   
  *          // Authentication code
 59   
  *          ..
 60   
  *   
 61   
  *          Visit visit = (Visit) getVisit();
 62   
  *
 63   
  *          visit.setAuthenticated(true);
 64   
  *  
 65   
  *          if (_callback != null) {
 66   
  *              _callback.performCallback(cycle);
 67   
  *          }
 68   
  *      }
 69   
  *  }    
 70   
  *  </pre>
 71   
  *
 72   
  *  @author Howard Lewis Ship
 73   
  *  @since 0.2.9
 74   
  *
 75   
  **/
 76   
 
 77   
 public class PageCallback implements ICallback
 78   
 {
 79   
     /**
 80   
      *  @since 2.0.4
 81   
      * 
 82   
      **/
 83   
 
 84   
     private static final long serialVersionUID = -3286806776105690068L;
 85   
 
 86   
     private String _pageName;
 87   
 
 88  1
     public PageCallback(String pageName)
 89   
     {
 90  1
         _pageName = pageName;
 91   
     }
 92   
 
 93  1
     public PageCallback(IPage page)
 94   
     {
 95  1
         this(page.getPageName());
 96   
     }
 97   
 
 98  1
     public String toString()
 99   
     {
 100  1
         return "PageCallback[" + _pageName + "]";
 101   
     }
 102   
 
 103   
     /**
 104   
      *  Invokes {@link IRequestCycle#activate(String)} to select the previously
 105   
      *  identified page as the response page.
 106   
      *
 107   
      **/
 108   
 
 109  1
     public void performCallback(IRequestCycle cycle)
 110   
     {
 111  1
         cycle.activate(_pageName);
 112   
     }
 113   
 }