ptolemy.data.expr
Class ModelScope

java.lang.Object
  extended by ptolemy.data.expr.ModelScope
All Implemented Interfaces:
ParserScope
Direct Known Subclasses:
CodeGeneratorHelper.VariableScope, Expression.VariableScope, Expression.VariableScope, Expression.VariableScope, ExpressionToToken.ExpressionScope, FSMActor.PortScope, FSMActor.PortScope, PSDFScheduler.ScheduleScope, Variable.VariableScope, VariableScope

public abstract class ModelScope
extends java.lang.Object
implements ParserScope

An abstract class that is useful for implementing expression language scopes for Ptolemy models.

Since:
Ptolemy II 2.1
Version:
$Id: ModelScope.java 54721 2009-06-26 22:32:23Z cxh $
Author:
Xiaojun Liu, Steve Neuendorffer, Contributor: Bert Rodiers
See Also:
PtParser
Accepted Rating:
Red (liuxj)
Proposed Rating:
Red (liuxj)

Constructor Summary
ModelScope()
           
 
Method Summary
private static Attribute _searchAttributeIn(Attribute exclude, NamedObj container, java.lang.String name)
           
private static Variable _searchVariableIn(Variable exclude, NamedObj container, java.lang.String name)
           
static java.util.Set getAllScopedObjectNames(NamedObj container)
          Return a list of object names in scope for variables in the given container.
static java.util.Set getAllScopedVariableNames(Variable exclude, NamedObj container)
          Return a list of variable names in scope for variables in the given container.
static Attribute getScopedAttribute(Attribute exclude, NamedObj container, java.lang.String name)
          Get the attribute with the given name in the scope of the given container.
static NamedObj getScopedObject(NamedObj container, java.lang.String name)
          Get the NamedObj with the given name in the scope of the given container.
static Variable getScopedVariable(Variable exclude, NamedObj container, java.lang.String name)
          Get the variable with the given name in the scope of the given container.
static Token preferenceValue(NamedObj context, java.lang.String preferenceName)
          Check to see whether a preference of the specified name is defined in the specified context, and if it is, return its value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ptolemy.data.expr.ParserScope
get, getType, getTypeTerm, identifierSet
 

Constructor Detail

ModelScope

public ModelScope()
Method Detail

getAllScopedObjectNames

public static java.util.Set getAllScopedObjectNames(NamedObj container)
Return a list of object names in scope for variables in the given container.

Parameters:
container - The container of this scope.

getAllScopedVariableNames

public static java.util.Set getAllScopedVariableNames(Variable exclude,
                                                      NamedObj container)
Return a list of variable names in scope for variables in the given container. Exclude the given variable from being considered in scope.

Parameters:
exclude - The variable to exclude from the scope.
container - The container of this scope.

getScopedAttribute

public static Attribute getScopedAttribute(Attribute exclude,
                                           NamedObj container,
                                           java.lang.String name)
Get the attribute with the given name in the scope of the given container. If the name contains the "::" scoping specifier, then an attribute more deeply in the hierarchy is searched for. The scope of the object includes any container of the given object, and any attribute contained in a scope extending attribute inside any of those containers.

Parameters:
exclude - An attribute to exclude from the search.
container - The container to search upwards from.
name - The attribute name to search for.
Returns:
The attribute with the given name or null if the attribute does not exist.

getScopedObject

public static NamedObj getScopedObject(NamedObj container,
                                       java.lang.String name)
Get the NamedObj with the given name in the scope of the given container. If the name contains the "::" scoping specifier, then an attribute more deeply in the hierarchy is searched for. If the specified container is lazy (implements LazyComposite), then references to its contained entities or relations will not resolve, so such references are disallowed.

Parameters:
container - The container to search upwards from.
name - The object name to search for.
Returns:
The NamedObj with the given name or null if the NamedObj does not exist.

getScopedVariable

public static Variable getScopedVariable(Variable exclude,
                                         NamedObj container,
                                         java.lang.String name)
Get the variable with the given name in the scope of the given container. If the name contains the "::" scoping specifier, then an attribute more deeply in the hierarchy is searched for. The scope of the object includes any container of the given object, and any variable contained in a scope extending attribute inside any of those containers.

Parameters:
exclude - A variable to exclude from the search.
container - The container to search upwards from.
name - The variable name to search for.
Returns:
The variable with the given name or null if the variable does not exist.

preferenceValue

public static Token preferenceValue(NamedObj context,
                                    java.lang.String preferenceName)
Check to see whether a preference of the specified name is defined in the specified context, and if it is, return its value. Note that if there is an error in the expression for the preference, then this method will return null and report the error to standard out. This is done because we assume the error will normally be caught before this method is called.

Parameters:
context - The context for the preference.
preferenceName - The name of the preference.
Returns:
The value of the preference, or null if it is not set.

_searchAttributeIn

private static Attribute _searchAttributeIn(Attribute exclude,
                                            NamedObj container,
                                            java.lang.String name)

_searchVariableIn

private static Variable _searchVariableIn(Variable exclude,
                                          NamedObj container,
                                          java.lang.String name)