ptolemy.actor.gt
Class TransformationMode

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.kernel.util.AbstractSettableAttribute
              extended by ptolemy.data.expr.Variable
                  extended by ptolemy.data.expr.Parameter
                      extended by ptolemy.data.expr.StringParameter
                          extended by ptolemy.data.expr.ChoiceParameter
                              extended by ptolemy.actor.gt.TransformationMode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, MatchCallback, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, Settable, ValueListener

public class TransformationMode
extends ChoiceParameter
implements MatchCallback

A parameter that determines the transformation mode. It also provides functions to perform transformation according to the chosen mode.

Since:
Ptolemy II 8.0
Version:
$Id: TransformationMode.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Thomas Huining Feng
See Also:
Serialized Form
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
static class TransformationMode.Mode
          The enumeration of accepted modes.
private static class TransformationMode.WorkingCopyScopeExtender
          A scope extender to resolve names in the scope of the master transformation rule even though the expression is specified in a working copy.
 
Nested classes/interfaces inherited from class ptolemy.data.expr.Variable
Variable.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Nested classes/interfaces inherited from interface ptolemy.kernel.util.Settable
Settable.Visibility
 
Field Summary
private  boolean _collectAllMatches
          Whether all matches should be collected in a list.
private  TransformationRule _masterRule
          The master transformation rule (not the working copy).
private  GraphMatcher _matcher
          The graph matcher.
private  java.util.LinkedList<MatchResult> _matchResults
          The collected matches.
private  java.util.Random _random
          The random number generator.
private  TransformationRule _workingCopy
          The current working copy.
private  long _workingCopyVersion
          Version of the current working copy.
private  Workspace _workspace
          A new workspace for working copies.
 
Fields inherited from class ptolemy.data.expr.Variable
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _valueListeners
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.kernel.util.Settable
EXPERT, FULL, NONE, NOT_EDITABLE
 
Constructor Summary
TransformationMode(NamedObj container, java.lang.String name)
          Construct a parameter with the given name contained by the specified entity.
 
Method Summary
 java.lang.Object clone(Workspace workspace)
          Clone the variable.
 java.util.List<MatchResult> findAllMatches(TransformationRule workingCopy, CompositeEntity model)
          Find all the matches to the pattern in the workingCopy and return those matches in a list.
 boolean foundMatch(GraphMatcher matcher)
          A routine to be called when a match is found in the graph matching.
 TransformationRule getWorkingCopy(TransformationRule masterRule)
          Get a working copy for the transformation rule, which can be modified in pattern matching and transformation without affecting the original rule.
 boolean isMatchOnly()
          Whether the transformation mode is match only.
 boolean transform(TransformationRule workingCopy, CompositeEntity model)
          Transform the model with the working copy.
 boolean transform(TransformationRule workingCopy, CompositeEntity model, TransformationListener listener, boolean defer)
          Transform the model with the working copy.
 
Methods inherited from class ptolemy.data.expr.ChoiceParameter
getChosenValue
 
Methods inherited from class ptolemy.data.expr.StringParameter
stringValue
 
Methods inherited from class ptolemy.data.expr.Parameter
addChoice, exportMoML, getChoices, removeAllChoices, removeChoice
 
Methods inherited from class ptolemy.data.expr.Variable
_description, _evaluate, _notifyValueListeners, _parseIfNecessary, _propagate, _propagateToValueListeners, _propagateValue, _setToken, _setTokenAndNotify, addValueListener, getDeclaredType, getExpression, getFreeIdentifiers, getParserScope, getScope, getScope, getToken, getType, getTypeTerm, getValueAsString, getVariable, getVisibility, invalidate, isKnown, isLazy, isStringMode, isTypeAcceptable, removeValueListener, reset, setContainer, setExpression, setLazy, setName, setParseTreeEvaluator, setStringMode, setToken, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, setUnknown, setVisibility, stringRepresentation, toString, typeConstraintList, typeConstraints, validate, valueChanged
 
Methods inherited from class ptolemy.kernel.util.AbstractSettableAttribute
getDefaultExpression
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName
 

Field Detail

_collectAllMatches

private boolean _collectAllMatches
Whether all matches should be collected in a list.


_masterRule

private TransformationRule _masterRule
The master transformation rule (not the working copy).


