|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.kernel.CompositeEntity
public class CompositeEntity
A CompositeEntity is a cluster in a clustered graph. I.e., it is a non-atomic entity, in that it can contain other entities and relations. It supports transparent ports, where, in effect, the port of a contained entity is represented by a port of this entity. Methods that "deeply" traverse the topology see right through transparent ports. It may be opaque, in which case its ports are opaque and methods that "deeply" traverse the topology do not see through them. For instance, deepEntityList() returns the opaque entities directly or indirectly contained by this entity.
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) |
Nested Class Summary | |
---|---|
protected class |
CompositeEntity.ContainedObjectsIterator
This class is an iterator over all the contained objects (all instances of NamedObj). |
private static class |
CompositeEntity.CountComparator
A comparator for a |
private static class |
CompositeEntity.LinkRecord
A data structure for level-crossing links. |
Field Summary | |
---|---|
private java.util.List |
_classDefinitionListCache
Cache of class definition list. |
private long |
_classDefinitionListVersion
Workspace version for cache. |
(package private) NamedList |
_containedEntities
List of contained entities. |
(package private) NamedList |
_containedRelations
|
private java.util.List<DecoratedAttributes> |
_decoratedAttributesToStoreAtThisLevel
Decorated attributes within this composite for which this composite is responsible. |
private static java.lang.String |
_defaultIcon
The default value icon. |
private java.util.List |
_entityListCache
Cache of entity list. |
private long |
_entityListVersion
Workspace version for cache. |
private boolean |
_levelCrossingConnectAllowed
|
protected java.util.List<CompositeEntity.LinkRecord> |
_levelCrossingLinks
Level-crossing links within this composite for which this composite is responsible. |
Fields inherited from class ptolemy.kernel.Entity |
---|
_portList |
Fields inherited from class ptolemy.kernel.util.NamedObj |
---|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Constructor Summary | |
---|---|
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. |
Method Summary | ||
---|---|---|
private static
|
_addAll(java.util.Set<T> result,
java.util.Collection<?> sourceList)
Add all elements from the sourceList into the targetList. |
|
protected void |
_addEntity(ComponentEntity entity)
Add an entity or class definition to this container. |
|
private void |
_addIcon()
Add a default icon description. |
|
protected void |
_addRelation(ComponentRelation relation)
Add a relation to this container. |
|
protected void |
_adjustDeferrals()
Adjust the deferrals in this object. |
|
private NamedObj |
_commonContainer(NamedObj object1,
NamedObj object2)
Find the least common container of the two objects. |
|
private boolean |
_commonImplier(NamedObj object1,
int depth1,
NamedObj object2,
int depth2)
Return true if the two specified objects are both derived, it is the same container above them whose parent-child relationship makes them derived, or if one of the containers contains the other, and those containers are no more than depth1 and depth2 above them, respectively. |
|
protected void |
_deepOpaqueEntityList(java.util.List result)
List the opaque entities that are directly or indirectly contained by this entity. |
|
private int |
_depthInside(NamedObj containee)
Return the depth of specified object inside this. |
|
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 |
_recordDecoratedAttributes(DecoratedAttributes attributes)
Record decorated attributes to store at the level of the container of the decorator. |
|
private void |
_recordLevelCrossingLink(Port port,
Relation relation1,
Relation relation2,
int index)
Record a level-crossing link with the least common container if there is such a least common container and if that least common container is currently exporting MoML. |
|
protected void |
_removeEntity(ComponentEntity entity)
Remove the specified entity. |
|
protected void |
_removeRelation(ComponentRelation relation)
Remove the specified relation. |
|
private void |
_unlinkLevelCrossingLinksToOutside(CompositeEntity entity)
Remove all level-crossing links from relations contained by the specified entity to ports or relations outside this composite entity, and from ports contained by entities contained by the specified entity to relations outside this composite entity. |
|
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. |
|
java.util.List |
allCompositeEntityList()
Return a list that consists of all the non-opaque composite 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 |
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 |
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). |
|
java.util.List |
entityList(java.lang.Class 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 |
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. |
Methods inherited from class ptolemy.kernel.ComponentEntity |
---|
_addPort, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, newPort, propagateExistence, setName |
Methods inherited from class ptolemy.kernel.Entity |
---|
_removePort, connectedPortList, connectedPorts, connectionsChanged, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts |
Methods inherited from class ptolemy.kernel.InstantiableNamedObj |
---|
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ptolemy.kernel.util.Derivable |
---|
getDerivedLevel, getDerivedList, propagateValue |
Methods inherited from interface ptolemy.kernel.util.Nameable |
---|
description, getDisplayName, getFullName, getName, getName |
Field Detail |
---|
protected java.util.List<CompositeEntity.LinkRecord> _levelCrossingLinks
NamedList _containedEntities
NamedList _containedRelations
private transient java.util.List _classDefinitionListCache
private transient long _classDefinitionListVersion
private java.util.List<DecoratedAttributes> _decoratedAttributesToStoreAtThisLevel
private static java.lang.String _defaultIcon
private transient java.util.List _entityListCache
private transient long _entityListVersion
private boolean _levelCrossingConnectAllowed
Constructor Detail |
---|
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.Method Detail |
---|
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 java.util.List allCompositeEntityList()
deepEntityList()
in that this method
returns only CompositeEntities, whereas deepEntityList()
returns ComponentEntities. The returned list of this method
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 deepOpaqueEntityList()
classDefinitionList()
,
allAtomicEntityList()
public java.util.List deepEntityList()
classDefinitionList()
,
allAtomicEntityList()
public java.util.Set<ComponentRelation> deepRelationSet()
public java.util.Enumeration deepGetEntities()
public java.util.List entityList()
classDefinitionList()
public java.util.List entityList(java.lang.Class filter)
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.
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)
getPort
in class Entity
name
- The name of the desired port.
public ComponentRelation getRelation(java.lang.String name)
name
- The name of the desired relation.
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 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.public int numEntities()
numberOfEntities()
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 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
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 _recordDecoratedAttributes(DecoratedAttributes attributes)
_recordDecoratedAttributes
in class NamedObj
attributes
- The decorated attributes.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)
private static <T> void _addAll(java.util.Set<T> result, java.util.Collection<?> sourceList)
private void _addIcon()
private NamedObj _commonContainer(NamedObj object1, NamedObj object2)
object1
- The first object.object2
- The second object.
private boolean _commonImplier(NamedObj object1, int depth1, NamedObj object2, int depth2)
object1
- The first object.depth1
- The depth of the first object.object2
- The second object.depth2
- The depth of the second object.
private int _depthInside(NamedObj containee)
containee
- The object contained.
private void _recordLevelCrossingLink(Port port, Relation relation1, Relation relation2, int index)
port
- The port, or null for a link between relations.relation1
- The first relation.relation2
- The second relation.index
- The index of the link.private void _unlinkLevelCrossingLinksToOutside(CompositeEntity entity)
entity
- The entity in which to look for relations or
(if it is an instance of CompositeEntity), entities with ports.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |