1 23 24 29 30 package com.sun.jdo.api.persistence.model.jdo.impl; 31 32 import java.beans.*; 33 34 import com.sun.jdo.api.persistence.model.ModelException; 35 import com.sun.jdo.api.persistence.model.ModelVetoException; 36 import com.sun.jdo.api.persistence.model.jdo.PersistenceElement; 37 import com.sun.jdo.api.persistence.model.jdo.PersistenceElementProperties; 38 39 42 43 48 public abstract class PersistenceElementImpl extends Object 49 implements PersistenceElement.Impl, PersistenceElementProperties 50 { 51 52 PersistenceElement _element; 53 54 55 private PropertyChangeSupport _support; 56 57 58 private transient VetoableChangeSupport _vetoableSupport; 59 60 61 private String _name; 62 63 66 public PersistenceElementImpl () 67 { 68 this(null); 69 } 70 71 74 public PersistenceElementImpl (String name) 75 { 76 super(); 77 _name = name; 78 } 79 80 87 public void attachToElement (PersistenceElement element) 88 { 89 _element = element; 90 } 91 92 97 protected void firePropertyChange (String name, Object o, Object n) 98 { 99 if (_support != null) 100 _support.firePropertyChange(name, o, n); 101 } 102 103 106 public synchronized void addPropertyChangeListener 107 (PropertyChangeListener l) 108 { 109 if (_support == null) 110 { 111 synchronized(this) 112 { 113 if (_support == null) 115 _support = new PropertyChangeSupport(_element); 116 } 117 } 118 119 _support.addPropertyChangeListener(l); 120 } 121 122 125 public synchronized void removePropertyChangeListener ( 126 PropertyChangeListener l) 127 { 128 if (_support != null) 129 _support.removePropertyChangeListener(l); 130 } 131 132 138 protected void fireVetoableChange (String name, Object o, Object n) 139 throws PropertyVetoException 140 { 141 if (_vetoableSupport != null) 142 _vetoableSupport.fireVetoableChange(name, o, n); 143 } 144 145 148 public synchronized void addVetoableChangeListener 149 (VetoableChangeListener l) 150 { 151 if (_vetoableSupport == null) 152 _vetoableSupport = new VetoableChangeSupport(_element); 153 154 _vetoableSupport.addVetoableChangeListener(l); 155 } 156 157 160 public synchronized void removeVetoableChangeListener ( 161 VetoableChangeListener l) 162 { 163 if (_vetoableSupport != null) 164 _vetoableSupport.removeVetoableChangeListener(l); 165 } 166 167 170 public String getName () { return _name; } 171 172 176 public void setName (String name) throws ModelException 177 { 178 String old = getName(); 179 180 try 181 { 182 fireVetoableChange(PROP_NAME, old, name); 183 _name = name; 184 firePropertyChange(PROP_NAME, old, name); 185 } 186 catch (PropertyVetoException e) 187 { 188 throw new ModelVetoException(e); 189 } 190 } 191 } 192 | Popular Tags |