01: // PropertyCache.java
02: // $Id: PropertyCache.java,v 1.2 2000/08/16 21:37:50 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05: package org.w3c.tools.jdbc;
06:
07: import java.util.Hashtable;
08: import java.util.Enumeration;
09: import java.beans.PropertyDescriptor;
10:
11: /**
12: * @version $Revision: 1.2 $
13: * @author Benoît Mahé (bmahe@w3.org)
14: */
15: public class PropertyCache {
16:
17: public static boolean debug = false;
18:
19: /**
20: * The modified properties
21: */
22: protected static Hashtable properties = new Hashtable();
23:
24: protected static String getId(JdbcBeanInterface bean,
25: String property) {
26: StringBuffer buffer = new StringBuffer(String.valueOf(bean
27: .hashCode()));
28: buffer.append(".").append(property);
29: return buffer.toString();
30: }
31:
32: public static void addProperty(JdbcBeanInterface bean,
33: String property, Object value) {
34: String id = getId(bean, property);
35: if (id != null) {
36: if (debug) {
37: System.out.println("add property in cache: " + id
38: + " = " + value);
39: }
40: properties.put(id, value);
41: }
42: }
43:
44: public static Object getProperty(JdbcBeanInterface bean,
45: PropertyDescriptor pd) {
46: String id = getId(bean, pd.getName());
47: if (id != null) {
48: return properties.get(id);
49: }
50: return null;
51: }
52:
53: public static void removeProperties(JdbcBeanInterface bean) {
54: Enumeration keys = properties.keys();
55: StringBuffer buffer = new StringBuffer(String.valueOf(bean
56: .hashCode()));
57: buffer.append(".");
58: String beankey = buffer.toString();
59: while (keys.hasMoreElements()) {
60: String key = (String) keys.nextElement();
61: if (key.startsWith(beankey)) {
62: if (debug) {
63: System.out.println("remove property from cache: "
64: + beankey);
65: }
66: properties.remove(key);
67: }
68: }
69: }
70: }
|