FileDocCategorySizeDatePackage
LockableHashtable.javaAPI DocApache Axis 1.44366Sat Apr 22 18:57:28 BST 2006org.apache.axis.utils

LockableHashtable

public class LockableHashtable extends Hashtable
This subclass of the java Hashtable allows individual entries to be "locked" so that their values cannot be overwritten or removed. Note, only the put() and remove() methods have been overridden. The clear() method still removes all entries whether they've been locked or not.
author
James Snell (jasnell@us.ibm.com)

Fields Summary
Vector
lockedEntries
Stores the keys of the locked entries
private Hashtable
parent
Place to look for properties which we don't find locally.
Constructors Summary
public LockableHashtable()


      
        super();
    
public LockableHashtable(int p1, float p2)

        super(p1, p2);
    
public LockableHashtable(Map p1)

        super(p1);
    
public LockableHashtable(int p1)

        super(p1);
    
Methods Summary
public synchronized java.lang.Objectget(java.lang.Object key)
Get an entry from this hashtable, and if we don't find anything, defer to our parent, if any.

        Object ret = super.get(key);
        if ((ret == null) && (parent != null)) {
            ret = parent.get(key);
        }
        return ret;
    
public java.util.SetgetAllKeys()
Returns the keys in this hashtable, and its parent chain

        HashSet set = new HashSet();
        set.addAll(super.keySet());
        Hashtable p = parent;
        while (p != null) {
            set.addAll(p.keySet());
            if (p instanceof LockableHashtable) {
                p = ((LockableHashtable) p).getParent();
            } else {
                p = null;
            }
        }
        return set;
    
public synchronized java.util.HashtablegetParent()
Gets the parent Hashtable for this object (if any)

      return parent;
    
public booleanisKeyLocked(java.lang.Object key)
Returns true if a given key is in our locked list

        return lockedEntries != null && lockedEntries.contains(key);
    
public synchronized java.lang.Objectput(java.lang.Object p1, java.lang.Object p2)
Overrides the Hashtable.put() method to mark items as not being locked.

        return put(p1, p2, false);
    
public synchronized java.lang.Objectput(java.lang.Object p1, java.lang.Object p2, boolean locked)
New version of the put() method that allows for explicitly marking items added to the hashtable as locked.

        if (lockedEntries != null && 
            this.containsKey(p1) && 
            lockedEntries.contains(p1)) {
            return null;
        }
        if (locked) {
            if (lockedEntries == null) {
                lockedEntries = new Vector();
            }
            lockedEntries.add(p1);
        }
        return super.put(p1, p2);
    
public synchronized java.lang.Objectremove(java.lang.Object p1)
Checks to see if an item is locked before it is removed.

        if (lockedEntries != null && lockedEntries.contains(p1)) {
            return null;
        }
        return super.remove(p1);
    
public synchronized voidsetParent(java.util.Hashtable parent)
Set the parent Hashtable for this object

        this.parent = parent;