package jdslx.core.ref;

import jdsl.core.api.*;
import jdslx.core.api.*;

/**
 * Implements read access to attributes represented by elements
 * that can be accessed through <code>Accessors</code>.
 *
 * @see jdsl.core.api.Accessor
 *
 * @author Ulrik Brandes 
 * @version 1.0, 07/31/99
**/

public class AccessorAttribute implements InspectableAttribute {

  /**
   * Provides the element currently referenced by this accessor.
   * 
   * @return the element referenced by this accessor
   * @exception InvalidAccessorException 
   *            if the argument is not an <code>Accessor</code>
  **/

  public Object get(Object acc) { 
    try {
      return ((Accessor) acc).element();
    } catch(ClassCastException e) {
      throw new InvalidAccessorException("Attempted attribute access via something other than an accessor.");
    }
  }

}
