Coverage Report - javax.faces.internal.ComponentStates
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentStates
68%
32/47
75%
12/16
2.333
 
 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 javax.faces.internal;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Iterator;
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.faces.component.EditableValueHolder;
 23  
 import javax.faces.component.UIComponent;
 24  
 import javax.faces.context.FacesContext;
 25  
 
 26  
 /**
 27  
  * @author manhole
 28  
  *
 29  
  * This class might be changed without notice. Please do not use it
 30  
  * excluding the JSF specification part.
 31  
  */
 32  
 public class ComponentStates {
 33  
 
 34  
     public static final int DEFAULT_INITIAL_CAPACITY = 1024;
 35  
 
 36  
     private Map savedStates;
 37  
 
 38  
     public ComponentStates() {
 39  420
         this(DEFAULT_INITIAL_CAPACITY);
 40  420
     }
 41  
 
 42  420
     public ComponentStates(int initialCapacity) {
 43  420
         this.savedStates = new HashMap(initialCapacity);
 44  420
     }
 45  
 
 46  
     public void restoreDescendantState(FacesContext context,
 47  
             UIComponent component) {
 48  344
         for (final Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
 49  213
             final UIComponent child = (UIComponent) it.next();
 50  213
             NamingContainerUtil.refreshClientId(child);
 51  213
             if (child instanceof ComponentStatesHolder) {
 52  0
                 final ComponentStatesHolder holder = (ComponentStatesHolder) child;
 53  0
                 final String clientId = child.getClientId(context);
 54  0
                 SavedState state = (SavedState) savedStates.get(clientId);
 55  0
                 if (state == null) {
 56  0
                     state = new SavedState();
 57  0
                     savedStates.put(clientId, state);
 58  
                 }
 59  0
                 state.restore(holder);
 60  0
                 continue;
 61  
             }
 62  213
             if (child instanceof EditableValueHolder) {
 63  21
                 final EditableValueHolder holder = (EditableValueHolder) child;
 64  21
                 final String clientId = child.getClientId(context);
 65  21
                 SavedState state = (SavedState) savedStates.get(clientId);
 66  21
                 if (state == null) {
 67  12
                     state = new SavedState();
 68  12
                     savedStates.put(clientId, state);
 69  
                 }
 70  21
                 state.restore(holder);
 71  
             }
 72  213
             restoreDescendantState(context, child);
 73  
         }
 74  344
     }
 75  
 
 76  
     public void saveDescendantComponentStates(FacesContext context,
 77  
             UIComponent component) {
 78  344
         for (final Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
 79  213
             final UIComponent child = (UIComponent) it.next();
 80  213
             if (child instanceof ComponentStatesHolder) {
 81  0
                 final ComponentStatesHolder holder = (ComponentStatesHolder) child;
 82  0
                 final SavedState state = new SavedState();
 83  0
                 final String clientId = child.getClientId(context);
 84  0
                 state.save(holder);
 85  0
                 savedStates.put(clientId, state);
 86  0
                 continue;
 87  
             }
 88  213
             if (child instanceof EditableValueHolder) {
 89  21
                 final EditableValueHolder holder = (EditableValueHolder) child;
 90  21
                 final SavedState state = new SavedState();
 91  21
                 final String clientId = child.getClientId(context);
 92  21
                 state.save(holder);
 93  21
                 savedStates.put(clientId, state);
 94  
             }
 95  213
             saveDescendantComponentStates(context, child);
 96  
         }
 97  344
     }
 98  
 
 99  
     public Map getSavedStates() {
 100  0
         return savedStates;
 101  
     }
 102  
 
 103  
     public void clear() {
 104  5
         savedStates.clear();
 105  5
     }
 106  
 
 107  
 }