001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package javax.faces.application;
017:
018: import javax.faces.context.FacesContext;
019: import java.io.IOException;
020:
021: /**
022: * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
023: *
024: * @author Manfred Geiler (latest modification by $Author: mbr $)
025: * @author Stan Silvert
026: * @version $Revision: 512227 $ $Date: 2007-02-27 13:25:16 +0100 (Di, 27 Feb 2007) $
027: */
028: public abstract class StateManager {
029: public static final String STATE_SAVING_METHOD_PARAM_NAME = "javax.faces.STATE_SAVING_METHOD";
030: public static final String STATE_SAVING_METHOD_CLIENT = "client";
031: public static final String STATE_SAVING_METHOD_SERVER = "server";
032: private Boolean _savingStateInClient = null;
033:
034: /**
035: * @deprecated
036: */
037: public StateManager.SerializedView saveSerializedView(
038: javax.faces.context.FacesContext context) {
039: return null;
040: }
041:
042: /**
043: * @since 1.2
044: */
045: public Object saveView(FacesContext context) {
046: StateManager.SerializedView serializedView = saveSerializedView(context);
047: if (serializedView == null)
048: return null;
049:
050: Object[] structureAndState = new Object[2];
051: structureAndState[0] = serializedView.getStructure();
052: structureAndState[1] = serializedView.getState();
053:
054: return structureAndState;
055: }
056:
057: /**
058: * @deprecated
059: */
060: protected Object getTreeStructureToSave(
061: javax.faces.context.FacesContext context) {
062: return null;
063: }
064:
065: /**
066: * @deprecated
067: */
068: protected Object getComponentStateToSave(
069: javax.faces.context.FacesContext context) {
070: return null;
071: }
072:
073: /**
074: * @deprecated
075: */
076: public void writeState(javax.faces.context.FacesContext context,
077: StateManager.SerializedView state)
078: throws java.io.IOException {
079: // default impl does nothing as per JSF 1.2 javadoc
080: }
081:
082: /**
083: * @since 1.2
084: */
085: public void writeState(FacesContext context, Object state)
086: throws IOException {
087: if (!(state instanceof Object[]))
088: return;
089: Object[] structureAndState = (Object[]) state;
090: if (structureAndState.length < 2)
091: return;
092:
093: writeState(context, new StateManager.SerializedView(
094: structureAndState[0], structureAndState[1]));
095: }
096:
097: public abstract javax.faces.component.UIViewRoot restoreView(
098: javax.faces.context.FacesContext context, String viewId,
099: String renderKitId);
100:
101: /**
102: * @deprecated
103: */
104: protected javax.faces.component.UIViewRoot restoreTreeStructure(
105: javax.faces.context.FacesContext context, String viewId,
106: String renderKitId) {
107: return null;
108: }
109:
110: /**
111: * @deprecated
112: */
113: protected void restoreComponentState(
114: javax.faces.context.FacesContext context,
115: javax.faces.component.UIViewRoot viewRoot,
116: String renderKitId) {
117: // default impl does nothing as per JSF 1.2 javadoc
118: }
119:
120: public boolean isSavingStateInClient(
121: javax.faces.context.FacesContext context) {
122: if (context == null)
123: throw new NullPointerException("context");
124: if (_savingStateInClient != null)
125: return _savingStateInClient.booleanValue();
126: String stateSavingMethod = context.getExternalContext()
127: .getInitParameter(STATE_SAVING_METHOD_PARAM_NAME);
128: if (stateSavingMethod == null) {
129: _savingStateInClient = Boolean.FALSE; //Specs 10.1.3: default server saving
130: context
131: .getExternalContext()
132: .log(
133: "No state saving method defined, assuming default server state saving");
134: } else if (stateSavingMethod.equals(STATE_SAVING_METHOD_CLIENT)) {
135: _savingStateInClient = Boolean.TRUE;
136: } else if (stateSavingMethod.equals(STATE_SAVING_METHOD_SERVER)) {
137: _savingStateInClient = Boolean.FALSE;
138: } else {
139: _savingStateInClient = Boolean.FALSE; //Specs 10.1.3: default server saving
140: context
141: .getExternalContext()
142: .log(
143: "Illegal state saving method '"
144: + stateSavingMethod
145: + "', default server state saving will be used");
146: }
147: return _savingStateInClient.booleanValue();
148: }
149:
150: /**
151: * @deprecated
152: */
153: public class SerializedView {
154: private Object _structure;
155: private Object _state;
156:
157: /**
158: * @deprecated
159: */
160: public SerializedView(Object structure, Object state) {
161: _structure = structure;
162: _state = state;
163: }
164:
165: /**
166: * @deprecated
167: */
168: public Object getStructure() {
169: return _structure;
170: }
171:
172: /**
173: * @deprecated
174: */
175: public Object getState() {
176: return _state;
177: }
178: }
179: }
|