KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > faces > application > StateManager


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package javax.faces.application;
17
18 import java.io.Serializable JavaDoc;
19
20
21 /**
22  * @author Manfred Geiler (latest modification by $Author: matzew $)
23  * @version $Revision: 1.7 $ $Date: 2005/01/18 07:03:16 $
24  */

25 public abstract class StateManager
26 {
27     public static final String JavaDoc STATE_SAVING_METHOD_PARAM_NAME = "javax.faces.STATE_SAVING_METHOD";
28     public static final String JavaDoc STATE_SAVING_METHOD_CLIENT = "client";
29     public static final String JavaDoc STATE_SAVING_METHOD_SERVER = "server";
30     private Boolean JavaDoc _savingStateInClient = null;
31
32     public abstract StateManager.SerializedView saveSerializedView(javax.faces.context.FacesContext context);
33
34     protected abstract Object JavaDoc getTreeStructureToSave(javax.faces.context.FacesContext context);
35
36     protected abstract Object JavaDoc getComponentStateToSave(javax.faces.context.FacesContext context);
37
38     public abstract void writeState(javax.faces.context.FacesContext context,
39                                     StateManager.SerializedView state)
40             throws java.io.IOException JavaDoc;
41
42     public abstract javax.faces.component.UIViewRoot restoreView(javax.faces.context.FacesContext context,
43                                                                  String JavaDoc viewId,
44                                                                  String JavaDoc renderKitId);
45
46     protected abstract javax.faces.component.UIViewRoot restoreTreeStructure(javax.faces.context.FacesContext context,
47                                                                              String JavaDoc viewId,
48                                                                              String JavaDoc renderKitId);
49
50     protected abstract void restoreComponentState(javax.faces.context.FacesContext context,
51                                                   javax.faces.component.UIViewRoot viewRoot,
52                                                   String JavaDoc renderKitId);
53
54     public boolean isSavingStateInClient(javax.faces.context.FacesContext context)
55     {
56         if (_savingStateInClient != null) return _savingStateInClient.booleanValue();
57         String JavaDoc stateSavingMethod = context.getExternalContext().getInitParameter(STATE_SAVING_METHOD_PARAM_NAME);
58         if (stateSavingMethod == null)
59         {
60             _savingStateInClient = Boolean.FALSE; //Specs 10.1.3: default server saving
61
context.getExternalContext().log("No state saving method defined, assuming default server state saving");
62         }
63         else if (stateSavingMethod.equals(STATE_SAVING_METHOD_CLIENT))
64         {
65             _savingStateInClient = Boolean.TRUE;
66         }
67         else if (stateSavingMethod.equals(STATE_SAVING_METHOD_SERVER))
68         {
69             _savingStateInClient = Boolean.FALSE;
70         }
71         else
72         {
73             _savingStateInClient = Boolean.FALSE; //Specs 10.1.3: default server saving
74
context.getExternalContext().log("Illegal state saving method '" + stateSavingMethod + "', default server state saving will be used");
75         }
76         return _savingStateInClient.booleanValue();
77     }
78
79
80     public class SerializedView
81     {
82         private Object JavaDoc _structure;
83         private Object JavaDoc _state;
84
85         public SerializedView(Object JavaDoc structure, Object JavaDoc state)
86         {
87             _structure = structure;
88             _state = state;
89         }
90
91         public Object JavaDoc getStructure()
92         {
93             return _structure;
94         }
95
96         public Object JavaDoc getState()
97         {
98             return _state;
99         }
100     }
101 }
102
Popular Tags