Package ptolemy.actor.gt
Class TransformationRule
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,GTCompositeActor
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
,ValueListener
public class TransformationRule extends MultiCompositeActor implements GTCompositeActor, ValueListener
A transformation rule that contains a pattern and a replacement. It has two purposes. As an abstraction of a transformation rule, it groups the pattern and the replacement and relate objects between them (withPatternObjectAttribute
associated to objects in the replacement). As an actor, it has a port that accepts model tokens containing models to be transformed, and it produces transformed models in new model tokens to another port.- Since:
- Ptolemy II 7.1
- Version:
- $Id$
- Author:
- Thomas Huining Feng
- Pt.AcceptedRating:
- Red (tfeng)
- Pt.ProposedRating:
- Yellow (tfeng)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransformationRule.TransformationDirector
A director to be associated with this actor, which does nothing.-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description TypedIOPort
matched
The matched port.TypedIOPort
matchInput
The matchInput port.TypedIOPort
matchOutput
The matchOutput port.TransformationMode
mode
The mode.TypedIOPort
modelInput
The modelInput port.TypedIOPort
modelOutput
The modelOutput port.TypedIOPort
remaining
The remaining port.Parameter
repeatCount
The count of repeated transformation in one firing.Parameter
repeatUntilFixpoint
Whether the transformation in one firing should continue until a fixpoint is reached.TypedIOPort
trigger
The trigger port.-
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 TransformationRule(CompositeEntity container, java.lang.String name)
Construct a transformation rule with a name and a container.TransformationRule(Workspace workspace)
Construct a transformation rule in the specified workspace with no container and an empty string as a name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_init()
Initialize the pattern, the replacement and the parameters of this transformation rule.void
attributeChanged(Attribute attribute)
React to a change in the mode parameter or the repeatUntilFixpoint parameter, and update the appearance of this actor.java.lang.Object
clone()
Clone the object into the current workspace by calling the clone() method that takes a Workspace argument.void
fire()
Fire this actor.Pattern
getPattern()
Get the pattern of this transformation rule.Replacement
getReplacement()
Get the replacement of this transformation rule.void
initialize()
Initialize this actor.boolean
postfire()
If a trigger has been received in fire and the next match has been produced to the matchOutput port, remove the first match in the list.boolean
prefire()
Test whether this actor can be fired, depending on the mode.java.util.Set<Inequality>
typeConstraints()
Return an empty list.void
valueChanged(Settable settable)
React to the change of mode and change the ports of this actor.void
wrapup()
Wrap up the actor after an execution.-
Methods inherited from class ptolemy.actor.lib.hoc.MultiCompositeActor
mirrorContainerPortsInRefinement, newPort
-
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newRelation, resolveTypes, typeConstraintList
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, createReceivers, createSchedule, getCausalityInterface, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort
-
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _exportMoMLContents, _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, 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, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, 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
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
Methods inherited from interface ptolemy.actor.TypedActor
isBackwardTypeInferenceEnabled
-
-
-
-
Field Detail
-
matchInput
public TypedIOPort matchInput
The matchInput port.
-
matchOutput
public TypedIOPort matchOutput
The matchOutput port.
-
matched
public TypedIOPort matched
The matched port.
-
mode
public TransformationMode mode
The mode.
-
modelInput
public TypedIOPort modelInput
The modelInput port.
-
modelOutput
public TypedIOPort modelOutput
The modelOutput port.
-
remaining
public TypedIOPort remaining
The remaining port.
-
repeatCount
public Parameter repeatCount
The count of repeated transformation in one firing.
-
repeatUntilFixpoint
public Parameter repeatUntilFixpoint
Whether the transformation in one firing should continue until a fixpoint is reached.
-
trigger
public TypedIOPort trigger
The trigger port.
-
-
Constructor Detail
-
TransformationRule
public TransformationRule(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a transformation rule with a name and a container. The container argument must not be null, or a NullPointerException will be thrown.- 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.
-
TransformationRule
public TransformationRule(Workspace workspace) throws IllegalActionException, NameDuplicationException
Construct a transformation rule 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.- Parameters:
workspace
- The workspace that will list the actor.- Throws:
IllegalActionException
- If the name has a period in it, or the director is not compatible with the specified container.NameDuplicationException
- If the container already contains an entity with the specified name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
React to a change in the mode parameter or the repeatUntilFixpoint parameter, and update the appearance of this actor.- Overrides:
attributeChanged
in classTypedCompositeActor
- Parameters:
attribute
- The attribute changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container (not thrown in this base class).
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Clone the object into the current workspace by calling the clone() method that takes a Workspace argument. This method read-synchronizes on the workspace.
-
fire
public void fire() throws IllegalActionException
Fire this actor. Depending on the transformation mode, the action performed on the input and output is different.- If the mode is match only, then the actor has only an input port to receive input models and an output port to send out success flags in Booleans. When fired, a model token is read from the input port. Pattern matching is performed on it with a working copy of the encapsulated transformation rule. A true or false token is produced to the output port depending on the result of the pattern matching.
- If the mode is one if replace first, replace last, replace any and
replace all, the actor has one more output port to send out the
transformed models in model tokens. The transformation action is
performed according to the transformation modes specified in
TransformationMode.Mode
. - If the mode is full control, then the actor has a total of 6 ports. A modelInput port receives input models. A modelOutput port sends out result models. A matchInput port receives matches to be used for the transformation. A matchOutput port to produce matches. A trigger port to trigger pattern matching. A remaining port to output integer numbers representing the numbers of remaining matches. In each firing, if the modelInput port has a token present, the token is read and pattern matching is performed on the contained model. All the matches are collected in a list. It matchInput port has a token present, the match is read from that port and is used to transform the model, with the output being sent to the modelOutput port. If the trigger port has a token present, the token is consumed and the next match in the collected list is sent to the matchOutput port. Finally, in all cases, the number of remaining matches in the list is sent to the remaining port.
- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classCompositeActor
- Throws:
IllegalActionException
- If error occurs in reading the input, in sending the output, or in the transformation.
-
getPattern
public Pattern getPattern()
Get the pattern of this transformation rule.- Returns:
- The pattern.
-
getReplacement
public Replacement getReplacement()
Get the replacement of this transformation rule.- Returns:
- The replacement.
-
initialize
public void initialize() throws IllegalActionException
Initialize this actor.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classCompositeActor
- Throws:
IllegalActionException
- If the superclass throws it.
-
postfire
public boolean postfire() throws IllegalActionException
If a trigger has been received in fire and the next match has been produced to the matchOutput port, remove the first match in the list.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classCompositeActor
- Returns:
- The result from postfire of the superclass.
- Throws:
IllegalActionException
- If thrown by the superclass.
-
prefire
public boolean prefire() throws IllegalActionException
Test whether this actor can be fired, depending on the mode.- Specified by:
prefire
in interfaceExecutable
- Overrides:
prefire
in classCompositeActor
- Returns:
- true if this actor can be fired.
- Throws:
IllegalActionException
- If thrown by the superclass or if the mode cannot be retrieved.- See Also:
fire()
-
typeConstraints
public java.util.Set<Inequality> typeConstraints() throws IllegalActionException
Return an empty list.- Specified by:
typeConstraints
in interfaceTypedActor
- Overrides:
typeConstraints
in classTypedCompositeActor
- Returns:
- An empty list.
- Throws:
IllegalActionException
- Not thrown in this class.- See Also:
Inequality
-
valueChanged
public void valueChanged(Settable settable)
React to the change of mode and change the ports of this actor.- Specified by:
valueChanged
in interfaceValueListener
- Parameters:
settable
- The attribute changed.
-
wrapup
public void wrapup() throws IllegalActionException
Wrap up the actor after an execution.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classCompositeActor
- Throws:
IllegalActionException
- If thrown by the superclass.
-
_init
protected void _init() throws IllegalActionException, NameDuplicationException
Initialize the pattern, the replacement and the parameters of this transformation rule.- Throws:
IllegalActionException
- If some objects cannot be contained by the proposed container.NameDuplicationException
- If the name of an object coincides with a name already in the container.
-
-