Annotation of java/classes/org/w3c/tools/jdbc/PropertyCache.java, revision 1.2

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

Webmaster