|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| 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). |
| Field Summary |
|---|
| 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 | |
|---|---|
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.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. |
java.util.List |
allCompositeEntityList()
Return a list that consists of all the 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 |
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. |
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. |
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 it has. |
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, exportMoML, 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 |
| 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 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 ComponentEntityworkspace - 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
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 Entitypublic java.util.List deepEntityList()
classDefinitionList(),
allAtomicEntityList()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 Attribute getAttribute(java.lang.String name)
getAttribute in class Entityname - 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 Entityname - 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 ComponentEntityCompositeEntitypublic boolean isOpaque()
isOpaque in class ComponentEntityCompositeEntity
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 EntityisClass - 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 ComponentEntitycontainer - 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)
uniqueName in class Entityprefix - 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 ComponentEntityIllegalActionException - If the class found in scope
cannot be set.
protected java.lang.String _description(int detail,
int indent,
int bracket)
_description in class Entitydetail - The level of detail.indent - The amount of indenting.bracket - The number of surrounding brackets (0, 1, or 2).
protected void _exportMoMLContents(java.io.Writer output,
int depth)
throws java.io.IOException
_exportMoMLContents in class Entityoutput - 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 EntityattributesValidated - 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)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||