ptolemy.kernel.util
Class StringAttribute

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.AbstractSettableAttribute
              extended by ptolemy.kernel.util.StringAttribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable
Direct Known Subclasses:
Action, Action, Documentation, FileAttribute, GraphTransformer.ReplacementObjectAttribute, GTIngredientsAttribute, PatternObjectAttribute, VersionAttribute

public class StringAttribute
extends AbstractSettableAttribute

An attribute that has a string value. Use setExpression() to define the value, as in for example

 attribute.setExpression("xxx");
 

The default value of the string contained by this attribute is the empty string.

By default, an instance of this class is fully visible in a user interface. The visibility is indicated to the user interface when the user interface calls the getVisibility() method of this class and the value Settable.FULL is returned to the userInterface.

Note that the string value within StringAttribute cannot reference other StringAttributes or Parameters, so if an actor has a public StringAttribute, then one cannot make the value of that attribute dependent on a value higher in the hierarchy. Usually, actors have public ptolemy.data.expr.Parameters instead of public StringAttributes so that the value can reference other parameters. The primary reason to use StringAttribute is if you want a string that will not be parsed and you do not want to type a leading a trailing double quote.

Since:
Ptolemy II 1.0
Version:
$Id: StringAttribute.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Edward A. Lee
See Also:
Settable.FULL, Serialized Form
Accepted Rating:
Green (cxh)
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 _value
           
private  java.util.List _valueListeners
           
private  Settable.Visibility _visibility
           
 
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
StringAttribute()
          Construct an attribute in the default workspace with an empty string as its name.
StringAttribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified container.
StringAttribute(Workspace workspace)
          Construct an attribute in the specified workspace with an empty string as a name.
 
Method Summary
protected  void _propagateValue(NamedObj destination)
          Propagate the value of this object to the specified object.
 void addValueListener(ValueListener listener)
          Add a listener to be notified when the value of this attribute changes.
 void exportMoML(java.io.Writer output, int depth, java.lang.String name)
          Write a MoML description of this object, unless it is non-persistent.
 java.lang.String getExpression()
          Get the value that has been set by setExpression(), or null if there is none.
 Settable.Visibility getVisibility()
          Get the visibility of this attribute, as set by setVisibility().
 void removeValueListener(ValueListener listener)
          Remove a listener from the list of listeners that is notified when the value of this attribute changes.
 void setExpression(java.lang.String expression)
          Set the value of the string attribute and notify the container of the value of this attribute by calling attributeChanged().
 void setVisibility(Settable.Visibility visibility)
          Set the visibility of this attribute.
 java.util.Collection validate()
          Do nothing.
 
Methods inherited from class ptolemy.kernel.util.AbstractSettableAttribute
getDefaultExpression, getValueAsString
 
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, _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, 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
getDisplayName
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName, setName
 

Field Detail

_value

private java.lang.String _value

_valueListeners

private java.util.List _valueListeners

_visibility

private Settable.Visibility _visibility
Constructor Detail

StringAttribute

public StringAttribute()
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.


StringAttribute

public StringAttribute(Workspace workspace)
Construct an attribute in the specified workspace with an empty string as a name. 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.

StringAttribute

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

addValueListener

public void addValueListener(ValueListener listener)
Add a listener to be notified when the value of this attribute changes. If the listener is already on the list of listeners, then do nothing.

Parameters:
listener - The listener to add.
See Also:
removeValueListener(ValueListener)

exportMoML

public void exportMoML(java.io.Writer output,
                       int depth,
                       java.lang.String name)
                throws java.io.IOException
Write a MoML description of this object, unless it is non-persistent. MoML is an XML modeling markup language. In this class, the object is identified by the "property" element, with "name", "class", and "value" (XML) attributes. The body of the element, between the "<property>" and "</property>", is written using the _exportMoMLContents() protected method, so that derived classes can override that method alone to alter only how the contents of this object are described. The text that is written is indented according to the specified depth, with each line (including the last one) terminated with a newline.

Specified by:
exportMoML in interface MoMLExportable
Overrides:
exportMoML in class NamedObj
Parameters:
output - The output stream to write to.
depth - The depth in the hierarchy, to determine indenting.
name - The name to use instead of the current name.
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
NamedObj.isPersistent()

getExpression

public java.lang.String getExpression()
Get the value that has been set by setExpression(), or null if there is none.

Returns:
The string value.
See Also:
setExpression(String)

getVisibility

public Settable.Visibility getVisibility()
Get the visibility of this attribute, as set by setVisibility(). The visibility is set by default to FULL.

Returns:
The visibility of this attribute.
See Also:
setVisibility(Settable.Visibility)

removeValueListener

public void removeValueListener(ValueListener listener)
Remove a listener from the list of listeners that is notified when the value of this attribute changes. If no such listener exists, do nothing.

Parameters:
listener - The listener to remove.
See Also:
addValueListener(ValueListener)

setExpression

public void setExpression(java.lang.String expression)
                   throws IllegalActionException
Set the value of the string attribute and notify the container of the value of this attribute by calling attributeChanged(). Notify any value listeners of this attribute.

Specified by:
setExpression in interface Settable
Overrides:
setExpression in class AbstractSettableAttribute
Parameters:
expression - The value of the string attribute.
Throws:
IllegalActionException - If the change is not acceptable to the container.
See Also:
getExpression()

setVisibility

public void setVisibility(Settable.Visibility visibility)
Set the visibility of this attribute. The argument should be one of the public static instances in Settable.

Parameters:
visibility - The visibility of this attribute.
See Also:
getVisibility()

validate

public java.util.Collection validate()
                              throws IllegalActionException
Do nothing. There is no need to notify the container or listeners of this attribute because they have presumably already been notified in setExpression().

Returns:
Null, indicating that no other instances of Settable are validated.
Throws:
IllegalActionException - If the change is not acceptable to the container.

_propagateValue

protected void _propagateValue(NamedObj destination)
                        throws IllegalActionException
Propagate the value of this object to the specified object. The specified object is required to be an instance of the same class as this one, or a ClassCastException will be thrown.

Overrides:
_propagateValue in class NamedObj
Parameters:
destination - Object to which to propagate the value.
Throws:
IllegalActionException - If the value cannot be propagated.