01: // WebOnSwing - Web Application Framework
02: //Copyright (C) 2003 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package net.ar.webonswing.managers.cache;
19:
20: import java.util.*;
21:
22: import net.ar.webonswing.*;
23:
24: /**
25: * Maneja el estado del cache, si existe un Map como estado de "cache" quiere
26: * decir que el componente va a ser cacheado. Y este Map va a contener todas las
27: * diferentes alternativas cacheadas del mismo componente determinadas y
28: * parametrizadas por la clave "aKey" que se le pasa al grabar.
29: *
30: * @author Fernando Damian Petrola
31: */
32: public class ComponentCacheStateContainer {
33: private static final String CACHE_ID = "cache";
34: protected String theCachedComponentName = "";
35:
36: protected Map theCachedState;
37: protected String theCachedWindowName = "";
38:
39: public Object[] getCacheData(String aWindowName,
40: String aComponentName, String aKey) {
41: updateCachedState(aWindowName, aComponentName);
42: return (Object[]) theCachedState.get(aKey);
43: }
44:
45: public boolean isCached(String aWindowName, String aComponentName) {
46: updateCachedState(aWindowName, aComponentName);
47: return theCachedState != null;
48: }
49:
50: public void setCached(String aWindowName, String aComponentName,
51: boolean isCached) {
52: updateCachedState(aWindowName, aComponentName);
53:
54: if (!isCached)
55: theCachedState = null;
56: else if (theCachedState == null)
57: theCachedState = new Hashtable();
58:
59: WosFramework.getInstance().getWindowTreeStateManager()
60: .setComponentState(aWindowName, aComponentName,
61: CACHE_ID, theCachedState);
62: }
63:
64: public void setCacheData(String aWindowName, String aComponentName,
65: String aKey, Object aProps) {
66: updateCachedState(aWindowName, aComponentName);
67: theCachedState.put(aKey, aProps);
68: }
69:
70: protected void updateCachedState(String aWindowName,
71: String aComponentName) {
72: if (!aWindowName.equals(theCachedWindowName)
73: || !aComponentName.equals(theCachedComponentName)) {
74: theCachedState = (Map) WosFramework.getInstance()
75: .getWindowTreeStateManager().getComponentState(
76: aWindowName, aComponentName, CACHE_ID);
77: theCachedWindowName = aWindowName;
78: theCachedComponentName = aComponentName;
79: }
80: }
81: }
|