ptolemy.kernel.util
Class Attribute

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.util.Attribute
All Implemented Interfaces:
Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable
Direct Known Subclasses:
AbstractSettableAttribute, ConfigurableAttribute, DependencyDeclaration, Director, DocumentationAttribute, EditorFactory, EditorIcon, EditorPaneFactory, GiottoCodeGenerator, ImageAttribute, ImportAttribute, MoMLAttribute, ParameterEditorStyle, RelationList, SchedulePlotter, Scheduler, ScopeExtendingAttribute, ShapeAttribute, SingletonAttribute, TableauFactory, TextAttribute, UnitCategory

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,v 1.63.2.1 2004/06/18 00:49:18 cxh Exp $
Author:
Edward A. Lee, Neil Smyth
See Also:
Serialized Form
Accepted Rating:
Green (johnr)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _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.
Attribute(Workspace workspace)
          Construct an attribute in the specified workspace with an empty string as a name.
 
Method Summary
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.
 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.
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

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.

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.

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.

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.getDerivedLevel()

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