Package ptolemy.data.expr
Class ModelScope
- java.lang.Object
-
- ptolemy.data.expr.ModelScope
-
- All Implemented Interfaces:
ParserScope
- Direct Known Subclasses:
ActorModelScope
,Expression.VariableScope
,Expression.VariableScope
,FSMActor.PortScope
,NamedProgramCodeGeneratorAdapter.VariableScope
,Variable.VariableScope
,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.getScopedVariable(Variable, NamedObj, String)
is the primary entry point, used by the Expression actor and other code to look up Variables by name.- Since:
- Ptolemy II 2.1
- Version:
- $Id$
- Author:
- Xiaojun Liu, Steve Neuendorffer, Contributor: Bert Rodiers
- See Also:
PtParser
- Pt.AcceptedRating:
- Red (liuxj)
- Pt.ProposedRating:
- Red (liuxj)
-
-
Constructor Summary
Constructors Constructor Description ModelScope()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<java.lang.String>
getAllScopedObjectNames(NamedObj container)
Return a list of object names in scope for variables in the given container.static java.util.Set<java.lang.String>
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
-
-
-
-
Method Detail
-
getAllScopedObjectNames
public static java.util.Set<java.lang.String> getAllScopedObjectNames(NamedObj container)
Return a list of object names in scope for variables in the given container.- Parameters:
container
- The container of this scope.- Returns:
- a list of object names in scope for variables in the given container.
-
getAllScopedVariableNames
public static java.util.Set<java.lang.String> 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.- Returns:
- A list of variable names in scope for variables in the given container.
-
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.
-
-