ptolemy.actor.gt
Class NamedObjVariable

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.AbstractSettableAttribute
              extended by ptolemy.data.expr.Variable
                  extended by ptolemy.actor.gt.NamedObjVariable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable, ValueListener

public class NamedObjVariable
extends Variable

A variable to encapsulate the NamedObj that contains itself. This variable is automatically generated by the expression evaluator when a name resolves to a NamedObj which is not a variable. In that case, one such variable is generated in the resolved NamedObj, whose value is an ObjectToken containing the NamedObj as its value.

Since:
Ptolemy II 6.1
Version:
$Id: NamedObjVariable.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Huining Feng
See Also:
Serialized Form
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.data.expr.Variable
Variable.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Nested classes/interfaces inherited from interface ptolemy.kernel.util.Settable
Settable.Visibility
 
Field Summary
private  boolean _setTokenWithContainer
          Whether the token should be set as the container.
static java.lang.String NAME_PREFIX
          Prefix of the names of any automatically generated NamedObjVariable.
 
Fields inherited from class ptolemy.data.expr.Variable
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _valueListeners
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.kernel.util.Settable
EXPERT, FULL, NONE, NOT_EDITABLE
 
Constructor Summary
NamedObjVariable(NamedObj container)
          Construct a variable with a generated name as an attribute of the given container.
NamedObjVariable(NamedObj container, java.lang.String name)
          Construct a variable with the given name as an attribute of the given container.
 
Method Summary
static NamedObjVariable getNamedObjVariable(NamedObj container, boolean autoCreate)
          Get the NamedObjVariable contained in the container, and create a new one if none is found in the container and autoCreate is true.
 void setContainer(NamedObj container)
          Specify the container, and add this variable to the list of attributes in the container.
 void setToken(Token token)
          Put a new token in this variable and notify the container and and value listeners.
 
Methods inherited from class ptolemy.data.expr.Variable
_description, _evaluate, _notifyValueListeners, _parseIfNecessary, _propagate, _propagateToValueListeners, _propagateValue, _setToken, _setTokenAndNotify, addValueListener, clone, getDeclaredType, getExpression, getFreeIdentifiers, getParserScope, getScope, getScope, getToken, getType, getTypeTerm, getValueAsString, getVariable, getVisibility, invalidate, isKnown, isLazy, isStringMode, isTypeAcceptable, removeValueListener, reset, setExpression, setLazy, setName, setParseTreeEvaluator, setStringMode, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, setUnknown, setVisibility, stringRepresentation, toString, typeConstraintList, typeConstraints, validate, valueChanged
 
Methods inherited from class ptolemy.kernel.util.AbstractSettableAttribute
getDefaultExpression
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName
 

Field Detail

NAME_PREFIX

public static final java.lang.String NAME_PREFIX
Prefix of the names of any automatically generated NamedObjVariable.

See Also:
Constant Field Values

_setTokenWithContainer

private boolean _setTokenWithContainer
Whether the token should be set as the container. This should be false only before the local constructor is invoked. After that, this variable should always be true.

Constructor Detail

NamedObjVariable

public NamedObjVariable(NamedObj container)
                 throws IllegalActionException,
                        NameDuplicationException
Construct a variable with a generated name as an attribute of the given container. The container argument must not be null, otherwise a NullPointerException will be thrown. This variable will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - The container.
Throws:
IllegalActionException - If the container does not accept a variable as its attribute.
NameDuplicationException - If the name coincides with a variable already in the container.

NamedObjVariable

public NamedObjVariable(NamedObj container,
                        java.lang.String name)
                 throws IllegalActionException,
                        NameDuplicationException
Construct a variable with the given name as an attribute of the given container. The container argument must not be null, otherwise a NullPointerException will be thrown. This variable will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - The container.
name - The name of the variable.
Throws:
IllegalActionException - If the container does not accept a variable as its attribute.
NameDuplicationException - If the name coincides with a variable already in the container.
Method Detail

getNamedObjVariable

public static NamedObjVariable getNamedObjVariable(NamedObj container,
                                                   boolean autoCreate)
                                            throws IllegalActionException
Get the NamedObjVariable contained in the container, and create a new one if none is found in the container and autoCreate is true.

Parameters:
container - The container.
autoCreate - Whether a NamedObjVariable should be created if none is found.
Returns:
The NamedObjVariable, or null if none is found and autoCreate is false.
Throws:
IllegalActionException - If variable of the container cannot be retrieved, or a new one cannot be created.

setContainer

public void setContainer(NamedObj container)
                  throws IllegalActionException,
                         NameDuplicationException
Specify the container, and add this variable to the list of attributes in the container. If this variable already has a container, remove this variable from the attribute list of the current container first. Otherwise, remove it from the directory of the workspace, if it is there. If the specified container is null, remove this variable from the list of attributes of the current container. If the specified container already contains an attribute with the same name, then throw an exception and do not make any changes. Similarly, if the container is not in the same workspace as this variable, throw an exception. If this variable is already contained by the specified container, do nothing.

If this method results in a change of container (which it usually does), then remove this variable from the scope of any scope dependent of this variable.

This method is write-synchronized on the workspace and increments its version number.

Overrides:
setContainer in class Variable
Parameters:
container - The proposed container of this variable.
Throws:
IllegalActionException - If the container will not accept a variable as its attribute, or this variable and the container are not in the same workspace, or the proposed container would result in recursive containment.
NameDuplicationException - If the container already has an attribute with the name of this variable.
See Also:
Attribute.getContainer()

setToken

public void setToken(Token token)
              throws IllegalActionException
Put a new token in this variable and notify the container and and value listeners. The token must be an ObjectToken containing the container of this variable. If an expression had been previously given using setExpression(), then that expression is forgotten. If the type of this variable has been set with setTypeEquals(), then convert the specified token into that type, if possible, or throw an exception, if not. If setTypeAtMost() has been called, then verify that its type constraint is satisfied, and if not, throw an exception.
Note that you can call this with a null argument regardless of type constraints, unless there are other variables that depend on its value.
Note that setPersistent(true} may need to be called so that the change to the token is marked as persistent and is exported. to the token is expor

Overrides:
setToken in class Variable
Parameters:
token - The new token to be stored in this variable.
Throws:
IllegalActionException - If the token type is not compatible with specified constraints, or if you are attempting to set to null a variable that has value dependents, or if the container rejects the change.
See Also:
Variable.getToken()