1 package de.webman.acl; 2 3 import com.teamkonzept.lib.TKException; 4 import com.teamkonzept.lib.TKVector; 5 import de.webman.acl.db.ObjectDBData; 6 7 15 public abstract class WMObject 16 { 17 18 20 22 25 private boolean attributesModified = false; 26 27 30 private boolean associationsModified = false; 31 32 35 private boolean associationsLoaded = false; 36 37 40 private Integer id = null; 41 42 45 private String string = null; 46 47 50 private TKVector associations = null; 51 52 53 55 60 protected WMObject (ObjectDBData data) 61 { 62 this.id = data.getID(); 63 } 64 65 66 68 75 public final boolean equals (Object object) 76 { 77 if (object == null) 78 { 79 return false; 80 } 81 82 if (object.getClass() != getClass()) 83 { 84 return false; 85 } 86 87 return ((WMObject) object).getID().equals(this.id); 88 } 89 90 95 public final int hashCode () 96 { 97 return this.id.intValue(); 98 } 99 100 105 public final String toString () 106 { 107 if (this.string == null) 108 { 109 this.string = (new StringBuffer (getClass().getName())).append('.') 110 .append(id) 111 .toString(); 112 } 113 114 return this.string; 115 } 116 117 118 120 126 public abstract ObjectFactory getFactory () 127 throws TKException; 128 129 130 132 137 public final Integer getID () 138 { 139 return id; 140 } 141 142 148 public final boolean isModifiedAttributes () 149 { 150 return this.attributesModified; 151 } 152 153 159 public final boolean isModifiedAssociations () 160 { 161 return this.associationsModified; 162 } 163 164 165 167 173 protected final void modifyAttribute (Object pre, Object post) 174 { 175 if (pre != null || post != null) 176 { 177 try 178 { 179 this.attributesModified = this.attributesModified || 180 ! pre.equals(post); 181 } 182 catch (NullPointerException npe) 183 { 184 this.attributesModified = true; 185 } 186 } 187 } 188 189 192 protected final void updatedAttributes () 193 { 194 this.attributesModified = false; 195 } 196 197 198 200 206 protected final TKVector getAssociations () 207 throws TKException 208 { 209 loadAssociations(); 210 211 return this.associations; 212 } 213 214 220 protected final void addAssociation (WMObject object) 221 throws TKException 222 { 223 loadAssociations(); 224 225 if (object != null) 226 { 227 if (this.associations == null) 228 { 229 this.associations = new TKVector(); 230 } 231 232 if (! this.associations.contains(object.getID())) 233 { 234 this.associations.addElement(object.getID()); 235 this.associationsModified = true; 236 } 237 } 238 } 239 240 246 protected final void removeAssociation (WMObject object) 247 throws TKException 248 { 249 loadAssociations(); 250 251 if (object != null && 252 this.associations != null) 253 { 254 this.associationsModified = this.associationsModified || 255 this.associations.removeElement(object.getID()); 256 } 257 } 258 259 264 protected final void removeAssociations () 265 throws TKException 266 { 267 loadAssociations(); 268 269 if (this.associations != null && 270 this.associations.size() > 0) 271 { 272 this.associations.removeAllElements(); 273 this.associationsModified = true; 274 } 275 } 276 277 285 protected final boolean containsAssociation (WMObject object) 286 throws TKException 287 { 288 loadAssociations(); 289 290 if (object != null && 291 this.associations != null) 292 { 293 return this.associations.contains(object.getID()); 294 } 295 296 return false; 297 } 298 299 302 protected final void updatedAssociations () 303 { 304 this.associationsModified = false; 305 } 306 307 312 protected final void loadAssociations () 313 throws TKException 314 { 315 if (! this.associationsLoaded) 316 { 317 this.associations = getFactory().getObjectAssociations(this); 318 this.associationsLoaded = true; 319 } 320 } 321 322 } 323 | Popular Tags |