Package ptolemy.actor.ptalon
Class PtalonActor
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Configurable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
PtalonMatcher.NestedPtalonActor
public class PtalonActor extends TypedCompositeActor implements Configurable
An aggregation of typed actors, specified by a Ptalon program.A TypedCompositeActor is an aggregation of typed actors. A PtalonActor is a TypedCompositeActor whose aggregation is specified by a Ptalon program in an external file. This file is loaded during initialization, and is specified in a FileParameter called ptalonCodeLocation.
- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Adam Cataldo, Elaine Cheong, Contributor: Christopher Brooks
- Pt.AcceptedRating:
- Yellow (celaine)
- Pt.ProposedRating:
- Yellow (celaine)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description FileParameter
ptalonCodeLocation
The location of the Ptalon code.-
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _derivedPiggybacks, _initializables, _notifyingActorFiring, _piggybacks, _publishedPorts, _publisherRelations, _stopRequested, _subscribedPorts
-
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description PtalonActor(CompositeEntity container, java.lang.String name)
Construct a PtalonActor with a name and a container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addAttribute(Attribute attribute)
Add the attribute, and if the attribute is a PtalonParameter, add it to a list of Ptalon parameters.protected PtalonEvaluator
_createPtalonEvaluator(PtalonActor actor)
protected PtalonPopulator
_createPtalonPopulator()
protected PtalonRecognizer
_createPtalonRecognizer(PtalonLexer lexer)
Create Ptalon parser.protected void
_exportMoMLContents(java.io.Writer output, int depth)
Write a MoML description of the contents of this object, which in this class is the configuration information.protected void
_initializePtalonActor()
Initialize this PtalonActor.protected void
_initializePtalonCodeLocation()
This helper method is used to begin the Ptalon compiler if the ptalonCodeLocation attribute has been updated.protected void
_removeContents()
void
attributeChanged(Attribute attribute)
React to a change in an attribute.void
configure(java.net.URL base, java.lang.String source, java.lang.String text)
Read the saved XML for this PtalonActor.java.lang.String
getConfigureSource()
Return the input source that was specified the last time the configure() method was called.java.lang.String
getConfigureText()
Override the default behavior to always return null.java.lang.String
getMappedName(java.lang.String ptalonName)
Get the stored unique name for a symbol in the PtalonActor.int
getNestedDepth()
Return the depth of this PtalonActor declaration with respect to its creator.PtalonParameter
getPtalonParameter(java.lang.String name)
Find the parameter in the Ptalon code with the specified name, and return the Ptolemy parameter (java) that was created.void
setNestedDepth(int depth)
Set the depth of this PtalonActor declaration with respect to its creator.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.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newPort, newRelation, resolveTypes, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, createReceivers, createSchedule, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort, wrapup
-
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics
-
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
_adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, 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, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
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
-
-
-
-
Field Detail
-
ptalonCodeLocation
public FileParameter ptalonCodeLocation
The location of the Ptalon code.
-
-
Constructor Detail
-
PtalonActor
public PtalonActor(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a PtalonActor 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
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
React to a change in an attribute. This method is called by a contained attribute when its value changes. This initially responds to changes in the ptalonCodeLocation parameter by calling a method which starts the parsing of the Ptalon code. Later, this method responds to changes in parameters specified in the Ptalon code itself: (1) If the parameter was not previously assigned, then update the internal variables; (2) If the parameter was previously assigned, then update the internal variables, and also update the rest of the PtalonActor based on the new value of the parameter (we currently choose the reparse and regenerate the entire PtalonActor from scratch).We choose to implement this in attributeChanged() instead if preinitialize() because we want changes to be reflected immediately, since preinitialize() is only processed after the model starts to run.
- Overrides:
attributeChanged
in classTypedCompositeActor
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container (not thrown in this base class).
-
configure
public void configure(java.net.URL base, java.lang.String source, java.lang.String text) throws java.lang.Exception
Read the saved XML for this PtalonActor.- Specified by:
configure
in interfaceConfigurable
- Parameters:
base
- The base relative to which references within the input are found, or null if this is not known, or there is none.source
- The input source, which specifies a URL, or null if none.text
- Configuration information given as text, or null if none.- Throws:
java.lang.Exception
- If something goes wrong.
-
getConfigureSource
public java.lang.String getConfigureSource()
Return the input source that was specified the last time the configure() method was called.- Specified by:
getConfigureSource
in interfaceConfigurable
- Returns:
- The string representation of the input URL, or null if the no source has been used to configure this object, or null if no external source need be used to configure this object.
-
getConfigureText
public java.lang.String getConfigureText()
Override the default behavior to always return null.- Specified by:
getConfigureText
in interfaceConfigurable
- Returns:
- null.
-
getMappedName
public java.lang.String getMappedName(java.lang.String ptalonName) throws PtalonRuntimeException
Get the stored unique name for a symbol in the PtalonActor. The unique name comes from a call to uniqueName().- Parameters:
ptalonName
- The symbol.- Returns:
- The unique name.
- Throws:
PtalonRuntimeException
- If no such symbol exists.
-
getNestedDepth
public int getNestedDepth()
Return the depth of this PtalonActor declaration with respect to its creator. If this PtalonActor is not created by another PtalonActor's code, then the depth is zero. If, however, this PtalonActor is named Bar in some PtalonCode, and it is created with Foo(actorparameter0 := Bar()), then its depth will be 2, and the corresponding Foo container will have depth 1.- Returns:
- The depth of this actor declaration with respect to its creator.
- See Also:
setNestedDepth(int)
-
getPtalonParameter
public PtalonParameter getPtalonParameter(java.lang.String name) throws PtalonRuntimeException
Find the parameter in the Ptalon code with the specified name, and return the Ptolemy parameter (java) that was created.- Parameters:
name
- The name of the parameter in the Ptalon code, which may be a prefix of the actual parameter's name.- Returns:
- The PtalonParameter.
- Throws:
PtalonRuntimeException
- If no such PtalonParameter exists.
-
setNestedDepth
public void setNestedDepth(int depth)
Set the depth of this PtalonActor declaration with respect to its creator. If this PtalonActor is not created by another PtalonActor's code, then the depth will be zero. If, however, this PtalonActor is named Bar in some PtalonCode, and it is created with Foo(actorparameter0 := Bar()), then it's depth will be 2, and the corresponding Foo container will have depth 1.- Parameters:
depth
- The of this actor declaration with respect to its creator.- See Also:
getNestedDepth()
-
uniqueName
public 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. In this implementation, the argument is stripped of any numeric suffix, and then a numeric suffix is appended and incremented until a name is found that does not conflict with a contained attribute, port, class, entity, or relation. If this composite entity or any composite entity that it contains defers its MoML definition (i.e., it is an instance of a class or a subclass), then the prefix gets appended with "_n_", where n is the depth of this deferral. That is, if the object deferred to also defers, then n is incremented. This differs from the superclass in that a number is always appended in this class. This is mainly important for visualization of the created actors and their displayed names.- Overrides:
uniqueName
in classCompositeEntity
- Parameters:
prefix
- A prefix for the name.- Returns:
- A unique name.
-
_addAttribute
protected void _addAttribute(Attribute attribute) throws NameDuplicationException, IllegalActionException
Add the attribute, and if the attribute is a PtalonParameter, add it to a list of Ptalon parameters.- Overrides:
_addAttribute
in classNamedObj
- Parameters:
attribute
- The attribute to be added.- Throws:
NameDuplicationException
- If the superclass throws it.IllegalActionException
- If the superclass throws it.
-
_createPtalonEvaluator
protected PtalonEvaluator _createPtalonEvaluator(PtalonActor actor)
-
_createPtalonPopulator
protected PtalonPopulator _createPtalonPopulator()
-
_createPtalonRecognizer
protected PtalonRecognizer _createPtalonRecognizer(PtalonLexer lexer)
Create Ptalon parser. This function simply constructs aPtalonRecognizer
instance with the given lexer. Subclasses may override this function to return a customized parser.- Parameters:
lexer
- The lexer.- Returns:
- The Ptalon parser.
-
_exportMoMLContents
protected void _exportMoMLContents(java.io.Writer output, int depth) throws java.io.IOException
Write a MoML description of the contents of this object, which in this class is the configuration information. This method is called by exportMoML(). Each description is indented according to the specified depth and terminated with a newline character. Note that this only saves the values of the Ptalon parameters; it does not save other entities generated as a result of parsing the Ptalon file.- Overrides:
_exportMoMLContents
in classCompositeEntity
- Parameters:
output
- The output stream for writing.depth
- The depth in the hierarchy, to determine indenting.- Throws:
java.io.IOException
- If an I/O error occurs.- See Also:
NamedObj.exportMoML(Writer, int)
-
_initializePtalonActor
protected void _initializePtalonActor()
Initialize this PtalonActor. This method may be called when the PtalonActor is first constructed or if any of its parameter values are changed, so we only initialize variables that do not need to be saved when reparsing the Ptalon file.
-
_initializePtalonCodeLocation
protected void _initializePtalonCodeLocation() throws IllegalActionException
This helper method is used to begin the Ptalon compiler if the ptalonCodeLocation attribute has been updated.- Throws:
IllegalActionException
- If any exception is thrown.
-
_removeContents
protected void _removeContents()
-
-