001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.application;
030:
031: import java.io.*;
032:
033: import javax.faces.component.*;
034: import javax.faces.context.*;
035:
036: public abstract class StateManager {
037: public static final String STATE_SAVING_METHOD_CLIENT = "client";
038: public static final String STATE_SAVING_METHOD_PARAM_NAME = "javax.faces.STATE_SAVING_METHOD";
039: public static final String STATE_SAVING_METHOD_SERVER = "server";
040:
041: @Deprecated
042: public SerializedView saveSerializedView(FacesContext context) {
043: return null;
044: }
045:
046: /**
047: * @Since 1.2
048: */
049: public Object saveView(FacesContext context) {
050: SerializedView view = saveSerializedView(context);
051:
052: if (view == null)
053: return null;
054:
055: return new Object[] { view.getStructure(), view.getState() };
056: }
057:
058: @Deprecated
059: protected Object getTreeStructureToSave(FacesContext context) {
060: return null;
061: }
062:
063: @Deprecated
064: protected Object getComponentStateToSave(FacesContext context) {
065: return null;
066: }
067:
068: /**
069: * @Since 1.2
070: */
071: public void writeState(FacesContext context, Object state)
072: throws IOException {
073: if (state != null
074: && Object[].class.isAssignableFrom(state.getClass())) {
075: Object[] data = (Object[]) state;
076:
077: if (data.length == 2) {
078: SerializedView view = new SerializedView(data[0],
079: data[1]);
080:
081: writeState(context, view);
082: }
083: }
084: }
085:
086: @Deprecated
087: public void writeState(FacesContext context, SerializedView state)
088: throws IOException {
089: }
090:
091: public abstract UIViewRoot restoreView(FacesContext context,
092: String viewId, String renderKitIt);
093:
094: @Deprecated
095: protected UIViewRoot restoreTreeStructure(FacesContext context,
096: String viewId, String renderKitId) {
097: return null;
098: }
099:
100: @Deprecated
101: protected void restoreComponentState(FacesContext context,
102: UIViewRoot viewRoot, String renderKitId) {
103: }
104:
105: public boolean isSavingStateInClient(FacesContext context) {
106: ExternalContext extContext = context.getExternalContext();
107: String value = extContext
108: .getInitParameter(STATE_SAVING_METHOD_PARAM_NAME);
109:
110: return STATE_SAVING_METHOD_CLIENT.equals(value);
111: }
112:
113: @Deprecated
114: public class SerializedView {
115: private Object _state;
116: private Object _structure;
117:
118: public SerializedView(Object structure, Object state) {
119: _structure = structure;
120: _state = state;
121: }
122:
123: public Object getStructure() {
124: return _structure;
125: }
126:
127: public Object getState() {
128: return _state;
129: }
130: }
131: }
|