ptolemy.kernel.util
Class AbstractSettableAttribute

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.AbstractSettableAttribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable
Direct Known Subclasses:
StringAttribute, UnitAttribute, Variable

public abstract class AbstractSettableAttribute
extends Attribute
implements Settable

This is an abstract base class for attributes that implement the Settable interface. In particular, it provides a default implementation of the getDefaultExpression() method. If this object is derived from another, then the default value is obtained from that other. Otherwise, the default value is the first value set using setExpression().

Since:
Ptolemy II 4.1
Version:
$Id: AbstractSettableAttribute.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Green (hyzheng)
Proposed Rating:
Green (eal)

Nested Class Summary
 
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  java.lang.String _default
          The default value.
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_attributes, _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
  AbstractSettableAttribute()
          Construct an attribute in the default workspace with an empty string as its name.
  AbstractSettableAttribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified entity.
protected AbstractSettableAttribute(NamedObj container, java.lang.String name, boolean incrementWorkspaceVersion)
          Construct an attribute with the given name contained by the specified entity.
  AbstractSettableAttribute(Workspace workspace)
          Construct an attribute in the specified workspace with an empty string as a name.
 
Method Summary
 java.lang.String getDefaultExpression()
          Return the default value of this Settable, or null if no default has been set.
 java.lang.String getValueAsString()
          Get the value of the attribute, which is the evaluated expression.
 void setExpression(java.lang.String expression)
          Set the value of this attribute to the specified expression.
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _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, toString, 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
addValueListener, getDisplayName, getExpression, getVisibility, removeValueListener, setVisibility, validate
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName, setName
 

Field Detail

_default

private java.lang.String _default
The default value.

Constructor Detail

AbstractSettableAttribute

public AbstractSettableAttribute()
Construct an attribute in the default workspace with an empty string as its name. The object is added to the directory of the workspace. Increment the version number of the workspace.


AbstractSettableAttribute

public AbstractSettableAttribute(Workspace workspace)
Construct an attribute in the specified workspace with an empty string as a name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace. The object is added to the directory of the workspace. Increment the version number of the workspace.

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

AbstractSettableAttribute

public AbstractSettableAttribute(NamedObj container,
                                 java.lang.String name)
                          throws IllegalActionException,
                                 NameDuplicationException
Construct an attribute with the given name contained by the specified entity. 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. 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.

AbstractSettableAttribute

protected AbstractSettableAttribute(NamedObj container,
                                    java.lang.String name,
                                    boolean incrementWorkspaceVersion)
                             throws IllegalActionException,
                                    NameDuplicationException
Construct an attribute with the given name contained by the specified entity. 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. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of this attribute.
incrementWorkspaceVersion - False to not add this to the workspace or do anything else that might change the workspace version number.
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

getDefaultExpression

public java.lang.String getDefaultExpression()
Return the default value of this Settable, or null if no default has been set. If this object is derived (in the actor-oriented class mechanism, see the Instantiable interface), then the default is the value of the object from which this is derived (the "prototype"). If this is not a derived object, then the default is the first value set using setExpression(), or null if setExpression() has not been called.

Specified by:
getDefaultExpression in interface Settable
Returns:
The default value of this attribute, or null if there is none.
See Also:
setExpression(String), Instantiable

getValueAsString

public java.lang.String getValueAsString()
Get the value of the attribute, which is the evaluated expression.

Specified by:
getValueAsString in interface Settable
Returns:
The same as getExpression().
See Also:
Settable.getExpression()

setExpression

public void setExpression(java.lang.String expression)
                   throws IllegalActionException
Set the value of this attribute to the specified expression. This base class implementation merely records the first value to serve as the default value if needed. Subclasses are required to override this to also record the value and to call super.setExpression().

Specified by:
setExpression in interface Settable
Parameters:
expression - The value of this attribute.
Throws:
IllegalActionException - If the expression is invalid (not thrown in this base class).
See Also:
getDefaultExpression()