public class CompositeEntity extends ComponentEntity
To add an entity or relation to this composite, call its setContainer() method with this composite as an argument. To remove it, call its setContainer() method with a null argument (or another container). The entity must be an instance of ComponentEntity and the relation of ComponentRelation or an exception is thrown. Derived classes may further constrain these to subclasses. To do that, they should override the protected methods _addEntity() and _addRelation() and the public member newRelation().
A CompositeEntity may be contained by another CompositeEntity. To set that up, call the setContainer() method of the inside entity. Derived classes may further constrain the container to be a subclass of CompositeEntity. To do this, they should override setContainer() to throw an exception. Recursive containment structures, where an entity directly or indirectly contains itself, are disallowed, and an exception is thrown on an attempt to set up such a structure.
A CompositeEntity can contain instances of ComponentPort. By default these ports will be transparent, although subclasses of CompositeEntity can make them opaque by overriding the isOpaque() method to return true. Derived classes may further constrain the ports to a subclass of ComponentPort. To do this, they should override the public method newPort() to create a port of the appropriate subclass, and the protected method _addPort() to throw an exception if its argument is a port that is not of the appropriate subclass.
Since contained entities implement the
Instantiable
interface,
some may be class definitions. If an entity is a class definition,
then it is not included in the lists returned by
entityList()
, entityList(Class)
,
deepEntityList()
, and allAtomicEntityList()
.
Correspondingly, if it is not a class definition, then it is not
included in the list returned by classDefinitionList()
.
Contained class definitions are nonetheless required to have names
distinct from contained entities that are not class definitions,
and the method getEntity(String)
will return either
a class definition or an entity that is not a class definition,
as long as the name matches. Note that contained entities that
are class definitions cannot be connected to other entities.
Moreover, they cannot be deleted as long as there are either
subclasses or instances present.
Green (hyzheng) |
Green (eal) |
Modifier and Type | Class and Description |
---|---|
protected class |
CompositeEntity.ContainedObjectsIterator
This class is an iterator over all the contained objects
(all instances of NamedObj).
|
Modifier and Type | Field and Description |
---|---|
(package private) NamedList |
_containedEntities
List of contained entities.
|
(package private) NamedList |
_containedRelations |
protected java.util.List<ptolemy.kernel.CompositeEntity.LinkRecord> |
_levelCrossingLinks
Level-crossing links within this composite for which this composite
is responsible.
|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
CompositeEntity()
Construct an entity in the default workspace with an empty string
as its name.
|
CompositeEntity(CompositeEntity container,
java.lang.String name)
Create an object with a name and a container.
|
CompositeEntity(Workspace workspace)
Construct an entity in the specified workspace with an empty
string as a name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_addEntity(ComponentEntity entity)
Add an entity or class definition to this container.
|
protected void |
_addRelation(ComponentRelation relation)
Add a relation to this container.
|
protected void |
_adjustDeferrals()
Adjust the deferrals in this object.
|
protected java.util.List<Decorator> |
_containedDecorators()
Return a list of decorators contained by this object.
|
protected void |
_deepOpaqueEntityList(java.util.List result)
List the opaque entities that are directly or indirectly
contained by this entity.
|
protected java.lang.String |
_description(int detail,
int indent,
int bracket)
Return a description of the object.
|
protected void |
_exportMoMLContents(java.io.Writer output,
int depth)
Write a MoML description of the contents of this object, which
in this class are the attributes, ports, contained relations,
and contained entities, plus all links.
|
protected void |
_finishedAddEntity(ComponentEntity entity)
Notify this entity that the given entity has been added inside it.
|
protected void |
_removeEntity(ComponentEntity entity)
Remove the specified entity.
|
protected void |
_removeRelation(ComponentRelation relation)
Remove the specified relation.
|
protected void |
_validateSettables(java.util.Collection attributesValidated)
Validate attributes deeply contained by this object if they
implement the Settable interface by calling their validate() method.
|
java.util.List |
allAtomicEntityList()
Return a list that consists of all the atomic entities in a model.
|
void |
allowLevelCrossingConnect(boolean boole)
Allow or disallow connections that are created using the connect()
method to cross levels of the hierarchy.
|
java.util.List |
classDefinitionList()
List the contained class definitions
in the order they were added
(using their setContainer() method).
|
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace.
|
ComponentRelation |
connect(ComponentPort port1,
ComponentPort port2)
Create a new relation and use it to connect two ports.
|
ComponentRelation |
connect(ComponentPort port1,
ComponentPort port2,
java.lang.String relationName)
Create a new relation with the specified name and use it to
connect two ports.
|
java.util.Iterator |
containedObjectsIterator()
Return an iterator over contained objects.
|
java.util.List<CompositeEntity> |
deepCompositeEntityList()
Return a list that consists of all the transparent and opaque
composite entities in a model.
|
java.util.List |
deepEntityList()
List the opaque entities that are directly or indirectly
contained by this entity.
|
java.util.Enumeration |
deepGetEntities()
Deprecated.
Use deepEntityList() instead.
|
java.util.List |
deepNamedObjList()
List the NamedObjs that are directly or indirectly
contained by this entity.
|
java.util.List |
deepOpaqueEntityList()
List the opaque entities that are directly or indirectly
contained by this entity.
|
java.util.Set<ComponentRelation> |
deepRelationSet()
Return a set with the relations that are directly or indirectly
contained by this entity.
|
java.util.List |
entityList()
List the contained entities in the order they were added
(using their setContainer() method).
|
<T> java.util.List<T> |
entityList(java.lang.Class<T> filter)
Return a list of the component entities contained by this object that
are instances of the specified Java class.
|
java.lang.String |
exportLinks(int depth,
java.util.Collection filter)
Return a sequence of MoML link attributes that describe
any link between objects (ports, entities, and relations) that are
present in the filter argument.
|
void |
exportMoML(java.io.Writer output,
int depth,
java.lang.String name)
Override the base class to initialize a data structure that can
capture and then export level-crossing links deeply contained
structure within.
|
Attribute |
getAttribute(java.lang.String name)
Get the attribute with the given name.
|
java.util.Enumeration |
getEntities()
Deprecated.
Use entityList() instead.
|
ComponentEntity |
getEntity(java.lang.String name)
Get a contained entity by name.
|
Port |
getPort(java.lang.String name)
Get a contained port by name.
|
ComponentRelation |
getRelation(java.lang.String name)
Get a contained relation by name.
|
java.util.Enumeration |
getRelations()
Deprecated.
Use relationList() instead.
|
boolean |
isAtomic()
Return false since CompositeEntities are not atomic.
|
boolean |
isOpaque()
Return false.
|
java.util.List |
lazyAllAtomicEntityList()
Lazy version of
allAtomicEntityList() . |
java.util.List |
lazyAllCompositeEntityList()
Lazy version of {#link #allCompositeEntityList()}.
|
java.util.List |
lazyAllCompositeTransparentAndOpaqueEntityList()
Return all the transparent and opaque composites.
|
java.util.List |
lazyClassDefinitionList()
Lazy version of
classDefinitionList() . |
java.util.List |
lazyDeepEntityList()
Lazy version of
deepEntityList() . |
java.util.List |
lazyEntityList()
Lazy version of
entityList() . |
java.util.List |
lazyRelationList()
Lazy version of
relationList() . |
ComponentRelation |
newRelation(java.lang.String name)
Create a new relation with the specified name, add it to the
relation list, and return it.
|
int |
numberOfEntities()
Return the number of contained entities, not including
class definitions.
|
int |
numberOfRelations()
Return the number of contained relations.
|
int |
numEntities()
Deprecated.
Use numberOfEntities
|
int |
numRelations()
Deprecated.
Use numberOfRelations.
|
java.util.List |
relationList()
List the relations contained by this entity.
|
void |
removeAllEntities()
Remove all contained entities and unlink them from all relations.
|
void |
removeAllRelations()
Remove all contained relations and unlink them from everything.
|
void |
setClassDefinition(boolean isClass)
Specify whether this object is a class definition.
|
void |
setContainer(CompositeEntity container)
Override the base class so that if the argument is null, all
level-crossing links from inside this composite to outside this
composite are removed.
|
java.lang.String |
statistics(java.lang.String className)
Return a string describing how many actors, parameters,
ports, and relations are in this CompositeEntity.
|
java.lang.String |
uniqueName(java.lang.String prefix)
Return a name that is guaranteed to not be the name of
any contained attribute, port, class, entity, or relation.
|
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, newPort, propagateExistence, setName
_addPort, _removePort, connectedPortList, connectedPorts, connectionsChanged, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDerivedLevel, getDerivedList, propagateValue
description, getDisplayName, getFullName, getName, getName
protected java.util.List<ptolemy.kernel.CompositeEntity.LinkRecord> _levelCrossingLinks
NamedList _containedEntities
NamedList _containedRelations
public CompositeEntity()
public CompositeEntity(Workspace workspace)
workspace
- The workspace that will list the entity.public CompositeEntity(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container entity.name
- The name of the entity.IllegalActionException
- If the container is incompatible
with this entity.NameDuplicationException
- If the name coincides with
an entity already in the container.public java.util.List allAtomicEntityList()
deepEntityList()
in that
this method looks inside opaque entities, whereas deepEntityList()
does not. The returned list does not include any entities that
are class definitions.public void allowLevelCrossingConnect(boolean boole)
boole
- True to allow level-crossing connections.public java.util.List classDefinitionList()
entityList()
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class ComponentEntity
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 ComponentRelation connect(ComponentPort port1, ComponentPort port2) throws IllegalActionException
Note that if this method is being called many times, then
it may be more efficient to use
connect(ComponentPort, ComponentPort, String)
instead of this method because this method calls
uniqueName(String)
each time, which
searches the object for attributes, ports, entities and relations
that may match a candidate unique name.
port1
- The first port to connect.port2
- The second port to connect.IllegalActionException
- If one of the arguments is null, or
if a disallowed level-crossing connection would result.public ComponentRelation connect(ComponentPort port1, ComponentPort port2, java.lang.String relationName) throws IllegalActionException, NameDuplicationException
port1
- The first port to connect.port2
- The second port to connect.relationName
- The name of the new relation.IllegalActionException
- If one of the arguments is null, or
if a disallowed level-crossing connection would result, or if the two
ports are not in the same workspace as this entity.NameDuplicationException
- If there is already a relation with
the specified name in this entity.public java.util.Iterator containedObjectsIterator()
containedObjectsIterator
in class Entity
public java.util.List<CompositeEntity> deepCompositeEntityList()
allAtomicEntityList()
in that this method returns
CompositeEntities and allAtomicEntityList() returns atomic
entities. This method differs from deepEntityList()
in that this method returns only opaque and transparent
CompositeEntities, whereas deepEntityList() returns opaque
ComponentEntities. The returned list of this method does not
include any entities that are class definitions.
The entityList(Class)
method only returns entities in the
current level, this method traverses the hierarchy.public java.util.List deepOpaqueEntityList()
classDefinitionList()
,
allAtomicEntityList()
public java.util.List deepEntityList()
classDefinitionList()
,
allAtomicEntityList()
public java.util.List deepNamedObjList()
classDefinitionList()
,
allAtomicEntityList()
public java.util.Set<ComponentRelation> deepRelationSet()
@Deprecated public java.util.Enumeration deepGetEntities()
public java.util.List entityList()
classDefinitionList()
public <T> java.util.List<T> entityList(java.lang.Class<T> filter)
T
- The type corresponding to the class of interest.filter
- The class of ComponentEntity of interest.classDefinitionList()
public java.lang.String exportLinks(int depth, java.util.Collection filter) throws java.io.IOException
If the filter argument is null, then return all the links that this composite is responsible for (i.e., apply no filtering). If the argument is an empty collection, then return none of the links. The links that this entity is responsible for are the inside links of its ports, and links on ports contained by contained entities.
If any link is found where both ends of the link are inherited objects, then that link is not exported. It is assumed that the base class will export that link. For this purpose, a port of a contained entity is deemed to be an inherited object if it is itself a class element and its container is an inherited object.
depth
- The depth below the MoML export in the hierarchy.filter
- A collection of ports, parameters, and entities, or
null to apply no filtering.java.io.IOException
- If an I/O error occurs.public void exportMoML(java.io.Writer output, int depth, java.lang.String name) throws java.io.IOException
exportMoML
in interface MoMLExportable
exportMoML
in class InstantiableNamedObj
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 Attribute getAttribute(java.lang.String name)
getAttribute
in class Entity
name
- The name of the desired attribute.@Deprecated public java.util.Enumeration getEntities()
public ComponentEntity getEntity(java.lang.String name)
name
- The name of the desired entity.public Port getPort(java.lang.String name)
public ComponentRelation getRelation(java.lang.String name)
name
- The name of the desired relation.@Deprecated public java.util.Enumeration getRelations()
public final boolean isAtomic()
isAtomic
in class ComponentEntity
CompositeEntity
public boolean isOpaque()
isOpaque
in class ComponentEntity
CompositeEntity
public java.util.List lazyAllAtomicEntityList()
allAtomicEntityList()
.
In this base class, this is identical to allAtomicEntityList(),
except that if any inside entities are lazy, their contents
are listed lazily. Derived classes may omit from the returned list any
entities whose instantiation is deferred.public java.util.List lazyAllCompositeEntityList()
public java.util.List lazyAllCompositeTransparentAndOpaqueEntityList()
public java.util.List lazyClassDefinitionList()
classDefinitionList()
.
In this base class, this is identical to classDefinitionList(),
but derived classes may omit from the returned list any class
definitions whose instantiation is deferred.public java.util.List lazyDeepEntityList()
deepEntityList()
.
In this base class, this is identical to deepEntityList(),
except that if any contained composite is lazy, its contents
are listed lazily.
Derived classes may omit from the returned list any entities
whose instantiation is deferred.public java.util.List lazyEntityList()
entityList()
.
In this base class, this is identical to entityList(),
but derived classes may omit from the returned list any
entities whose instantiation is deferred.public java.util.List lazyRelationList()
relationList()
.
In this base class, this is identical to relationList(),
but derived classes may omit from the returned list any
relations whose instantiation is deferred.public ComponentRelation newRelation(java.lang.String name) throws IllegalActionException, NameDuplicationException
name
- The name of the new relation.IllegalActionException
- If name argument is null.NameDuplicationException
- If name collides with a name
already in the container.@Deprecated public int numEntities()
numberOfEntities()
@Deprecated public int numRelations()
public int numberOfEntities()
public int numberOfRelations()
public java.util.List relationList()
public void removeAllEntities()
public void removeAllRelations()
public void setClassDefinition(boolean isClass) throws IllegalActionException
setClassDefinition
in class Entity
isClass
- True to make this object a class definition.IllegalActionException
- If the argument is true and
this entity contains ports with links.InstantiableNamedObj.isClassDefinition()
,
Instantiable
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
setContainer
in class ComponentEntity
container
- The proposed container.IllegalActionException
- If the action would result in a
recursive containment structure, or if
this entity and container are not in the same workspace, or
if the protected method _checkContainer() throws it, or if
a contained Settable becomes invalid and the error handler
throws it.NameDuplicationException
- If the name of this entity
collides with a name already in the container.ComponentEntity.getContainer()
public java.lang.String statistics(java.lang.String className) throws IllegalActionException
className
- If non-null and non-empty, then also
include the number of objects with the give name.IllegalActionException
- If the class named by
actorClassName cannot be found.public java.lang.String uniqueName(java.lang.String prefix)
Note that this method should be called judiciously from when the CompositeEntity is large. The reason is that this method searches for matching attributes, ports, classes, entities and relations, which can result in slow performance.
uniqueName
in class Entity
prefix
- A prefix for the name.protected void _addEntity(ComponentEntity entity) throws IllegalActionException, NameDuplicationException
entity
- Entity to contain.IllegalActionException
- If the entity has no name, or the
action would result in a recursive containment structure.NameDuplicationException
- If the name collides with a name
already in the entity.protected void _addRelation(ComponentRelation relation) throws IllegalActionException, NameDuplicationException
relation
- Relation to contain.IllegalActionException
- If the relation has no name.NameDuplicationException
- If the name collides with a name
already on the contained relations list.protected void _adjustDeferrals() throws IllegalActionException
Derived classes that contain other objects should recursively call this method on contained objects.
_adjustDeferrals
in class ComponentEntity
IllegalActionException
- If the class found in scope
cannot be set.protected java.util.List<Decorator> _containedDecorators()
Decorator
interface, but also entities._containedDecorators
in class NamedObj
protected void _deepOpaqueEntityList(java.util.List result)
result
- The list of opaque ComponentEntity objects.classDefinitionList()
,
allAtomicEntityList()
,
deepEntityList()
protected java.lang.String _description(int detail, int indent, int bracket) throws IllegalActionException
_description
in class Entity
detail
- The level of detail.indent
- The amount of indenting.bracket
- The number of surrounding brackets (0, 1, or 2).IllegalActionException
- If thrown while getting the
description of subcomponents.protected void _exportMoMLContents(java.io.Writer output, int depth) throws java.io.IOException
_exportMoMLContents
in class Entity
output
- The output to write to.depth
- The depth in the hierarchy, to determine indenting.java.io.IOException
- If an I/O error occurs.NamedObj.exportMoML(Writer, int)
protected void _finishedAddEntity(ComponentEntity entity)
entity
- The contained entity.protected void _removeEntity(ComponentEntity entity)
entity
- The entity to remove.protected void _removeRelation(ComponentRelation relation)
relation
- The relation to remove.protected void _validateSettables(java.util.Collection attributesValidated) throws IllegalActionException
_validateSettables
in class Entity
attributesValidated
- A HashSet of Attributes that have
already been validated. For example, Settables that implement
the SharedSettable interface are validated only once.IllegalActionException
- If the superclass throws it
or if handleModelError() throws it.NamedObj.handleModelError(NamedObj, IllegalActionException)