/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.model;

import java.awt.Component;

/**
 * This typesave enumeration contains all existing Scope types. 
 * It can be used to set the scope that certain components should use to
 * retrieve symbols from.
 *
 * @author Markus Kraetzig
 */
public abstract class Scope {

	private final String name;

	/**
	 * The local symbol scope.
	 */
	public static final Scope GLOBAL = new Scope("GLOBAL") {
		public SymbolTable getSymbolTable(Component comp) {
			if (comp instanceof SymbolScope)
				return ((SymbolScope) comp).global();

			SymbolScope scope = ModelPanel.findParentScope(comp);
			if (scope == null)
				return null;
			return scope.global();
		}
	};
	/**
	 * The local symbol scope.
	 */
	public static final Scope UPPER = new Scope("UPPER") {
		public SymbolTable getSymbolTable(Component comp) {
			if (comp instanceof SymbolScope)
				return ((SymbolScope) comp).upper();

			SymbolScope scope = ModelPanel.findParentScope(comp);
			if (scope == null)
				return null;
			return scope.upper();
		}
	};
	/**
	 * The local symbol scope.
	 */
	public static final Scope LOCAL = new Scope("LOCAL") {
		public SymbolTable getSymbolTable(Component comp) {
			if (comp instanceof SymbolScope)
				return ((SymbolScope) comp).local();

			SymbolScope scope = ModelPanel.findParentScope(comp);
			if (scope == null)
				return null;
			return scope.local();
		}
	};

	/**
	 * Not to be invoked.
	 */
	protected Scope(String name) {
		this.name = name;
	}

	/**
	 * Gets the symbol table according to this scope from the
	 * component hierarchy. The method returns null of there
	 * is no parent SymbolScope.
	 * 
	 * @param comp the component to start searching from
	 * @return the symbol table or null
	 */
	public abstract SymbolTable getSymbolTable(Component comp);

	/**
	 * Gets string representation of this object.
	 *
	 * @return a string 
	 */
	public final String toString() {
		return name;
	}

}
 

Ads help maintain this website.