Coverage Report - org.apache.tapestry5.internal.services.AjaxComponentInstanceEventResultProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
AjaxComponentInstanceEventResultProcessor
100%
16/16
100%
4/4
0
 
 1  
 // Copyright 2007, 2008 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.tapestry5.internal.services;
 16  
 
 17  
 import org.apache.tapestry5.ComponentResources;
 18  
 import org.apache.tapestry5.internal.structure.Page;
 19  
 import org.apache.tapestry5.runtime.Component;
 20  
 import org.apache.tapestry5.runtime.RenderCommand;
 21  
 import org.apache.tapestry5.services.Ajax;
 22  
 import org.apache.tapestry5.services.ComponentEventResultProcessor;
 23  
 
 24  
 import java.io.IOException;
 25  
 
 26  
 /**
 27  
  * Performs a partial page render based on a root component.
 28  
  */
 29  12
 public class AjaxComponentInstanceEventResultProcessor implements ComponentEventResultProcessor<Component>
 30  
 {
 31  
     private final RequestPageCache cache;
 32  
 
 33  
     private final ComponentEventResultProcessor masterProcessor;
 34  
 
 35  
     public AjaxComponentInstanceEventResultProcessor(RequestPageCache cache,
 36  
                                                      @Ajax ComponentEventResultProcessor masterProcessor)
 37  6
     {
 38  6
         this.cache = cache;
 39  6
         this.masterProcessor = masterProcessor;
 40  6
     }
 41  
 
 42  
     public void processResultValue(Component value) throws IOException
 43  
     {
 44  12
         ComponentResources resources = value.getComponentResources();
 45  
 
 46  12
         boolean isPage = value == resources.getPage();
 47  
 
 48  12
         String pageName = resources.getPageName();
 49  
 
 50  12
         if (isPage)
 51  
         {
 52  
             // This will ultimately send a JSON response to redirect to the page
 53  
 
 54  2
             masterProcessor.processResultValue(pageName);
 55  2
             return;
 56  
         }
 57  
 
 58  
         // Otherwise, a component within a page.
 59  
 
 60  10
         Page page = cache.get(pageName);
 61  
 
 62  10
         String nestedId = resources.getNestedId();
 63  
 
 64  10
         RenderCommand command = page.getComponentElementByNestedId(nestedId);
 65  
 
 66  10
         masterProcessor.processResultValue(command);
 67  10
     }
 68  
 }