ptolemy.moml.unit
Class UnitAttribute

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

public class UnitAttribute
extends AbstractSettableAttribute

This class is used to implement the Unit Attribute. A UnitsAttribute is either a UnitExpr, or a vector of UnitConstraints.

Since:
Ptolemy II 8.0
Version:
$Id: UnitAttribute.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Rowland R Johnson
See Also:
Serialized Form
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

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 static int _CONSTRAINTS
           
private static int _EXPRESSION
           
private  int _type
           
private  UnitConstraints _unitConstraints
           
private  UnitExpr _unitExpr
           
private  java.util.List _valueListeners
           
(package private)  Settable.Visibility _visibility
           
 
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
UnitAttribute()
          Construct a UnitsAttribute with no specific name, or container.
UnitAttribute(NamedObj container, java.lang.String name)
          Construct a UnitsAttribute with the specified name, and container.
 
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 the UnitsAttribute.
 java.lang.String getExpression()
          Get the descriptive form of this attribute.
 UnitConstraints getUnitConstraints()
          Get the UnitConstraints.
 UnitExpr getUnitExpr()
          Get the Unit Expression.
 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 expression.
 void setUnitConstraints(UnitConstraints constraints)
          Set the UnitConstraints.
 void setUnitExpr(UnitExpr expr)
          Set the Unit Expression.
 void setVisibility(Settable.Visibility visibility)
          Set the visibility of this attribute.
 java.util.Collection validate()
          Check the validity of the expression set in setExpression().
 
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

_visibility

Settable.Visibility _visibility

_valueListeners

private java.util.List _valueListeners

_unitExpr

private UnitExpr _unitExpr

_unitConstraints

private UnitConstraints _unitConstraints

_type

private int _type

_EXPRESSION

private static final int _EXPRESSION
See Also:
Constant Field Values

_CONSTRAINTS

private static final int _CONSTRAINTS
See Also:
Constant Field Values
Constructor Detail

UnitAttribute

public UnitAttribute()
              throws IllegalActionException,
                     NameDuplicationException
Construct a UnitsAttribute with no specific name, or container.

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.

UnitAttribute

public UnitAttribute(NamedObj container,
                     java.lang.String name)
              throws IllegalActionException,
                     NameDuplicationException
Construct a UnitsAttribute with the specified name, and container.

Parameters:
container - Container
name - Name
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:
Settable.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 the UnitsAttribute. Nothing is written if the value is null or "".

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.exportMoML(Writer, int, String)

getExpression

public java.lang.String getExpression()
Get the descriptive form of this attribute.

Returns:
a String that represents the descriptive form.
See Also:
Settable.getExpression()

getUnitConstraints

public UnitConstraints getUnitConstraints()
Get the UnitConstraints.

Returns:
The UnitConstraints.

getUnitExpr

public UnitExpr getUnitExpr()
Get the Unit Expression.

Returns:
The UnitExpr.

getVisibility

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

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

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:
Settable.addValueListener(ValueListener)

setExpression

public void setExpression(java.lang.String expression)
                   throws IllegalActionException
Set the expression. This method takes the descriptive form and determines the internal form (by parsing the descriptive form) and stores it.

Specified by:
setExpression in interface Settable
Overrides:
setExpression in class AbstractSettableAttribute
Parameters:
expression - A String that is the descriptive form of either a Unit or a UnitEquation.
Throws:
IllegalActionException - If the expression is invalid (not thrown in this base class).
See Also:
Settable.setExpression(java.lang.String)

setUnitConstraints

public void setUnitConstraints(UnitConstraints constraints)
Set the UnitConstraints.

Parameters:
constraints - The UnitConstraints.

setUnitExpr

public void setUnitExpr(UnitExpr expr)
Set the Unit Expression.

Parameters:
expr - A UnitExpr.

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:
Settable.setVisibility(Settable.Visibility)

validate

public java.util.Collection validate()
                              throws IllegalActionException
Description copied from interface: Settable
Check the validity of the expression set in setExpression(). Implementations of this method should notify the container by calling attributeChanged(), unless the container has already been notified in setExpression(). They should also notify any registered value listeners if they have not already been notified. If any other instances of Settable are validated as a side effect, then an implementation should return a Collection containing those instances. This can be used by the caller to avoid validating those again. The list may contain this instance of Settable.

Returns:
A collection of settables that are also validated as a side effect, or null if there are none.
Throws:
IllegalActionException - If the expression is not valid, or its value is not acceptable to the container or the listeners.

_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.