1 16 package org.apache.axis.utils ; 17 18 import java.util.Hashtable ; 19 import java.util.Vector ; 20 import java.util.Set ; 21 import java.util.HashSet ; 22 23 35 public class LockableHashtable extends Hashtable { 36 37 44 Vector lockedEntries; 45 46 47 private Hashtable parent = null; 48 49 public LockableHashtable() { 50 super(); 51 } 52 53 public LockableHashtable(int p1, float p2) { 54 super(p1, p2); 55 } 56 57 public LockableHashtable(java.util.Map p1) { 58 super(p1); 59 } 60 61 public LockableHashtable(int p1) { 62 super(p1); 63 } 64 65 68 public synchronized void setParent(Hashtable parent) 69 { 70 this.parent = parent; 71 } 72 73 76 public synchronized Hashtable getParent() { 77 return parent; 78 } 79 80 83 public Set getAllKeys() { 84 HashSet set = new HashSet (); 85 set.addAll(super.keySet()); 86 Hashtable p = parent; 87 while (p != null) { 88 set.addAll(p.keySet()); 89 if (p instanceof LockableHashtable) { 90 p = ((LockableHashtable) p).getParent(); 91 } else { 92 p = null; 93 } 94 } 95 return set; 96 } 97 98 102 public synchronized Object get(Object key) { 103 Object ret = super.get(key); 104 if ((ret == null) && (parent != null)) { 105 ret = parent.get(key); 106 } 107 return ret; 108 } 109 113 public synchronized Object put(Object p1, Object p2, boolean locked) { 114 if (lockedEntries != null && 115 this.containsKey(p1) && 116 lockedEntries.contains(p1)) { 117 return null; 118 } 119 if (locked) { 120 if (lockedEntries == null) { 121 lockedEntries = new Vector (); 122 } 123 lockedEntries.add(p1); 124 } 125 return super.put(p1, p2); 126 } 127 128 131 public synchronized Object put(Object p1, Object p2) { 132 return put(p1, p2, false); 133 } 134 135 138 public synchronized Object remove(Object p1) { 139 if (lockedEntries != null && lockedEntries.contains(p1)) { 140 return null; 141 } 142 return super.remove(p1); 143 } 144 145 148 public boolean isKeyLocked(Object key) 149 { 150 return lockedEntries != null && lockedEntries.contains(key); 151 } 152 } 153 | Popular Tags |