1 7 8 package java.beans.beancontext; 9 10 import java.beans.PropertyChangeEvent ; 11 import java.beans.PropertyChangeListener ; 12 import java.beans.PropertyChangeSupport ; 13 14 import java.beans.VetoableChangeListener ; 15 import java.beans.VetoableChangeSupport ; 16 17 import java.beans.PropertyVetoException ; 18 19 import java.io.IOException ; 20 import java.io.ObjectInputStream ; 21 import java.io.ObjectOutputStream ; 22 import java.io.Serializable ; 23 24 41 42 public class BeanContextChildSupport implements BeanContextChild , BeanContextServicesListener , Serializable { 43 44 static final long serialVersionUID = 6328947014421475877L; 45 46 50 51 public BeanContextChildSupport() { 52 super(); 53 54 beanContextChildPeer = this; 55 56 pcSupport = new PropertyChangeSupport (beanContextChildPeer); 57 vcSupport = new VetoableChangeSupport (beanContextChildPeer); 58 } 59 60 65 66 public BeanContextChildSupport(BeanContextChild bcc) { 67 super(); 68 69 beanContextChildPeer = (bcc != null) ? bcc : this; 70 71 pcSupport = new PropertyChangeSupport (beanContextChildPeer); 72 vcSupport = new VetoableChangeSupport (beanContextChildPeer); 73 } 74 75 82 public synchronized void setBeanContext(BeanContext bc) throws PropertyVetoException { 83 if (bc == beanContext) return; 84 85 BeanContext oldValue = beanContext; 86 BeanContext newValue = bc; 87 88 if (!rejectedSetBCOnce) { 89 if (rejectedSetBCOnce = !validatePendingSetBeanContext(bc)) { 90 throw new PropertyVetoException ( 91 "setBeanContext() change rejected:", 92 new PropertyChangeEvent (beanContextChildPeer, "beanContext", oldValue, newValue) 93 ); 94 } 95 96 try { 97 fireVetoableChange("beanContext", 98 oldValue, 99 newValue 100 ); 101 } catch (PropertyVetoException pve) { 102 rejectedSetBCOnce = true; 103 104 throw pve; } 106 } 107 108 if (beanContext != null) releaseBeanContextResources(); 109 110 beanContext = newValue; 111 rejectedSetBCOnce = false; 112 113 firePropertyChange("beanContext", 114 oldValue, 115 newValue 116 ); 117 118 if (beanContext != null) initializeBeanContextResources(); 119 } 120 121 127 public synchronized BeanContext getBeanContext() { return beanContext; } 128 129 140 public void addPropertyChangeListener(String name, PropertyChangeListener pcl) { 141 pcSupport.addPropertyChangeListener(name, pcl); 142 } 143 144 157 public void removePropertyChangeListener(String name, PropertyChangeListener pcl) { 158 pcSupport.removePropertyChangeListener(name, pcl); 159 } 160 161 172 public void addVetoableChangeListener(String name, VetoableChangeListener vcl) { 173 vcSupport.addVetoableChangeListener(name, vcl); 174 } 175 176 189 public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) { 190 vcSupport.removeVetoableChangeListener(name, vcl); 191 } 192 193 201 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) { } 202 203 212 public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) { } 213 214 220 public BeanContextChild getBeanContextChildPeer() { return beanContextChildPeer; } 221 222 227 public boolean isDelegated() { return !this.equals(beanContextChildPeer); } 228 229 236 public void firePropertyChange(String name, Object oldValue, Object newValue) { 237 pcSupport.firePropertyChange(name, oldValue, newValue); 238 } 239 240 257 public void fireVetoableChange(String name, Object oldValue, Object newValue) throws PropertyVetoException { 258 vcSupport.fireVetoableChange(name, oldValue, newValue); 259 } 260 261 270 public boolean validatePendingSetBeanContext(BeanContext newValue) { 271 return true; 272 } 273 274 280 281 protected void releaseBeanContextResources() { 282 } 284 285 290 291 protected void initializeBeanContextResources() { 292 } 294 295 298 299 private void writeObject(ObjectOutputStream oos) throws IOException { 300 301 305 306 if (!equals(beanContextChildPeer) && !(beanContextChildPeer instanceof Serializable )) 307 throw new IOException ("BeanContextChildSupport beanContextChildPeer not Serializable"); 308 309 else 310 oos.defaultWriteObject(); 311 312 } 313 314 315 320 321 private void readObject(ObjectInputStream ois) throws IOException , ClassNotFoundException { 322 ois.defaultReadObject(); 323 } 324 325 328 329 333 public BeanContextChild beanContextChildPeer; 334 335 339 protected PropertyChangeSupport pcSupport; 340 341 345 protected VetoableChangeSupport vcSupport; 346 347 protected transient BeanContext beanContext; 348 349 354 protected transient boolean rejectedSetBCOnce; 355 356 } 357 | Popular Tags |