1 23 24 29 30 package com.sun.jdo.api.persistence.model.jdo.impl; 31 32 import java.beans.PropertyVetoException ; 33 34 import com.sun.jdo.api.persistence.model.jdo.*; 35 import com.sun.jdo.api.persistence.model.ModelException; 36 import com.sun.jdo.api.persistence.model.ModelVetoException; 37 import com.sun.jdo.spi.persistence.utility.JavaTypeHelper; 38 39 44 public class PersistenceClassElementImpl extends PersistenceElementImpl 45 implements PersistenceClassElement.Impl 46 { 47 48 private boolean _isModified; 49 50 51 private int _objectIdentityType; 52 53 54 private String _keyClass; 55 56 57 private PersistenceElementCollection _fields; 58 59 60 private PersistenceElementCollection _groups; 61 62 65 public PersistenceClassElementImpl () 66 { 67 this(null); 68 } 69 70 73 public PersistenceClassElementImpl (String name) 74 { 75 super(name); 76 77 if (name != null) 78 _keyClass = name + ".Oid"; 80 _objectIdentityType = PersistenceClassElement.APPLICATION_IDENTITY; 81 _fields = new PersistenceElementCollection(this, PROP_FIELDS, 82 new PersistenceFieldElement[0]); 83 _groups = new PersistenceElementCollection(this, PROP_GROUPS, 84 new ConcurrencyGroupElement[0]); 85 } 86 87 94 protected final void firePropertyChange (String name, Object o, Object n) 95 { 96 boolean noChange = ((o != null) && (n != null) && o.equals(n)); 100 101 super.firePropertyChange(name, o, n); 102 103 if (!(PROP_MODIFIED.equals(name)) && !noChange) 104 setModified(true); 105 } 106 107 115 protected final void fireVetoableChange (String name, Object o, Object n) 116 throws PropertyVetoException 117 { 118 boolean noChange = ((o != null) && (n != null) && o.equals(n)); 122 123 super.fireVetoableChange(name, o, n); 124 125 if (!(PROP_MODIFIED.equals(name)) && !noChange) 126 fireVetoableChange(PROP_MODIFIED, Boolean.FALSE, Boolean.TRUE); 127 } 128 129 133 public boolean isModified () { return _isModified; } 134 135 141 public void setModified (boolean flag) 142 { 143 boolean oldFlag = isModified(); 144 145 if (flag != oldFlag) 146 { 147 _isModified = flag; 148 firePropertyChange(PROP_MODIFIED, JavaTypeHelper.valueOf(oldFlag), 149 JavaTypeHelper.valueOf(flag)); 150 } 151 } 152 153 160 public int getObjectIdentityType () 161 { 162 return _objectIdentityType; 163 } 164 165 172 public void setObjectIdentityType (int type) throws ModelException 173 { 174 Integer old = new Integer (getObjectIdentityType()); 175 Integer newType = new Integer (type); 176 177 try 178 { 179 fireVetoableChange(PROP_IDENTITY, old, newType); 180 _objectIdentityType = type; 181 firePropertyChange(PROP_IDENTITY, old, newType); 182 } 183 catch (PropertyVetoException e) 184 { 185 throw new ModelVetoException(e); 186 } 187 } 188 189 190 199 public String getKeyClass () 200 { 201 return ((PersistenceClassElement.APPLICATION_IDENTITY == 202 getObjectIdentityType()) ? _keyClass : null); 203 } 204 205 213 public void setKeyClass (String name) throws ModelException 214 { 215 String old = getKeyClass(); 216 217 try 218 { 219 fireVetoableChange(PROP_KEY_CLASS, old, name); 220 _keyClass = name; 221 firePropertyChange(PROP_KEY_CLASS, old, name); 222 } 223 catch (PropertyVetoException e) 224 { 225 throw new ModelVetoException(e); 226 } 227 } 228 229 231 236 public void changeFields (PersistenceFieldElement[] fields, int action) 237 throws ModelException 238 { 239 _fields.changeElements(fields, action); 240 } 241 242 245 public PersistenceFieldElement[] getFields () 246 { 247 return (PersistenceFieldElement[])_fields.getElements(); 248 } 249 250 254 public PersistenceFieldElement getField (String name) 255 { 256 return (PersistenceFieldElement)_fields.getElement(name); 257 } 258 259 261 266 public void changeConcurrencyGroups (ConcurrencyGroupElement[] groups, 267 int action) throws ModelException 268 { 269 _groups.changeElements(groups, action); 270 } 271 272 275 public ConcurrencyGroupElement[] getConcurrencyGroups () 276 { 277 return (ConcurrencyGroupElement[])_groups.getElements(); 278 } 279 280 284 public ConcurrencyGroupElement getConcurrencyGroup (String name) 285 { 286 return (ConcurrencyGroupElement)_groups.getElement(name); 287 } 288 289 291 295 public PersistenceElementCollection getFieldCollection () 296 { 297 return _fields; 298 } 299 300 305 public void setFieldCollection (PersistenceElementCollection collection) 306 { 307 _fields = collection; 308 } 309 310 315 public PersistenceElementCollection getGroupCollection () 316 { 317 return _groups; 318 } 319 320 325 public void setGroupCollection (PersistenceElementCollection collection) 326 { 327 _groups = collection; 328 } 329 } 330 | Popular Tags |