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

1.1       bmahe       1: // PropertyCache.java
1.3     ! ylafon      2: // $Id: PropertyCache.java,v 1.2 2000/08/16 21:37:50 ylafon 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.3     ! ylafon     12:  * @author Beno�t Mah� (bmahe@w3.org)
        !            13:  * @version $Revision: 1.2 $
1.1       bmahe      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) {
1.3     ! ylafon     25:         StringBuilder buffer;
        !            26:         buffer = new StringBuilder();
        !            27:         buffer.append(String.valueOf(bean.hashCode()));
        !            28:         buffer.append('.').append(property);
        !            29:         return buffer.toString();
1.1       bmahe      30:     }
                     31: 
1.3     ! ylafon     32:     public static void addProperty(JdbcBeanInterface bean,
        !            33:                                    String property,
        !            34:                                    Object value) {
        !            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:         }
1.1       bmahe      42:     }
                     43: 
                     44:     public static Object getProperty(JdbcBeanInterface bean,
1.3     ! ylafon     45:                                      PropertyDescriptor pd) {
        !            46:         String id = getId(bean, pd.getName());
        !            47:         if (id != null) {
        !            48:             return properties.get(id);
        !            49:         }
        !            50:         return null;
1.1       bmahe      51:     }
                     52: 
                     53:     public static void removeProperties(JdbcBeanInterface bean) {
1.3     ! ylafon     54:         Enumeration keys = properties.keys();
        !            55:         StringBuilder buffer = new StringBuilder();
        !            56:         buffer.append(String.valueOf(bean.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: " + beankey);
        !            64:                 }
        !            65:                 properties.remove(key);
        !            66:             }
        !            67:         }
1.1       bmahe      68:     }
                     69: }

Webmaster