1 30 31 34 package com.nightlabs.config; 35 36 import java.util.ArrayList ; 37 import java.util.Collection ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 import java.util.ListIterator ; 41 42 import org.apache.log4j.Logger; 43 44 import com.nightlabs.util.RWLockable; 45 46 60 public class CfModList extends ArrayList implements RWLockable 61 { 62 public static final Logger LOGGER = Logger.getLogger(CfModList.class); 63 64 protected ConfigModule ownerCfMod = null; 65 66 public CfModList() { } 67 68 public CfModList(int initialCapacity) 69 { 70 super(initialCapacity); 71 } 72 73 public CfModList(Collection c) 74 { 75 super(c); 76 } 77 78 public CfModList(ConfigModule ownerCfMod) 79 { 80 this.ownerCfMod = ownerCfMod; 81 } 82 83 86 public ConfigModule getOwnerCfMod() 87 { 88 return ownerCfMod; 89 } 90 93 public void setOwnerCfMod(ConfigModule ownerCfMod) 94 { 95 this.ownerCfMod = ownerCfMod; 96 } 97 98 protected void setChanged() 99 { 100 if (ownerCfMod == null) { 101 LOGGER.warn("Owner ConfigModule is null! Cannot notify change!"); 102 return; 103 } 104 ownerCfMod.setChanged(); 105 } 106 107 public void acquireReadLock() 108 { 109 if (ownerCfMod == null) { 110 LOGGER.warn("Owner ConfigModule is null! Cannot lock! Operation is not thread-safe!!!"); 111 return; 112 } 113 ownerCfMod.acquireReadLock(); 114 } 115 116 public void acquireWriteLock() 117 { 118 if (ownerCfMod == null) { 119 LOGGER.warn("Owner ConfigModule is null! Cannot lock! Operation is not thread-safe!!!"); 120 return; 121 } 122 ownerCfMod.acquireReadLock(); 123 } 124 125 public void releaseLock() 126 { 127 if (ownerCfMod == null) { 128 LOGGER.warn("Owner ConfigModule is null! Cannot lock! Operation is not thread-safe!!!"); 129 return; 130 } 131 ownerCfMod.releaseLock(); 132 } 133 134 137 public void add(int index, Object element) 138 { 139 acquireWriteLock(); 140 try { 141 super.add(index, element); 142 setChanged(); 143 } finally { 144 releaseLock(); 145 } 146 } 147 150 public boolean add(Object o) 151 { 152 acquireWriteLock(); 153 try { 154 boolean res = super.add(o); 155 setChanged(); 156 return res; 157 } finally { 158 releaseLock(); 159 } 160 } 161 164 public boolean addAll(Collection c) 165 { 166 acquireWriteLock(); 167 try { 168 boolean res = super.addAll(c); 169 setChanged(); 170 return res; 171 } finally { 172 releaseLock(); 173 } 174 } 175 178 public boolean addAll(int index, Collection c) 179 { 180 acquireWriteLock(); 181 try { 182 boolean res = super.addAll(index, c); 183 setChanged(); 184 return res; 185 } finally { 186 releaseLock(); 187 } 188 } 189 192 public void clear() 193 { 194 acquireWriteLock(); 195 try { 196 super.clear(); 197 setChanged(); 198 } finally { 199 releaseLock(); 200 } 201 } 202 205 public Object remove(int index) 206 { 207 acquireWriteLock(); 208 try { 209 Object res = super.remove(index); 210 setChanged(); 211 return res; 212 } finally { 213 releaseLock(); 214 } 215 } 216 219 protected void removeRange(int fromIndex, int toIndex) 220 { 221 acquireWriteLock(); 222 try { 223 super.removeRange(fromIndex, toIndex); 224 setChanged(); 225 } finally { 226 releaseLock(); 227 } 228 } 229 232 public Object set(int index, Object element) 233 { 234 acquireWriteLock(); 235 try { 236 Object res = super.set(index, element); 237 setChanged(); 238 return res; 239 } finally { 240 releaseLock(); 241 } 242 } 243 246 public void trimToSize() 247 { 248 acquireWriteLock(); 249 try { 250 super.trimToSize(); 251 setChanged(); 252 } finally { 253 releaseLock(); 254 } 255 } 256 259 public boolean remove(Object o) 260 { 261 acquireWriteLock(); 262 try { 263 boolean res = super.remove(o); 264 setChanged(); 265 return res; 266 } finally { 267 releaseLock(); 268 } 269 } 270 273 public boolean removeAll(Collection c) 274 { 275 acquireWriteLock(); 276 try { 277 boolean res = super.removeAll(c); 278 setChanged(); 279 return res; 280 } finally { 281 releaseLock(); 282 } 283 } 284 287 public boolean retainAll(Collection c) 288 { 289 acquireWriteLock(); 290 try { 291 boolean res = super.retainAll(c); 292 setChanged(); 293 return res; 294 } finally { 295 releaseLock(); 296 } 297 } 298 299 300 303 public Object clone() 304 { 305 acquireReadLock(); 306 try { 307 return super.clone(); 308 } finally { 309 releaseLock(); 310 } 311 } 312 315 public boolean contains(Object elem) 316 { 317 acquireReadLock(); 318 try { 319 return super.contains(elem); 320 } finally { 321 releaseLock(); 322 } 323 } 324 327 public void ensureCapacity(int minCapacity) 328 { 329 acquireReadLock(); 330 try { 331 super.ensureCapacity(minCapacity); 332 } finally { 333 releaseLock(); 334 } 335 } 336 339 public Object get(int index) 340 { 341 acquireReadLock(); 342 try { 343 return super.get(index); 344 } finally { 345 releaseLock(); 346 } 347 } 348 351 public int indexOf(Object elem) 352 { 353 acquireReadLock(); 354 try { 355 return super.indexOf(elem); 356 } finally { 357 releaseLock(); 358 } 359 } 360 363 public boolean isEmpty() 364 { 365 acquireReadLock(); 366 try { 367 return super.isEmpty(); 368 } finally { 369 releaseLock(); 370 } 371 } 372 375 public int lastIndexOf(Object elem) 376 { 377 acquireReadLock(); 378 try { 379 return super.lastIndexOf(elem); 380 } finally { 381 releaseLock(); 382 } 383 } 384 387 public int size() 388 { 389 acquireReadLock(); 390 try { 391 return super.size(); 392 } finally { 393 releaseLock(); 394 } 395 } 396 399 public Object [] toArray() 400 { 401 acquireReadLock(); 402 try { 403 return super.toArray(); 404 } finally { 405 releaseLock(); 406 } 407 } 408 411 public Object [] toArray(Object [] a) 412 { 413 acquireReadLock(); 414 try { 415 return super.toArray(a); 416 } finally { 417 releaseLock(); 418 } 419 } 420 423 public boolean equals(Object o) 424 { 425 acquireReadLock(); 426 try { 427 return super.equals(o); 428 } finally { 429 releaseLock(); 430 } 431 } 432 435 public int hashCode() 436 { 437 acquireReadLock(); 438 try { 439 return super.hashCode(); 440 } finally { 441 releaseLock(); 442 } 443 } 444 451 public Iterator iterator() 452 { 453 return super.iterator(); 454 } 455 463 public ListIterator listIterator() 464 { 465 return super.listIterator(); 466 } 467 474 public ListIterator listIterator(int index) 475 { 476 return super.listIterator(index); 477 } 478 481 public List subList(int fromIndex, int toIndex) 482 { 483 acquireReadLock(); 484 try { 485 return super.subList(fromIndex, toIndex); 486 } finally { 487 releaseLock(); 488 } 489 } 490 493 public boolean containsAll(Collection c) 494 { 495 acquireReadLock(); 496 try { 497 return super.containsAll(c); 498 } finally { 499 releaseLock(); 500 } 501 } 502 505 public String toString() 506 { 507 acquireReadLock(); 508 try { 509 return super.toString(); 510 } finally { 511 releaseLock(); 512 } 513 } 514 } 515 | Popular Tags |