ptolemy.kernel.util
Class Attribute

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
AbstractSettableAttribute, AttributeMatcher, CausalityMarker, CodeGenerator, ConfigurableAttribute, Configurer.ContainmentExtender, Configurer.ContainmentExtender, ContainmentExtender, ContainmentExtender, ContextMenuFactoryCreator, DecoratedAttributes, DependencyDeclaration, DesignPatternImporter, Director, DocBuilder, EditorFactory, EditorIcon, EditorPaneFactory, GiottoCodeGenerator, GUIAction, GUIProperty, HighlightEntities, ImportAttribute, KeplerDocumentationAttribute, MatchingAttribute, MathematicalModelConverter, ModelRepaintController, MoMLAttribute, MoMLModelAttribute, ParameterEditorStyle, RefinementExtender, RefinementExtender, RefinementSuggestion, RefinementSuggestion, SchedulePlotter, Scheduler, ScopeExtendingAttribute, SingletonAttribute, TableauFactory, TDLCodeGenerator, TransformationAttribute, TransformationAttribute.TransformationListener, TransformationMode.WorkingCopyScopeExtender, UnitCategory, VisibleAttribute

public class Attribute
extends NamedObj

Attribute is a base class for attributes to be attached to instances of NamedObj. This base class is itself a NamedObj, with the only extension being that it can have a container. The setContainer() method puts this object on the list of attributes of the container.

Since:
Ptolemy II 0.2
Version:
$Id: Attribute.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee, Neil Smyth
See Also:
Serialized Form
Accepted Rating:
Green (johnr)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  NamedObj _container
           
 
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
 
Constructor Summary
  Attribute()
          Construct an attribute in the default workspace with an empty string as its name.
  Attribute(NamedObj container, java.lang.String name)
          Construct an attribute with the given name contained by the specified entity.
protected Attribute(NamedObj container, java.lang.String name, boolean incrementWorkspaceVersion)
          Construct an attribute with the given name contained by the specified entity.
  Attribute(Workspace workspace)
          Construct an attribute in the specified workspace with an empty string as a name.
 
Method Summary
protected  void _checkContainer(NamedObj container)
          Check that the specified container is of a suitable class for this attribute.
protected  NamedObj _getContainedObject(NamedObj container, java.lang.String relativeName)
          Get an attribute with the specified name in the specified container.
protected  NamedObj _propagateExistence(NamedObj container)
          Propagate existence of this object to the specified object.
 java.lang.Object clone(Workspace workspace)
          Clone the object into the specified workspace.
 NamedObj getContainer()
          Get the NamedObj that this Attribute is attached to.
 int moveDown()
          Move this object down by one in the list of attributes of its container.
 int moveToFirst()
          Move this object to the first position in the list of attributes of the container.
 int moveToIndex(int index)
          Move this object to the specified position in the list of attributes of the container.
 int moveToLast()
          Move this object to the last position in the list of attributes of the container.
 int moveUp()
          Move this object up by one in the list of attributes of the container.
 void setContainer(NamedObj container)
          Specify the container NamedObj, adding this attribute to the list of attributes in the container.
 void setName(java.lang.String name)
          Set the name of the attribute.
 void updateContent()
          Update the content of this attribute.
 
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
 

Field Detail

_container

private NamedObj _container
Constructor Detail

Attribute

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


Attribute

