ModelScope.java

package edu.udel.cis.vsl.tass.model.impl.scope;

import java.util.LinkedHashSet;
import java.util.Set;

import edu.udel.cis.vsl.tass.model.IF.ModelIF;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;
import edu.udel.cis.vsl.tass.model.IF.scope.ModelScopeIF;
import edu.udel.cis.vsl.tass.model.IF.scope.ScopeIF;
import edu.udel.cis.vsl.tass.model.IF.variable.SharedVariableIF;

public class ModelScope extends Scope implements ModelScopeIF {

	private ModelIF model;

	private Set<SharedVariableIF> inputVariables = new LinkedHashSet<SharedVariableIF>();

	private Set<SharedVariableIF> outputVariables = new LinkedHashSet<SharedVariableIF>();

	private Set<SharedVariableIF> properSharedVariables = new LinkedHashSet<SharedVariableIF>();

	public ModelScope(ScopeIF parentScope, ModelIF model) {
		super(parentScope, ScopeKind.MODEL, model, "model scope for model"
				+ model);
		this.model = model;
	}

	/** The model for which this is the shared scope. */
	public ModelIF model() {
		return model;
	}

	/**
	 * The variables in this scope are assigned ID numbers 0, 1, 2, ..., at
	 * completion time. This method returns the variable with the given ID.
	 */
	@Override
	public SharedVariableIF variableWithId(int id) {
		return (SharedVariableIF) super.variableWithId(id);
	}

	/**
	 * Returns the variable in this scope with the given name, or null if there
	 * isn't one.
	 */
	@Override
	public SharedVariableIF variableWithName(String name) {
		return (SharedVariableIF) super.variableWithName(name);
	}

	/** Return the collection of input variables for this model. */
	public Set<SharedVariableIF> inputVariables() {
		return inputVariables;
	}

	/** Returns the collection of output variables for this model */
	public Set<SharedVariableIF> outputVariables() {
		return outputVariables;
	}

	/**
	 * Returns the collection of all shared variables that are not input or
	 * output variables
	 */
	public Set<SharedVariableIF> properSharedVariables() {
		return properSharedVariables;
	}

	public void addSharedVariable(SharedVariableIF variable)
			throws SyntaxException {
		if (variable.isInput()) {
			inputVariables.add(variable);
		} else if (variable.isOutput()) {
			outputVariables.add(variable);
		} else {
			properSharedVariables.add(variable);
		}
		addVariable(variable);
	}

}