package jdslx.core.ref;

import java.util.Hashtable;
import jdslx.core.api.*;

/**
 * Implements read and write access to attributes 
 * stored in <code>Hashtables</code>.
 * 
 * @see java.util.Hastable
 *
 * @author Ulrik Brandes
 * @version 1.0, 07/31/99
**/

public class HashtableAttribute implements Attribute {

  /**
   * <code>Hashtable</code> storing the attribute values.
  **/

  protected Hashtable hash_;


  /**
   * Use this <code>Hashtable</code> for the attributes.
  **/

  public HashtableAttribute(Hashtable attribute) 
  { hash_ = attribute; }


  /**
   * Read access to the attribute.
   * 
   * @return the value of the attribute
   * @exception InvalidAttributeException
   *	if <code>elem</code> has no attribute in the hashtable
  **/

  public Object get(Object elem) { 
    Object value = hash_.get(elem);
    if(value == null) 
      throw new InvalidAttributeException("Hashtable contains no attribute for " + elem);
    return value;
  }


  /**
   * Write acces to the attribute.
   *
   * @exception NullPointerException
   *	if the <code>elem</code> or <code>value</code> is <code>null</code>
  **/

  public void set(Object elem, Object value) { 
    hash_.put(elem, value); // may throw NullPointerException
  }

}