public Attribute(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.

Attribute

public Attribute(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.

Attribute

protected Attribute(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

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there). The result is an attribute with no container.

Overrides:
clone in class NamedObj
Parameters:
workspace - The workspace for the cloned object.
Returns:
The new Attribute.
Throws:
java.lang.CloneNotSupportedException - Not thrown in this base class
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

moveDown

public int moveDown()
             throws IllegalActionException
Move this object down by one in the list of attributes of its container. If this object is already last, do nothing. This method gets write access on workspace and increments the version.

Specified by:
moveDown in interface Moveable
Overrides:
moveDown in class NamedObj
Returns:
The index of the specified object prior to moving it, or -1 if it is not moved.
Throws:
IllegalActionException - If this object has no container.

moveToFirst

public int moveToFirst()
                throws IllegalActionException
Move this object to the first position in the list of attributes of the container. If this object is already first, do nothing. This method gets write access on workspace and increments the version.

Specified by:
moveToFirst in interface Moveable
Overrides:
moveToFirst in class NamedObj
Returns:
The index of the specified object prior to moving it, or -1 if it is not moved.
Throws:
IllegalActionException - If this object has no container.

moveToIndex

public int moveToIndex(int index)
                throws IllegalActionException
Move this object to the specified position in the list of attributes of the container. If this object is already at the specified position, do nothing. This method gets write access on workspace and increments the version.

Specified by:
moveToIndex in interface Moveable
Overrides:
moveToIndex in class NamedObj
Parameters:
index - The zero based position to which this object is moved. 0 means the first position, 1 means the second position.
Returns:
The index of the specified object prior to moving it, or -1 if it is not moved.
Throws:
IllegalActionException - If this object has no container or if the index is out of bounds.

moveToLast

public int moveToLast()
               throws IllegalActionException
Move this object to the last position in the list of attributes of the container. If this object is already last, do nothing. This method gets write access on workspace and increments the version.

Specified by:
moveToLast in interface Moveable
Overrides:
moveToLast in class NamedObj
Returns:
The index of the specified object prior to moving it, or -1 if it is not moved.
Throws:
IllegalActionException - If this object has no container.

moveUp

public int moveUp()
           throws IllegalActionException
Move this object up by one in the list of attributes of the container. If this object is already first, do nothing. This method gets write access on workspace and increments the version.

Specified by:
moveUp in interface Moveable
Overrides:
moveUp in class NamedObj
Returns:
The index of the specified object prior to moving it, or -1 if it is not moved.
Throws:
IllegalActionException - If this object has no container.

getContainer

public NamedObj getContainer()
Get the NamedObj that this Attribute is attached to.

Specified by:
getContainer in interface Nameable
Overrides:
getContainer in class NamedObj
Returns:
The container, an instance of NamedObj.
See Also:
setContainer(NamedObj)

setContainer

public void setContainer(NamedObj container)
                  throws IllegalActionException,
                         NameDuplicationException
Specify the container NamedObj, adding this attribute to the list of attributes in the container. If the container already contains an attribute with the same name, then throw an exception and do not make any changes. Similarly, if the container is not in the same workspace as this attribute, throw an exception. If this attribute is already contained by the NamedObj, do nothing. If the attribute already has a container, remove this attribute from its attribute list first. Otherwise, remove it from the directory of the workspace, if it is there. If the argument is null, then remove it from its container. It is not added to the workspace directory, so this could result in this object being garbage collected. Note that since an Attribute is a NamedObj, it can itself have attributes. However, recursive containment is not allowed, where an attribute is an attribute of itself, or indirectly of any attribute it contains. This method is write-synchronized on the workspace and increments its version number.

Subclasses may constrain the type of container by overriding setContainer(NamedObj).

Parameters:
container - The container to attach this attribute to..
Throws:
IllegalActionException - If this attribute is not of the expected class for the container, or it has no name, or the attribute and container are not in the same workspace, or the proposed container would result in recursive containment.
NameDuplicationException - If the container already has an attribute with the name of this attribute.
See Also:
getContainer()

setName

public void setName(java.lang.String name)
             throws IllegalActionException,
                    NameDuplicationException
Set the name of the attribute. If there is already an attribute of the container with the same name, then throw a NameDuplicationException.

Specified by:
setName in interface Nameable
Overrides:
setName in class NamedObj
Parameters:
name - The new name.
Throws:
IllegalActionException - If the name contains a period.
NameDuplicationException - If there is already an attribute with the same name in the container.
See Also:
NamedObj.getName(), NamedObj.getName(NamedObj)

updateContent

public void updateContent()
                   throws InternalErrorException
Update the content of this attribute. In this base class, nothing is performed. Subclasses need to override this class to update the attribute.

Throws:
InternalErrorException - Not thrown in this base class.

_checkContainer

protected void _checkContainer(NamedObj container)
                        throws IllegalActionException
Check that the specified container is of a suitable class for this attribute. In this base class, this method returns immediately without doing anything.

Parameters:
container - The proposed container.
Throws:
IllegalActionException - If the container is not of an acceptable class. Not thrown in this base class.

_getContainedObject

protected NamedObj _getContainedObject(NamedObj container,
                                       java.lang.String relativeName)
                                throws IllegalActionException
Get an attribute with the specified name in the specified container. The type of object sought is an instance of the same class as this object. The returned object is assured of being an instance of the same class as this object.

Overrides:
_getContainedObject in class NamedObj
Parameters:
relativeName - The name relative to the container.
container - The container expected to contain the object.
Returns:
An object of the same class as this object, or null if there is none.
Throws:
IllegalActionException - If the object exists and has the wrong class.

_propagateExistence

protected NamedObj _propagateExistence(NamedObj container)
                                throws IllegalActionException
Propagate existence of this object to the specified object. This overrides the base class to set the container.

Overrides:
_propagateExistence in class NamedObj
Parameters:
container - Object to contain the new object.
Returns:
A new object of the same class and name as this one.
Throws:
IllegalActionException - If the object cannot be cloned.