Coverage Report - org.seasar.teeda.core.application.TeedaStateManager
 
Classes in this File Line Coverage Branch Coverage Complexity
TeedaStateManager
90%
18/20
50%
2/4
1.4
 
 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;
 17  
 
 18  
 import javax.faces.application.StateManager;
 19  
 import javax.faces.component.UIViewRoot;
 20  
 import javax.faces.context.FacesContext;
 21  
 
 22  
 /**
 23  
  * @author shot
 24  
  */
 25  19
 public abstract class TeedaStateManager extends StateManager {
 26  
 
 27  2
     protected static final String SERIALIZED_VIEW_ATTR = TeedaStateManager.class
 28  
             .getName()
 29  
             + ".SERIALIZED_VIEW";
 30  
 
 31  
     private TreeStructureManager treeStructureManager;
 32  
 
 33  
     public TreeStructureManager getTreeStructureManager() {
 34  9
         return treeStructureManager;
 35  
     }
 36  
 
 37  
     public void setTreeStructureManager(
 38  
             TreeStructureManager treeStructureManager) {
 39  9
         this.treeStructureManager = treeStructureManager;
 40  9
     }
 41  
 
 42  
     public abstract void removeSerializedView(String viewId);
 43  
 
 44  
     public void saveViewToServer(FacesContext context, UIViewRoot viewRoot)
 45  
             throws IllegalStateException {
 46  
 
 47  3
         SerializedView serializedView = createSerializedView(context, viewRoot);
 48  3
         saveSerializedViewToServer(context, viewRoot.getViewId(),
 49  
                 serializedView);
 50  3
     }
 51  
 
 52  
     public Object getComponentStateToSave(FacesContext context,
 53  
             UIViewRoot viewRoot) {
 54  3
         if (viewRoot.isTransient()) {
 55  0
             return null;
 56  
         }
 57  3
         return viewRoot.processSaveState(context);
 58  
     }
 59  
 
 60  
     public Object getTreeStructureToSave(FacesContext context,
 61  
             UIViewRoot viewRoot) {
 62  3
         if (viewRoot.isTransient()) {
 63  0
             return null;
 64  
         }
 65  3
         return getTreeStructureManager().buildTreeStructure(viewRoot);
 66  
     }
 67  
 
 68  
     protected SerializedView createSerializedView(FacesContext context) {
 69  1
         Object struct = getTreeStructureToSave(context);
 70  1
         Object state = getComponentStateToSave(context);
 71  1
         return new SerializedView(struct, state);
 72  
     }
 73  
 
 74  
     protected SerializedView createSerializedView(FacesContext context,
 75  
             UIViewRoot viewRoot) {
 76  3
         Object struct = getTreeStructureToSave(context, viewRoot);
 77  3
         Object state = getComponentStateToSave(context, viewRoot);
 78  3
         return new SerializedView(struct, state);
 79  
     }
 80  
 
 81  
     protected abstract void saveSerializedViewToServer(FacesContext context,
 82  
             String viewId, SerializedView serializedView);
 83  
 
 84  
     public abstract boolean hasSerializedView(FacesContext context,
 85  
             String viewId);
 86  
 }