ptolemy.actor.gt
Class TransformationRule

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
                              extended by ptolemy.actor.lib.hoc.MultiCompositeActor
                                  extended by ptolemy.actor.gt.TransformationRule
All Implemented Interfaces:
java.io.Serializable, 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 (with PatternObjectAttribute 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: TransformationRule.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Huining Feng
See Also:
Serialized Form
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
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
private static java.util.Set<Inequality> _EMPTY_SET
          An empty list.
private static java.lang.String _FULL_CONTROL
          The full control mode.
private  CompositeEntity _lastModel
          The last received model.
private  java.util.List<MatchResult> _lastResults
          The list of match results collected in the most recent pattern matching.
private  boolean _removeFirst
          Whether the first match result should be removed in postfire.
 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, _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
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
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
newPort
 
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _typeConstraintsFromTo, newRelation, resolveTypes, typeConstraintList
 
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _getPublishedPort, _setDirector, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, createReceivers, createSchedule, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inferringWidths, inferWidths, inputPortList, isFireFunctional, isOpaque, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, preinitialize, recordFiring, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort
 
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, attributeList, attributeList, attributeTypeChanged, 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
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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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.


_EMPTY_SET

private static final java.util.Set<Inequality> _EMPTY_SET
An empty list.


_FULL_CONTROL

private static final java.lang.String _FULL_CONTROL
The full control mode.

See Also:
Constant Field Values

_lastModel

private CompositeEntity _lastModel
The last received model.


_lastResults

private java.util.List<MatchResult> _lastResults
The list of match results collected in the most recent pattern matching.


_removeFirst

private boolean _removeFirst
Whether the first match result should be removed in postfire.

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 class NamedObj
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.

Overrides:
clone in class NamedObj
Returns:
A new NamedObj.
Throws:
java.lang.CloneNotSupportedException - If any of the attributes cannot be cloned.

fire

public void fire()
          throws IllegalActionException
Fire this actor. Depending on the transformation mode, the action performed on the input and output is different.

Specified by:
fire in interface Executable
Overrides:
fire in class CompositeActor
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 interface Initializable
Overrides:
initialize in class CompositeActor
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 interface Executable
Overrides:
postfire in class CompositeActor
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 interface Executable
Overrides:
prefire in class CompositeActor
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 interface TypedActor
Overrides:
typeConstraints in class TypedCompositeActor
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 interface ValueListener
Parameters:
settable - The attribute changed.

wrapup

public void wrapup()
            throws IllegalActionException
Wrap up the actor after an execution.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class CompositeActor
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.