Coverage Report - org.seasar.teeda.core.application.navigation.NavigationContext
 
Classes in this File Line Coverage Branch Coverage Complexity
NavigationContext
68%
21/31
62%
10/16
1.75
 
 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.application.navigation;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 /**
 23  
  * @author shot
 24  
  */
 25  
 public class NavigationContext {
 26  
 
 27  
     protected static final String WILDCARD = "*";
 28  
 
 29  19
     private String fromViewId_ = WILDCARD;
 30  
 
 31  19
     private boolean isWildCardMatch_ = false;
 32  
 
 33  19
     private List navigationCases_ = new ArrayList();
 34  
 
 35  19
     public NavigationContext() {
 36  19
     }
 37  
 
 38  
     public void setFromViewId(String fromViewId) {
 39  17
         fromViewId_ = fromViewId;
 40  17
     }
 41  
 
 42  
     public void addNavigationCaseContext(
 43  
             NavigationCaseContext navigationCaseContext) {
 44  19
         if (navigationCaseContext != null) {
 45  18
             navigationCases_.add(navigationCaseContext);
 46  
         }
 47  19
         if (fromViewId_ != null) {
 48  19
             isWildCardMatch_ = fromViewId_.endsWith(WILDCARD);
 49  
         }
 50  19
     }
 51  
 
 52  
     public String getFromViewId() {
 53  24
         return fromViewId_;
 54  
     }
 55  
 
 56  
     public List getNavigationCases() {
 57  20
         return navigationCases_;
 58  
     }
 59  
 
 60  
     public NavigationCaseContext getNavigationCase(String fromAction,
 61  
             String outCome) {
 62  15
         for (Iterator itr = getNavigationCases().iterator(); itr.hasNext();) {
 63  15
             NavigationCaseContext caseContext = (NavigationCaseContext) itr
 64  
                     .next();
 65  15
             String from = caseContext.getFromAction();
 66  15
             String out = caseContext.getFromOutcome();
 67  15
             if ((from == null || from.equals(fromAction))
 68  
                     && (out == null || out.equals(outCome))) {
 69  15
                 return caseContext;
 70  
             }
 71  
         }
 72  0
         return null;
 73  
     }
 74  
 
 75  
     public boolean isWildCardMatch() {
 76  20
         return isWildCardMatch_;
 77  
     }
 78  
 
 79  
     public String toString() {
 80  0
         StringBuffer buf = new StringBuffer();
 81  0
         buf.append("navigation-rule = ");
 82  0
         buf.append("[");
 83  0
         buf.append("from-view-id = \"" + fromViewId_ + "\"");
 84  0
         buf.append(" ");
 85  0
         for (Iterator itr = navigationCases_.iterator(); itr.hasNext();) {
 86  0
             buf.append(itr.next());
 87  
         }
 88  0
         buf.append("]");
 89  0
         return buf.toString();
 90  
     }
 91  
 }