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.persistence;
19:
20: import java.util.*;
21:
22: import net.ar.webonswing.*;
23:
24: public class PersistenceStateManager {
25: private static final String PERSISTENCE_ID = "persistence";
26: public static final int PERSISTED_IN_PAGE = 0;
27: public static final int PERSISTED_IN_SESSION = 1;
28: public static final int PERSISTED_IN_DB = 2;
29:
30: private Vector theLastState;
31: private String theLastComponentName = "";
32: private String theLastWindowName = "";
33:
34: public boolean isComponentPersisted(String aWindowName,
35: String aComponentName) {
36: if (!aWindowName.equals(theLastWindowName)
37: || !aComponentName.equals(theLastComponentName))
38: theLastState = (Vector) WosFramework.getInstance()
39: .getWindowTreeStateManager()
40: .getComponentState(aWindowName, aComponentName,
41: PERSISTENCE_ID);
42:
43: if (theLastState != null)
44: return ((Boolean) theLastState.get(0)).booleanValue();
45:
46: return false;
47: }
48:
49: public int getPersistenceMethod(String aWindowName,
50: String aComponentName) {
51: if (!aWindowName.equals(theLastWindowName)
52: || !aComponentName.equals(theLastComponentName))
53: theLastState = (Vector) WosFramework.getInstance()
54: .getWindowTreeStateManager()
55: .getComponentState(aWindowName, aComponentName,
56: PERSISTENCE_ID);
57:
58: if (theLastState != null)
59: return ((Integer) theLastState.get(1)).intValue();
60:
61: return PERSISTED_IN_PAGE;
62: }
63:
64: public void setComponentPersistenceState(String aWindowName,
65: String aComponentName, boolean isPersisted) {
66: Vector thePersistenceState = getOrCreatePersistenceState(
67: aWindowName, aComponentName);
68: thePersistenceState.set(0, new Boolean(isPersisted));
69: WosFramework.getInstance().getWindowTreeStateManager()
70: .setComponentState(aWindowName, aComponentName,
71: PERSISTENCE_ID, thePersistenceState);
72: }
73:
74: public void setComponentPersistenceMethod(String aWindowName,
75: String aComponentName, int aMethod) {
76: Vector thePersistenceState = getOrCreatePersistenceState(
77: aWindowName, aComponentName);
78: thePersistenceState.set(1, new Integer(aMethod));
79: WosFramework.getInstance().getWindowTreeStateManager()
80: .setComponentState(aWindowName, aComponentName,
81: PERSISTENCE_ID, thePersistenceState);
82: }
83:
84: private Vector getOrCreatePersistenceState(String aWindowName,
85: String aComponentName) {
86: Vector thePersistenceState = (Vector) WosFramework
87: .getInstance().getWindowTreeStateManager()
88: .getComponentState(aWindowName, aComponentName,
89: PERSISTENCE_ID);
90:
91: if (thePersistenceState == null) {
92: thePersistenceState = new Vector();
93: thePersistenceState.add(new Boolean(false));
94: thePersistenceState.add(new Integer(PERSISTED_IN_PAGE));
95: }
96:
97: return thePersistenceState;
98: }
99: }
|