Coverage Report - org.seasar.teeda.core.config.faces.assembler.impl.DefaultNavigationRuleAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultNavigationRuleAssembler
100%
14/14
100%
6/6
1.667
DefaultNavigationRuleAssembler$NavigationCaseContextWrapper
100%
2/2
N/A
1.667
DefaultNavigationRuleAssembler$NavigationContextWrapper
100%
12/12
100%
4/4
1.667
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.config.faces.assembler.impl;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 
 21  
 import org.seasar.teeda.core.application.navigation.NavigationCaseContext;
 22  
 import org.seasar.teeda.core.application.navigation.NavigationContext;
 23  
 import org.seasar.teeda.core.application.navigation.NavigationResource;
 24  
 import org.seasar.teeda.core.config.faces.assembler.NavigationRuleAssembler;
 25  
 import org.seasar.teeda.core.config.faces.element.NavigationCaseElement;
 26  
 import org.seasar.teeda.core.config.faces.element.NavigationRuleElement;
 27  
 import org.seasar.teeda.core.util.IteratorUtil;
 28  
 
 29  
 /**
 30  
  * @author shot
 31  
  */
 32  
 public class DefaultNavigationRuleAssembler extends NavigationRuleAssembler {
 33  
 
 34  
     public DefaultNavigationRuleAssembler(List navigationRules) {
 35  4
         super(navigationRules);
 36  4
     }
 37  
 
 38  
     protected void setupBeforeAssemble() {
 39  5
         for (Iterator itr = IteratorUtil.getIterator(getNavigationRules()); itr
 40  10
                 .hasNext();) {
 41  5
             NavigationRuleElement rule = (NavigationRuleElement) itr.next();
 42  5
             isAllSuitableJsfElement(rule.getNavigationCaseElements(),
 43  1
                     NavigationCaseElement.class);
 44  
         }
 45  5
     }
 46  
 
 47  
     public void assemble() {
 48  3
         for (Iterator itr = IteratorUtil.getIterator(getNavigationRules()); itr
 49  6
                 .hasNext();) {
 50  3
             NavigationRuleElement rule = (NavigationRuleElement) itr.next();
 51  3
             NavigationContextWrapper wrapper = new NavigationContextWrapper(
 52  
                     rule);
 53  3
             NavigationResource.addNavigationContext(wrapper);
 54  
         }
 55  3
     }
 56  
 
 57  
     public static class NavigationContextWrapper extends NavigationContext {
 58  
 
 59  4
         public NavigationContextWrapper(NavigationRuleElement navigationRule) {
 60  4
             String fromViewId = navigationRule.getFromViewId();
 61  4
             if (fromViewId != null) {
 62  3
                 setFromViewId(fromViewId);
 63  
             }
 64  4
             toNavigationCaseContext(navigationRule);
 65  4
         }
 66  
 
 67  
         private void toNavigationCaseContext(
 68  
                 NavigationRuleElement navigationRule) {
 69  4
             List navigationCases = navigationRule.getNavigationCaseElements();
 70  4
             for (Iterator itr = IteratorUtil.getIterator(navigationCases); itr
 71  8
                     .hasNext();) {
 72  4
                 NavigationCaseElement caseElement = (NavigationCaseElement) itr
 73  
                         .next();
 74  4
                 addNavigationCaseContext(new NavigationCaseContextWrapper(
 75  
                         caseElement));
 76  
             }
 77  4
         }
 78  
 
 79  
     }
 80  
 
 81  
     public static class NavigationCaseContextWrapper extends
 82  
             NavigationCaseContext {
 83  
         public NavigationCaseContextWrapper(NavigationCaseElement element) {
 84  5
             super(element.getFromAction(), element.getFromOutcome(), element
 85  
                     .getToViewId(), element.isRedirect());
 86  5
         }
 87  
     }
 88  
 }