Package ptolemy.actor.gt
Class GraphTransformer
- java.lang.Object
-
- ptolemy.kernel.util.ChangeRequest
-
- ptolemy.actor.gt.GraphTransformer
-
public class GraphTransformer extends ChangeRequest
Model transformation with a given match of the pattern. The transformation is implemented as aChangeRequest
, so its execution can be deferred. When it is executed, it generates a bunch ofMoMLChangeRequest
s and immediately executes those requests. Those requests adjusts the model with the given match of the pattern.- 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
GraphTransformer.ReplacementObjectAttribute
A temporary attribute to record the corresponding object in the replacement for any object in the pattern.
-
Constructor Summary
Constructors Constructor Description GraphTransformer(TransformationRule transformationRule, java.util.List<MatchResult> matchResults)
Construct a transformer with the given transformation rule (including a pattern and a replacement), and a list of match results.GraphTransformer(TransformationRule transformationRule, MatchResult matchResult)
Construct a transformer with the given transformation rule (including a pattern and a replacement), and a single match result.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addConnections()
Add new connections.protected void
_addObjects()
Add new NamedObjs.protected void
_execute()
Execute the change request and perform the transformation on the match result(s) given to the constructor.protected void
_hideRelations()
Hide all the relations in the host model that can be hidden, such as the ones that are visible but are not multi-way.protected void
_init()
Initialize model transformation and construct the maps between objects in the pattern, those in the replacement, and those in the host model.protected void
_performOperations()
Perform all the operations associated with the objects in the replacement.protected void
_recordMoML()
Record the MoML for the objects in the host model that are matched and need to be preserved in the result.protected void
_removeLinks()
Remove the links in the host model that are matched but need to be deleted.protected void
_removeObjects()
Remove the NamedObjs in the host model that are matched but need to be deleted.protected void
_restoreParameterValues()
Restore the values of the ValueIterators in the host model, so that they have the values that were used to obtain the match result.protected void
_wrapup()
Finish up transformation and remove the helper attributes in the replacement and the host model created in the transformation.void
addTransformationListener(TransformationListener listener)
Add a TransformationListener to listen to the transformation.MatchResult
getMatchResult()
Get the current match result used for the transformation.Pattern
getPattern()
Get the pattern of the transformation rule being used.Replacement
getReplacement()
Get the replacement of the transformation rule being used.void
removeTransformationListener(TransformationListener listener)
Remove a previously added TransformationListener.static void
startUndoableTransformation(boolean mergeWithPrevious)
Make all the transformers to execute undoable MoMLChangeRequests.static void
stopUndoableTransformation()
Stop executing undoable MoMLChangeRequests in all transformers, so that future requests cannot be undone.static void
transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults)
Transform a list of match results with a transformation rule.static void
transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults, TransformationListener listener)
Transform a list of match results with a transformation rule.static void
transform(TransformationRule transformationRule, MatchResult matchResult)
Transform a match result with a transformation rule.static void
transform(TransformationRule transformationRule, MatchResult matchResult, TransformationListener listener)
Transform a match result with a transformation rule.-
Methods inherited from class ptolemy.kernel.util.ChangeRequest
addChangeListener, execute, getDescription, getLocality, getSource, isErrorReported, isPersistent, isStructuralChange, removeChangeListener, setDescription, setErrorReported, setListeners, setPersistent, waitForCompletion
-
-
-
-
Constructor Detail
-
GraphTransformer
public GraphTransformer(TransformationRule transformationRule, java.util.List<MatchResult> matchResults)
Construct a transformer with the given transformation rule (including a pattern and a replacement), and a list of match results. The transformer tries to transform all matches, unless the previous ones violate the latter ones.- Parameters:
transformationRule
- The transformation rule.matchResults
- The list of match results.
-
GraphTransformer
public GraphTransformer(TransformationRule transformationRule, MatchResult matchResult)
Construct a transformer with the given transformation rule (including a pattern and a replacement), and a single match result. The transformer transforms the match.- Parameters:
transformationRule
- The transformation rule.matchResult
- The match result.
-
-
Method Detail
-
addTransformationListener
public void addTransformationListener(TransformationListener listener)
Add a TransformationListener to listen to the transformation.- Parameters:
listener
- The TransformationListener.- See Also:
removeTransformationListener(TransformationListener)
-
getMatchResult
public MatchResult getMatchResult()
Get the current match result used for the transformation.- Returns:
- The current match result.
-
getPattern
public Pattern getPattern()
Get the pattern of the transformation rule being used.- Returns:
- The pattern.
-
getReplacement
public Replacement getReplacement()
Get the replacement of the transformation rule being used.- Returns:
- The replacement.
-
removeTransformationListener
public void removeTransformationListener(TransformationListener listener)
Remove a previously added TransformationListener. No effect if the TransformationListener is not added yet.- Parameters:
listener
- The TransformationListener.- See Also:
addTransformationListener(TransformationListener)
-
startUndoableTransformation
public static void startUndoableTransformation(boolean mergeWithPrevious)
Make all the transformers to execute undoable MoMLChangeRequests.- Parameters:
mergeWithPrevious
- Whether the undo entries should be merged with previous undo entries.
-
stopUndoableTransformation
public static void stopUndoableTransformation()
Stop executing undoable MoMLChangeRequests in all transformers, so that future requests cannot be undone.
-
transform
public static void transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults) throws TransformationException
Transform a list of match results with a transformation rule.- Parameters:
transformationRule
- The transformation rule.matchResults
- The list of match results.- Throws:
TransformationException
- If the pattern is not matched to any host model in the match results.
-
transform
public static void transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults, TransformationListener listener) throws TransformationException
Transform a list of match results with a transformation rule.- Parameters:
transformationRule
- The transformation rule.matchResults
- The list of match results.listener
- The TransformationListener to listen to the transformation.- Throws:
TransformationException
- If the pattern is not matched to any host model in the match results.
-
transform
public static void transform(TransformationRule transformationRule, MatchResult matchResult) throws TransformationException
Transform a match result with a transformation rule.- Parameters:
transformationRule
- The transformation rule.matchResult
- The match result.- Throws:
TransformationException
- If the pattern is not matched to any host model in the match result.
-
transform
public static void transform(TransformationRule transformationRule, MatchResult matchResult, TransformationListener listener) throws TransformationException
Transform a match result with a transformation rule.- Parameters:
transformationRule
- The transformation rule.matchResult
- The match result.listener
- The TransformationListener to listen to the transformation.- Throws:
TransformationException
- If the pattern is not matched to any host model in the match result.
-
_addConnections
protected void _addConnections() throws TransformationException
Add new connections.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_addObjects
protected void _addObjects() throws TransformationException
Add new NamedObjs.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_execute
protected void _execute() throws TransformationException
Execute the change request and perform the transformation on the match result(s) given to the constructor.- Specified by:
_execute
in classChangeRequest
- Throws:
TransformationException
- If transformation is unsuccessful.
-
_hideRelations
protected void _hideRelations()
Hide all the relations in the host model that can be hidden, such as the ones that are visible but are not multi-way.
-
_init
protected void _init() throws TransformationException
Initialize model transformation and construct the maps between objects in the pattern, those in the replacement, and those in the host model.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_performOperations
protected void _performOperations() throws TransformationException
Perform all the operations associated with the objects in the replacement.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_recordMoML
protected void _recordMoML() throws TransformationException
Record the MoML for the objects in the host model that are matched and need to be preserved in the result.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_removeLinks
protected void _removeLinks()
Remove the links in the host model that are matched but need to be deleted.
-
_removeObjects
protected void _removeObjects() throws TransformationException
Remove the NamedObjs in the host model that are matched but need to be deleted.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_restoreParameterValues
protected void _restoreParameterValues() throws TransformationException
Restore the values of the ValueIterators in the host model, so that they have the values that were used to obtain the match result.- Throws:
TransformationException
- If transformation is unsuccessful.
-
_wrapup
protected void _wrapup() throws TransformationException
Finish up transformation and remove the helper attributes in the replacement and the host model created in the transformation.- Throws:
TransformationException
- If transformation is unsuccessful.
-
-