01: /*
02: * Created on Jun 5, 2003
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.xdev.base.core;
08:
09: /**
10: * @author AYegorov
11: *
12: * To change the template for this generated type comment go to
13: * Window>Preferences>Java>Code Generation>Code and Comments
14: */
15:
16: import org.xdev.base.core.*;
17: import org.xdev.base.core.object.*;
18: import org.xdev.base.log.LoggerWriter;
19: import org.xdev.base.xssl.XSSLAction;
20: import org.xdev.base.xssl.XSSLComponent;
21:
22: import java.util.*;
23: import org.apache.log4j.Level;
24:
25: public abstract class AbstractPersistance extends Configuration {
26: protected XSSLAction template = null;
27:
28: protected boolean overwrite = true;
29:
30: protected List constants = new ArrayList();
31:
32: public AbstractPersistance(String id, HashMap properties) {
33: super (id, properties);
34: }
35:
36: public void storeObject(String id, Object obj) {
37:
38: boolean found = this .exists(id);
39:
40: this .logDebug("Variable " + id + " is already declared: "
41: + found);
42:
43: this .logDebug("Variable overwrite is active: "
44: + this .doOverwrite());
45:
46: this .logDebug("Variable " + id + " will be overwritten: "
47: + (found && this .doOverwrite()));
48:
49: if (!this .constants.contains(id)
50: && (found && this .doOverwrite()) || !found) {
51:
52: try {
53:
54: this .store(id, obj);
55:
56: this .logDebug("Variable " + id
57: + " has been assigned value " + obj);
58:
59: } catch (Exception ex) {
60: this .logError(ex);
61: }
62: }
63: }
64:
65: public void addConstant(String id) {
66:
67: synchronized (this .constants) {
68:
69: this .constants.add(id);
70: }
71: }
72:
73: public boolean isConstant(String id) {
74: return this .constants.contains(id);
75: }
76:
77: protected abstract void store(String id, Object obj)
78: throws Exception;
79:
80: public abstract boolean exists(String id);
81:
82: public abstract Object get(String id);
83:
84: public abstract Object remove(String id);
85:
86: public void setOverwrite(boolean flag) {
87: this .overwrite = flag;
88: }
89:
90: public boolean doOverwrite() {
91: return this.overwrite;
92: }
93: }
|