public class InstantiableNamedObj extends NamedObj implements Instantiable
Instantiable
interface.
Note that the instantiate(NamedObj, String)
permits instantiating
an object into a workspace that is different from the one associated with
this object. This means that some care must be exercised when propagating
changes from a parent to a child, since they may be in different workspaces.
Suppose for example that the change that has to propagate is made via a
change request. Although it may be a safe time to execute a change request
in the parent, it is not necessarily a safe time to execute a change request
in the child. Classes that restrict these safe times should override
the propagateExistence(), propagateValue(), and propagateValues() methods
to ensure that the destinations of the propagation are in a state that
they can accept changes.
Instantiable
NamedObj.ContainedObjectsIterator
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
InstantiableNamedObj()
Construct an object in the default workspace with an empty string
as its name.
|
InstantiableNamedObj(java.lang.String name)
Construct an object in the default workspace with the given name.
|
InstantiableNamedObj(Workspace workspace)
Construct an object in the given workspace with an empty string
as a name.
|
InstantiableNamedObj(Workspace workspace,
java.lang.String name)
Construct an object in the given workspace with the given name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_setParent(Instantiable parent)
Specify the parent for this object.
|
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace.
|
void |
exportMoML(java.io.Writer output,
int depth,
java.lang.String name)
Write a MoML description of this object with the specified
indentation depth and with the specified name substituting
for the name of this object.
|
java.util.List |
getChildren()
Get a list of weak references to instances of Instantiable
that are children of this object.
|
java.lang.String |
getElementName()
Get the MoML element name.
|
Instantiable |
getParent()
Return the parent of this object, or null if there is none.
|
java.util.List |
getPrototypeList()
Return a list of prototypes for this object.
|
Instantiable |
instantiate(NamedObj container,
java.lang.String name)
Create an instance by (deeply) cloning this object and then adjusting
the parent-child relationships between the clone and its parent.
|
boolean |
isClassDefinition()
Return true if this object is a class definition, which means that
it can be instantiated.
|
boolean |
isWithinClassDefinition()
Return true if this object is a class definition or is within
a class definition, which means that
any container above it in the hierarchy is
a class definition.
|
void |
setClassDefinition(boolean isClass)
Specify whether this object is a class definition.
|
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _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, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDerivedLevel, getDerivedList, propagateExistence, propagateValue
description, getContainer, getDisplayName, getFullName, getName, getName, setName
public InstantiableNamedObj()
public InstantiableNamedObj(java.lang.String name) throws IllegalActionException
name
- The name of this object.IllegalActionException
- If the name has a period.public InstantiableNamedObj(Workspace workspace)
workspace
- The workspace for synchronization and version tracking.public InstantiableNamedObj(Workspace workspace, java.lang.String name) throws IllegalActionException
workspace
- The workspace for synchronization and version tracking.name
- The name of this object.IllegalActionException
- If the name has a period.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class NamedObj
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- If one of the attributes
cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void exportMoML(java.io.Writer output, int depth, java.lang.String name) throws java.io.IOException
<class name="name" extends="classname source="source"> body, determined by _exportMoMLContents() </class>Otherwise, the exported MoML is that generated by the superclass method that this overrides.
If this object has no container and the depth argument is zero, then this method prepends XML file header information, which is:
<?xml version="1.0" standalone="no"?> <!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd">In the above, "entity" may be replaced by "property" or "port" if what is being exported is an attribute or a port.
The text that is written is indented according to the specified depth, with each line (including the last one) terminated with a newline. Derived classes can override this method to change the MoML description of an object. They can override the protected method _exportMoMLContents() if they need to only change which contents are described.
If this object is not persistent, or if there is no MoML description of this object, or if this object is implied by a parent-child relationship that less than depth levels up in the containment hierarchy and it has not been overridden, then write nothing.
exportMoML
in interface MoMLExportable
exportMoML
in class NamedObj
output
- The output stream to write to.depth
- The depth in the hierarchy, to determine indenting.name
- The name to use in the exported MoML.java.io.IOException
- If an I/O error occurs.MoMLExportable
public java.util.List getChildren()
getChildren
in interface Instantiable
Instantiable
,
WeakReference
public java.lang.String getElementName()
getElementName
in interface MoMLExportable
getElementName
in class NamedObj
MoMLExportable
public Instantiable getParent()
getParent
in interface Instantiable
_setParent(Instantiable)
,
Instantiable
public java.util.List getPrototypeList() throws IllegalActionException
getPrototypeList
in interface Derivable
getPrototypeList
in class NamedObj
IllegalActionException
- If a prototype with the right
name but the wrong class is found.Derivable
public Instantiable instantiate(NamedObj container, java.lang.String name) throws java.lang.CloneNotSupportedException, IllegalActionException, NameDuplicationException
The new object is not a class definition by default (it is an
"instance" rather than a "class"). To make it a class
definition (a "subclass"), call setClassDefinition(boolean)
with a true argument.
In this base class, the container argument is ignored except that it provides the workspace into which to clone this object. Derived classes with setContainer() methods are responsible for overriding this and calling setContainer().
Note that the workspace for the instantiated object can be different from the workspace for this object. This means that propagation of changes from a parent to a child may not be able to be safely performed in the child even when they are safely performed in the parent. Subclasses that restrict when changes are performed are therefore required to check whether the workspaces are the same before propagating changes.
instantiate
in interface Instantiable
container
- The container for the instance, or null
to instantiate it at the top level. Note that this base class
does not set the container. It uses the container argument to
get the workspace. Derived classes are responsible for
setting the container.name
- The name for the instance.java.lang.CloneNotSupportedException
- If this object
cannot be cloned.IllegalActionException
- If this object is not a
class definition or the proposed container is not acceptable.NameDuplicationException
- If the name collides with
an object already in the container.setClassDefinition(boolean)
,
Instantiable
public final boolean isClassDefinition()
isClassDefinition
in interface Instantiable
setClassDefinition(boolean)
,
Instantiable
public final boolean isWithinClassDefinition()
setClassDefinition(boolean)
,
Instantiable
public void setClassDefinition(boolean isClass) throws IllegalActionException
isClass
- True to make this object a class definition, false
to make it an instance.IllegalActionException
- If there are subclasses and/or
instances and the argument is false.isClassDefinition()
,
Instantiable
protected void _setParent(Instantiable parent) throws IllegalActionException
instantiate(NamedObj, String)
method. This method is write synchronized on
the workspace because it modifies the object that is the
argument to refer back to this one.
Note that a parent references a child via a weak reference. This means that the parent will not prevent the child from being garbage collected. However, as long as the child has not been garbage collected, changes to the parent will propagate to the child even if there are no other live references to the child. If there are a large number of such dangling children, this could create performance problems when making changes to the parent.
parent
- The parent, or null to specify that there is
no parent.IllegalActionException
- If the parent is not an
instance of InstantiableNamedObj.NamedObj.exportMoML(Writer, int)
,
getParent()
,
Instantiable