1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.application;
20
21 import javax.faces.context.FacesContext;
22
23 /**
24 * This class provides and interface to separate the state caching operations (saving/restoring)
25 * from the renderkit specific stuff that HtmlResponseStateManager should do.
26 *
27 * @author Leonardo Uribe
28 *
29 */
30 public abstract class StateCache<K, V>
31 {
32
33 /**
34 * Put the state on the cache, to can be restored later.
35 *
36 * @param facesContext
37 * @param serializedView
38 */
39 public abstract K saveSerializedView(FacesContext facesContext, V serializedView);
40
41 /**
42 * Get the state from the cache is server side state saving is used,
43 * or decode it from the passed viewState param if client side is used.
44 *
45 * @param facesContext
46 * @param viewId The viewId of the view to be restored
47 * @param viewState A token usually retrieved from a call to ResponseStateManager.getState that will be
48 * used to identify or restore the state.
49 * @return
50 */
51 public abstract V restoreSerializedView(FacesContext facesContext, String viewId, K viewState);
52
53 /**
54 * Calculate the token to be used if server side state saving, or encode the view and return the
55 * viewState that can be used by the underlying ResponseStateManager to write the state.
56 *
57 * @param facesContext
58 * @param state The state that will be used to derive the token returned.
59 * @return A token (usually encoded on javax.faces.ViewState input hidden field) that will be passed to
60 * ResponseStateManager.writeState or ResponseStateManager.getViewState to be
61 * output to the client.
62 */
63 public abstract K encodeSerializedState(FacesContext facesContext, Object serializedView);
64
65 /**
66 * Indicates if the call to ResponseStateManager.writeState should be done after the view is fully rendered.
67 * Usually this is required for client side state saving, but it is not for server side state saving, because
68 * ResponseStateManager.writeState could render a just a marker and then StateManager.saveState could be called,
69 * preventing use an additional buffer.
70 *
71 * @param facesContext
72 * @return
73 */
74 public abstract boolean isWriteStateAfterRenderViewRequired(FacesContext facesContext);
75 }