Package ptolemy.moml.unit
Class UnitAttribute
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.kernel.util.AbstractSettableAttribute
-
- ptolemy.moml.unit.UnitAttribute
-
- All Implemented Interfaces:
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$
- Author:
- Rowland R Johnson
- Pt.AcceptedRating:
- Red (rowland)
- Pt.ProposedRating:
- 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
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_propagateValue(NamedObj destination)Propagate the value of this object to the specified object.voidaddValueListener(ValueListener listener)Add a listener to be notified when the value of this attribute changes.voidexportMoML(java.io.Writer output, int depth, java.lang.String name)Write a MoML description of the UnitsAttribute.java.lang.StringgetExpression()Get the descriptive form of this attribute.UnitConstraintsgetUnitConstraints()Get the UnitConstraints.UnitExprgetUnitExpr()Get the Unit Expression.Settable.VisibilitygetVisibility()Get the visibility of this attribute, as set by setVisibility().voidremoveValueListener(ValueListener listener)Remove a listener from the list of listeners that is notified when the value of this attribute changes.voidsetExpression(java.lang.String expression)Set the expression.voidsetUnitConstraints(UnitConstraints constraints)Set the UnitConstraints.voidsetUnitExpr(UnitExpr expr)Set the Unit Expression.voidsetVisibility(Settable.Visibility visibility)Set the visibility of this attribute.java.util.Collectionvalidate()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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, 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, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.Nameable
description, getContainer, getFullName, getName, getName, setName
-
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
-
-
-
-
Constructor Detail
-
UnitAttribute
public UnitAttribute() throws IllegalActionException, NameDuplicationExceptionConstruct 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- Containername- 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.IOExceptionWrite a MoML description of the UnitsAttribute. Nothing is written if the value is null or "".- Specified by:
exportMoMLin interfaceMoMLExportable- Overrides:
exportMoMLin classNamedObj- 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 IllegalActionExceptionSet the expression. This method takes the descriptive form and determines the internal form (by parsing the descriptive form) and stores it.- Specified by:
setExpressionin interfaceSettable- Overrides:
setExpressionin classAbstractSettableAttribute- 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 IllegalActionExceptionDescription copied from interface:SettableCheck 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:
_propagateValuein classNamedObj- Parameters:
destination- Object to which to propagate the value.- Throws:
IllegalActionException- If the value cannot be propagated.
-
-