home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / PropertyHookupManager.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.6 KB  |  53 lines

  1. package sun.beanbox;
  2.  
  3. /**
  4.  * This class manages hookups between properties, so that a
  5.  * bound property change on object X turns into a property
  6.  * set on a related property on object Y.
  7.  * <P>
  8.  * We do this by associating a PropertyHookup adaptor with each
  9.  * source object that we are interested in.  As part of the adaptor
  10.  * we keep track of which target setter methods to call when a given
  11.  * property changes.
  12.  */
  13.  
  14. import java.lang.reflect.*;
  15. import java.beans.*;
  16. import java.io.*;
  17. import java.util.Hashtable;
  18. import java.util.Vector;
  19. import sunw.beanbox.PropertyHookup;
  20.  
  21. class PropertyHookupManager {
  22.  
  23.     /**
  24.      * Create a property hookup, so that a change to the named bound
  25.      * property on the source object turns into a call on the "setter"
  26.      * method of the given target object.
  27.      */
  28.  
  29.     public synchronized static void attach(Wrapper sourceWrapper,
  30.             String propertyName, Method getter,
  31.             Wrapper targetWrapper, Method setter) {
  32.  
  33.     Object source = sourceWrapper.getBean();
  34.     Object targetObject = targetWrapper.getBean();
  35.  
  36.     PropertyHookup hook = (PropertyHookup) instances.get(source);
  37.     if (hook == null) {
  38.         // This is the first property hookup on this source object.
  39.         // Push a PropertyHookup adaptor onto the source.
  40.         hook = new PropertyHookup(source);
  41.         instances.put(source, hook);
  42.         // Register our listener object with the source Wrapper.
  43.         sourceWrapper.addEventTarget("propertyChange", null, hook);
  44.     }
  45.  
  46.     hook.attach(source, propertyName, getter, targetObject, setter);
  47.     }
  48.  
  49.     // This table maps from event sources to PropertyHookup objects.
  50.     private static Hashtable instances = new Hashtable();
  51.  
  52. }
  53.