ptolemy.actor
Class TypeAttribute

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.data.expr.Parameter
                      extended by ptolemy.actor.TypeAttribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable, ValueListener

public class TypeAttribute
extends Parameter

An attribute for defining a data type for a port. Use setExpression() to define a data type, as in for example,

 attribute.setExpression("double");
 
The class TypedIOPort recognizes when this attribute is inserted and calls setTypeEquals() to define its type. In the above example, the type of the port is set to double.

The type can be given by any expression that can be evaluated. In fact, it would be equally valid to specify the type to be double using

 attribute.setExpression("0.0");
 
The Constants class defines the constant "double" to have the value 0.0, so that instead you may give the type by name. The Constants class defines for convenience the following constants: boolean, complex, double, fixedpoint, general, int, long, matrix, object, scalar, string, and unknown. The constant "unknown" has a rather special behavior, in that it sets the type of the port to be unknown, allowing type resolution to infer it. The constant "matrix" designates a matrix without specifying an element type, in contrast to, for example, "[double]", which specifies a double matrix. Similarly, the constant "scalar" designates a scalar of any type (double, int, long, etc.). The constant "general" designates any type.

Since the type is given by a "prototype" (an expression with the appropriate type), any data type that can be given in an expression can be specified as a type. For structured types, follow the same syntax as in expressions. For example:

 {double} - double array
 [int]    - int matrix
 {field1 = string, field2 = int} - record with two fields
 

This attribute is a singleton in a strong sense. When its container is set, if the container contains any other instance of TypeAttribute, that other instance is removed.

Since:
Ptolemy II 1.0
Version:
$Id: TypeAttribute.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Edward A. Lee, Xiaojun Liu
See Also:
TypedIOPort, Constants, Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

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
 
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
TypeAttribute(Attribute container, java.lang.String name)
          Construct an attribute with the given name contained by the specified port.
TypeAttribute(TypedIOPort container, java.lang.String name)
          Construct an attribute with the given name contained by the specified port.
TypeAttribute(Workspace workspace)
          Construct a parameter in the specified workspace with an empty string as a name.
 
Method Summary
protected  void _checkContainer(NamedObj container)
          Override the base class to ensure that the proposed container is a TypedIOPort or a Kepler PortAttribute.
 void setContainer(NamedObj container)
          Override the base class to remove any other instances of TypeAttribute.
 
Methods inherited from class ptolemy.data.expr.Parameter
addChoice, exportMoML, getChoices, removeAllChoices, removeChoice
 
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, 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
_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, 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
 

Constructor Detail

TypeAttribute

public TypeAttribute(Workspace workspace)
Construct a parameter in the specified workspace with an empty string as a name. If the workspace argument is null, then use the default workspace. The object is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - The workspace that will list the parameter.

TypeAttribute

public TypeAttribute(TypedIOPort container,
                     java.lang.String name)
              throws IllegalActionException,
                     NameDuplicationException
Construct an attribute with the given name contained by the specified port. The container argument must not be null, or a NullPointerException will be thrown. This attribute 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. The object is added to the directory of the workspace if the container is null. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of this attribute.
Throws:
IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
NameDuplicationException - If the name coincides with an attribute already in the container.

TypeAttribute

public TypeAttribute(Attribute container,
                     java.lang.String name)
              throws IllegalActionException,
                     NameDuplicationException
Construct an attribute with the given name contained by the specified port. The container argument must not be null, or a NullPointerException will be thrown. This attribute 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. The object is added to the directory of the workspace if the container is null. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of this attribute.
Throws:
IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
NameDuplicationException - If the name coincides with an attribute already in the container.
Method Detail

setContainer

public void setContainer(NamedObj container)
                  throws IllegalActionException,
                         NameDuplicationException
Override the base class to remove any other instances of TypeAttribute.

Overrides:
setContainer in class Variable
Parameters:
container - The proposed container.
Throws:
IllegalActionException - If the proposed container is not a TypedIOPort, or if the base class throws it.
NameDuplicationException - If the container already has an attribute with the name of this attribute that is not an instance of TypeAttribute.
See Also:
Attribute.getContainer()

_checkContainer

protected void _checkContainer(NamedObj container)
                        throws IllegalActionException
Override the base class to ensure that the proposed container is a TypedIOPort or a Kepler PortAttribute.

Overrides:
_checkContainer in class Attribute
Parameters:
container - The proposed container.
Throws:
IllegalActionException - If the proposed container is not a TypedIOPort, or if the base class throws it.