ptolemy.actor
Class TypedCompositeActor

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.kernel.CompositeEntity
                      extended by ptolemy.actor.CompositeActor
                          extended by ptolemy.actor.TypedCompositeActor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
ActorRecursion, CompiledCompositeActor, CompiledCompositeActor, CompositeActorMatcher, ContinuousTransferFunction, ContinuousTransferFunction, CTCompositeActor, CTCompositeActor, DifferentialSystem, DifferentialSystem, DistributedTypedCompositeActor, EnabledComposite, LazyTypedCompositeActor, LifeCycleManager, LinearStateSpace, LinearStateSpace, MirrorComposite, MirrorComposite.MirrorCompositeContents, MobileModel, ModalModel, ModelExecutor.Wrapper, MultiCompositeActor, MultiInstanceComposite, NondeterministicMerge, PetriNetActor, PtalonActor, PtalonMatcher, Refinement, Refinement, Region, SMVLegacyCodeActor, TDLTask, TMCompositeFacade, WirelessComposite

public class TypedCompositeActor
extends CompositeActor
implements TypedActor

A TypedCompositeActor is an aggregation of typed actors.

When exporting MoML, instances of this class identify their class name as TypedCompositeActor. If a derived class does not change this, then it too will be identified as a TypedCompositeActor. To change this in a derived class, put the following line in the constructor

 setClassName(full class name");
 
If you do this, you will probably also want to override _exportMoMLContents() to not generate a description of the contents of the composite, since they will be already defined in the Java class.

The ports of a TypedCompositeActor are constrained to be TypedIOPorts, the relations to be TypedIORelations, and the actors to be instances of ComponentEntity that implement the TypedActor interface. Derived classes may impose further constraints by overriding newPort(), _addPort(), newRelation(), _addRelation(), and _addEntity(). Also, derived classes may constrain the container by overriding _checkContainer().

Since:
Ptolemy II 0.2
Version:
$Id: TypedCompositeActor.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Yuhong Xiong
See Also:
TypedIOPort, TypedIORelation, TypedActor, ComponentEntity, CompositeActor, Serialized Form
Accepted Rating:
Green (lmuliadi)
Proposed Rating:
Green (yuhong)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _initializables, _notifyingActorFiring, _publishedPorts, _publisherRelations, _stopRequested
 
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
TypedCompositeActor()
          Construct a TypedCompositeActor in the default workspace with no container and an empty string as its name.
TypedCompositeActor(CompositeEntity container, java.lang.String name)
          Construct a TypedCompositeActor with a name and a container.
TypedCompositeActor(Workspace workspace)
          Construct a TypedCompositeActor in the specified workspace with no container and an empty string as a name.
 
Method Summary
protected  void _addEntity(ComponentEntity entity)
          Add an actor to this container with minimal error checking.
protected  void _addPort(Port port)
          Add a port to this actor.
protected  void _addRelation(ComponentRelation relation)
          Add a relation to this container.
private  java.util.List _checkDeclaredTypes()
           
protected  java.util.List _checkTypesFromTo(TypedIOPort sourcePort, java.util.List destinationPortList)
          Check types from a source port to a group of destination ports, assuming the source port is connected to all the ports in the group of destination ports.
private  java.util.List _receiverToPort(Receiver[][] receivers)
           
protected  java.util.List _typeConstraintsFromTo(TypedIOPort sourcePort, java.util.List destinationPortList)
          Return the type constraints on all connections starting from the specified source port to all the ports in a group of destination ports.
 Port newPort(java.lang.String name)
          Create a new TypedIOPort with the specified name.
 ComponentRelation newRelation(java.lang.String name)
          Create a new TypedIORelation with the specified name, add it to the relation list, and return it.
static void resolveTypes(TypedCompositeActor topLevel)
          Do type checking and type resolution on the specified composite actor.
 java.util.List typeConstraintList()
          Deprecated. Use typeConstraints().
 java.util.Set<Inequality> typeConstraints()
          Return the type constraints of this typed composite actor.
 
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _getPublishedPort, _setDirector, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, createReceivers, createSchedule, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isOpaque, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, wrapup
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _deepOpaqueEntityList, _description, _exportMoMLContents, _recordDecoratedAttributes, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allCompositeEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepEntityList, deepGetEntities, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Constructor Detail

TypedCompositeActor

public TypedCompositeActor()
Construct a TypedCompositeActor in the default workspace with no container and an empty string as its name. Add the actor to the workspace directory. You should set the local director or executive director before attempting to send data to the actor or to execute it. Increment the version number of the workspace.


TypedCompositeActor

public TypedCompositeActor(Workspace workspace)
Construct a TypedCompositeActor in the specified workspace with no container and 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. You should set the local director or executive director before attempting to send data to the actor or to execute it. Add the actor to the workspace directory. Increment the version number of the workspace.

Parameters:
workspace - The workspace that will list the actor.

TypedCompositeActor

public TypedCompositeActor(CompositeEntity container,
                           java.lang.String name)
                    throws IllegalActionException,
                           NameDuplicationException
Construct a TypedCompositeActor with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor 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. This actor will have no local director initially, and its executive director will be simply the director of the container.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the container is incompatible with this actor.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

newPort

public Port newPort(java.lang.String name)
             throws NameDuplicationException
Create a new TypedIOPort with the specified name. The container of the port is set to this actor. This method is write-synchronized on the workspace.

Overrides:
newPort in class CompositeActor
Parameters:
name - The name for the new port.
Returns:
A new TypedIOPort.
Throws:
NameDuplicationException - If this actor already has a port with the specified name.

newRelation

public ComponentRelation newRelation(java.lang.String name)
                              throws NameDuplicationException
Create a new TypedIORelation with the specified name, add it to the relation list, and return it. Derived classes can override this to create domain-specific subclasses of TypedIORelation. This method is write-synchronized on the workspace.

Overrides:
newRelation in class CompositeActor
Parameters:
name - The name for the new TypedIORelation.
Returns:
A new TypedIORelation.
Throws:
NameDuplicationException - If name collides with a name already on the container's contents list.

resolveTypes

public static void resolveTypes(TypedCompositeActor topLevel)
                         throws TypeConflictException
Do type checking and type resolution on the specified composite actor. The specified actor must be the top level container of the model.

Parameters:
topLevel - The top level TypedCompositeActor.
Throws:
java.lang.IllegalArgumentException - If the specified actor is not the top level container. That is, its container is not null.
TypeConflictException - If a type conflict is detected.

typeConstraints

public java.util.Set<Inequality> typeConstraints()
                                          throws IllegalActionException
Return the type constraints of this typed composite actor. The constraints have the form of a set of inequalities. The constraints come from three sources, the contained actors, the contained Typeables, and (for opaque actors) the topology of connections between actors. To generate the constraints based on the topology, this method scans all the connections within this composite between opaque TypedIOPorts. If the type of the ports on one or both ends of a connection is not declared, a type constraint is formed that requires the type of the port at the source end of the connection to be less than or equal to the type at the destination port. To collect the type constraints from the contained actors, This method recursively calls the typeConstraints() method of the contained actors and combine all the constraints together. The type constraints from contained Typeables (ports and parameters) are collected by calling the typeConstraints() method of all the contained Typeables.

This method is read-synchronized on the workspace.

Specified by:
typeConstraints in interface TypedActor
Returns:
a list of instances of Inequality.
Throws:
IllegalActionException - If the typeConstraints of one of the deeply contained objects throws it.
See Also:
Inequality

typeConstraintList

public java.util.List typeConstraintList()
                                  throws IllegalActionException
Deprecated. Use typeConstraints().

Return the type constraints of this variable. The constraints include the ones explicitly set to this variable, plus the constraint that the type of this variable must be no less than its current type, if it has one. The constraints are a list of inequalities.

Returns:
a list of Inequality objects.
Throws:
IllegalActionException - If thrown while constructing the set of type constraints.
See Also:
Inequality

_addEntity

protected void _addEntity(ComponentEntity entity)
                   throws IllegalActionException,
                          NameDuplicationException
Add an actor to this container with minimal error checking. This overrides the base-class method to make sure the argument implements the TypedActor interface. This method does not alter the actor in any way. It is not synchronized on the workspace, so the caller should be.

Overrides:
_addEntity in class CompositeActor
Parameters:
entity - TypedActor to contain.
Throws:
IllegalActionException - If the actor has no name, or the action would result in a recursive containment structure, or the argument does not implement the TypedActor interface.
NameDuplicationException - If the name collides with a name already on the actor contents list.

_addPort

protected void _addPort(Port port)
                 throws IllegalActionException,
                        NameDuplicationException
Add a port to this actor. This overrides the base class to throw an exception if the proposed port is not an instance of TypedIOPort. This method should not be used directly. Call the setContainer() method of the port instead. This method does not set the container of the port to point to this actor. It assumes that the port is in the same workspace as this actor, but does not check. The caller should check. This method is not synchronized on the workspace, so the caller should be.

Overrides:
_addPort in class CompositeActor
Parameters:
port - The TypedIOPort to add to this actor.
Throws:
IllegalActionException - If the port class is not acceptable to this actor, or the port has no name.
NameDuplicationException - If the port name collides with a name already in the actor.

_addRelation

protected void _addRelation(ComponentRelation relation)
                     throws IllegalActionException,
                            NameDuplicationException
Add a relation to this container. This overrides the base class to throw an exception if the proposed relation is not an instance of TypedIORelation. This method should not be used directly. Call the setContainer() method of the relation instead. This method does not set the container of the relation to refer to this container. This method is not synchronized on the workspace, so the caller should be.

Overrides:
_addRelation in class CompositeActor
Parameters:
relation - The TypedIORelation to contain.
Throws:
IllegalActionException - If the relation has no name, or is not an instance of TypedIORelation.
NameDuplicationException - If the name collides with a name already on the contained relations list.

_checkTypesFromTo

protected java.util.List _checkTypesFromTo(TypedIOPort sourcePort,
                                           java.util.List destinationPortList)
Check types from a source port to a group of destination ports, assuming the source port is connected to all the ports in the group of destination ports. Return a list of instances of Inequality that have type conflicts.

Parameters:
sourcePort - The source port.
destinationPortList - A list of destination ports.
Returns:
A list of instances of Inequality indicating the type constraints that are not satisfied.

_typeConstraintsFromTo

protected java.util.List _typeConstraintsFromTo(TypedIOPort sourcePort,
                                                java.util.List destinationPortList)
Return the type constraints on all connections starting from the specified source port to all the ports in a group of destination ports.

Parameters:
sourcePort - The source port.
destinationPortList - The destination port list.
Returns:
A list of instances of Inequality.

_checkDeclaredTypes

private java.util.List _checkDeclaredTypes()
                                    throws IllegalActionException
Throws:
IllegalActionException

_receiverToPort

private java.util.List _receiverToPort(Receiver[][] receivers)