_matchResults

private java.util.LinkedList<MatchResult> _matchResults
The collected matches.


_matcher

private GraphMatcher _matcher
The graph matcher.


_random

private java.util.Random _random
The random number generator.


_workingCopy

private TransformationRule _workingCopy
The current working copy.


_workingCopyVersion

private long _workingCopyVersion
Version of the current working copy.


_workspace

private Workspace _workspace
A new workspace for working copies.

Constructor Detail

TransformationMode

public TransformationMode(NamedObj container,
                          java.lang.String name)
                   throws IllegalActionException,
                          NameDuplicationException
Construct a parameter with the given name contained by the specified entity. The container argument must not be null, or a NullPointerException will be thrown. This parameter 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. The object is not added to the list of objects in the workspace unless the container is null. Increment the version of the workspace.

Parameters:
container - The container.
name - The name of the parameter.
Throws:
IllegalActionException - If the parameter is not of an acceptable class for the container.
NameDuplicationException - If the name coincides with a parameter already in the container.
Method Detail

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the variable. This creates a new variable containing the same token (if the value was set with setToken()) or the same (unevaluated) expression, if the expression was set with setExpression(). The list of variables added to the scope is not cloned; i.e., the clone has an empty scope. The clone has the same static type constraints (those given by setTypeEquals() and setTypeAtMost()), but none of the dynamic type constraints (those relative to other variables).

Overrides:
clone in class Variable
Parameters:
workspace - The workspace in which to place the cloned variable.
Returns:
The cloned variable.
Throws:
java.lang.CloneNotSupportedException - Not thrown in this base class.
See Also:
Object.clone()

findAllMatches

public java.util.List<MatchResult> findAllMatches(TransformationRule workingCopy,
                                                  CompositeEntity model)
Find all the matches to the pattern in the workingCopy and return those matches in a list. When invoked a second time, the previously returned list would be invalidated. It is the caller's responsibility to duplicate the list if it needs to be preserved after the next invocation.

Parameters:
workingCopy - The transformation rule that can be modified.
model - The model for pattern matching.
Returns:
The list of matches.

foundMatch

public boolean foundMatch(GraphMatcher matcher)
A routine to be called when a match is found in the graph matching. The graph matcher is passed in as the parameter, and the current match can be obtained by calling GraphMatcher.getMatchResult(). This match result should not be kept, however, because it may be changed by future matching operations. To keep a copy of this result, invoke MatchResult.clone() and keep the cloned copy. The return value indicates whether the match is the one looked for. If it is true, the matching will terminate after this routine returns, and no more match result will be reported.

Specified by:
foundMatch in interface MatchCallback
Parameters:
matcher - The graph matcher.
Returns:
Whether the matching should terminate right away.

getWorkingCopy

public TransformationRule getWorkingCopy(TransformationRule masterRule)
                                  throws IllegalActionException
Get a working copy for the transformation rule, which can be modified in pattern matching and transformation without affecting the original rule.

Parameters:
masterRule - The transformation rule.
Returns:
The working copy.
Throws:
IllegalActionException - If a working copy cannot be obtained.

isMatchOnly

public boolean isMatchOnly()
Whether the transformation mode is match only.

Returns:
true if the transformation mode is match only.

transform

public boolean transform(TransformationRule workingCopy,
                         CompositeEntity model)
                  throws IllegalActionException
Transform the model with the working copy. The change is done immediately without defer.

Parameters:
workingCopy - The working copy.
model - The model to be transformed.
Returns:
true if the transformation was successful (i.e., any match to the pattern is found).
Throws:
IllegalActionException - If thrown in pattern matching or transformation.
See Also:
transform(TransformationRule, CompositeEntity, TransformationListener, boolean)

transform

public boolean transform(TransformationRule workingCopy,
                         CompositeEntity model,
                         TransformationListener listener,
                         boolean defer)
                  throws IllegalActionException
Transform the model with the working copy.

Parameters:
workingCopy - The working copy.
model - The model to be transformed.
listener - The listener to be invoked during transformation.
defer - Whether the change should be deferred if necessary with a change request.
Returns:
true if the transformation was successful (i.e., any match to the pattern is found).
Throws:
IllegalActionException - If thrown in pattern matching or transformation.