1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
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 | |
} |