|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.ChangeRequest
ptolemy.actor.gt.GraphTransformer
public class GraphTransformer
Model transformation with a given match of the pattern. The transformation is
implemented as a GraphTransformer.CreateObjectChangeRequest
, so its execution can be deferred. When
it is executed, it generates a bunch of MoMLChangeRequest
s and
immediately executes those requests. Those requests adjusts the model with the
given match of the pattern.
Red (tfeng) |
Yellow (tfeng) |
Nested Class Summary | |
---|---|
private class |
GraphTransformer.CreateObjectChangeRequest
The change request to create objects in the host model and record those objects in the tables. |
static class |
GraphTransformer.ReplacementObjectAttribute
A temporary attribute to record the corresponding object in the replacement for any object in the pattern. |
Field Summary | |
---|---|
private CompositeEntity |
_host
The top level of the host model. |
private java.util.List<TransformationListener> |
_listeners
The list of listeners. |
private MatchResult |
_matchResult
The current match result for the transformation. |
private java.util.List<MatchResult> |
_matchResults
The list of match results to be used. |
private static boolean |
_mergeWithPrevious
Whether the change requests are undoable and merged with previous change requests in an undo action. |
private java.util.Map<NamedObj,java.lang.String> |
_moml
The MoML of the objects recorded from the host model. |
private Pattern |
_pattern
The pattern of the transformation rule. |
private TwoWayHashMap<NamedObj,NamedObj> |
_patternToReplacement
A table from the preserved objects in the pattern to the objects in the replacement. |
private Replacement |
_replacement
The replacement of the transformation rule. |
private TwoWayHashMap<NamedObj,NamedObj> |
_replacementToHost
A table from the objects in the replacement to the objects in the host model. |
private static boolean |
_undoable
Whether the change requests are undoable. |
Constructor Summary | |
---|---|
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 | |
---|---|
protected void |
_addConnections()
Add new connections. |
protected void |
_addObjects()
Add new NamedObjs. |
private void |
_addObjects(NamedObj replacement,
NamedObj host,
boolean copyAttributes)
Add objects in a container in the replacement to a container in the host model. |
private void |
_addObjectsWithCreationAttributes(NamedObj pattern)
Add objects with CreationAttribute s from a container in the
pattern to the container that that container matches in the host model. |
private void |
_addReplacementToHostEntries(NamedObj host)
Add replacement-to-host entries in the table by traversing from a container in the host model to all its contained objects recursively. |
private GraphTransformer.CreateObjectChangeRequest |
_createAddObjectRequest(NamedObj context,
java.lang.String moml)
Create a change request to add an object in the context in the host model, and record the created object(s) in a private field of the change request itself. |
private MoMLChangeRequest |
_createChangeRequest(NamedObj context,
java.lang.String moml)
Create a change request to be executed in the context. |
protected void |
_execute()
Execute the change request and perform the transformation on the match result(s) given to the constructor. |
private Token |
_getAttribute(NamedObj container,
java.lang.String name,
java.lang.Class<? extends Parameter> attributeClass)
Get a GTAttribute in the given attribute class with the given name in the container. |
private double[] |
_getBestLocation(java.util.List<?> linkedObjectList)
Return the best location (in X-Y coordinates) for a relation that is linked to the given list of objects. |
private java.lang.String |
_getLinkMoML(NamedObj object,
Relation relation)
Return the MoML to link the object to the relation. |
private java.lang.String |
_getMoML(NamedObj host)
Get the MoML for an object in the host model. |
private GraphTransformer.ReplacementObjectAttribute |
_getReplacementObjectAttribute(NamedObj object)
Get the ReplacementObjectAttribute associated with an object in the host model, if any. |
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. |
private void |
_hideRelations(CompositeEntity host)
Hide all the relations in a container 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. |
private void |
_initPatternToReplacement(NamedObj replacement)
Initialize the table from objects in the pattern to the objects in the replacement. |
private void |
_initPreservedObjects(NamedObj pattern)
For the objects in the pattern that are tagged to be preserved, mirror them to the replacement to preserve them. |
private void |
_initReplacementObjectAttributes(NamedObj replacement)
Initialize the ReplacementObjectAttributes for all the objects in a container in the replacement, so that when those objects are copied into the host model, the new objects in the host model also have those ReplacementObjectAttributes. |
private void |
_initReplacementToHost()
For the objects in the replacement, initialize table entries that map them to the host model if they are preserved from the pattern, and set the ReplacementObjectAttributes for them. |
private boolean |
_isAttributeCopied(Attribute attribute)
Test whether the attribute should be copied. |
protected void |
_performOperations()
Perform all the operations associated with the objects in the replacement. |
private void |
_recordMirroredObjects(NamedObj pattern,
NamedObj host)
Mirror the object tagged to be preserved in the pattern so that it is also considered to exist 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. |
private boolean |
_relink(Relation preserved,
Relation removed)
Remove the removed relation, and link all the ports that are originally linked to the removed relation with the preserved relation. |
protected void |
_removeLinks()
Remove the links in the host model that are matched but need to be deleted. |
private void |
_removeLinks(CompositeEntity pattern)
Remove the links in the host model that are matched but need to be deleted. |
private java.util.Set<NamedObj> |
_removeObject(NamedObj object,
boolean shallowRemoval)
Remove an object from the host model. |
protected void |
_removeObjects()
Remove the NamedObjs in the host model that are matched but need to be deleted. |
private void |
_removeObjects(CompositeEntity host)
Remove the NamedObjs in a container in the host model that are matched but need to be deleted. |
private void |
_removeReplacementObjectAttributes(NamedObj object)
Remove the ReplacementObjectAttributes associated with the object and any of the objects contained in that object. |
private void |
_removeReplacementToHostEntries(NamedObj host)
Remove the replacement-to-host entries in the table for the container in the host model, as well as all the objects contained in it. |
private void |
_replaceMatchResultEntries(NamedObj oldHost,
NamedObj newHost)
Replace the entries in the current match result from the old host object to the new host object. |
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. |
private void |
_setReplacementObjectAttribute(NamedObj object,
java.lang.String replacementObjectCode)
Set the ReplacementObjectAttribute for an object in the host model with the given code about the object type and object name. |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private CompositeEntity _host
private java.util.List<TransformationListener> _listeners
private MatchResult _matchResult
private java.util.List<MatchResult> _matchResults
private static boolean _mergeWithPrevious
private java.util.Map<NamedObj,java.lang.String> _moml
private Pattern _pattern
private TwoWayHashMap<NamedObj,NamedObj> _patternToReplacement
private Replacement _replacement
private TwoWayHashMap<NamedObj,NamedObj> _replacementToHost
private static boolean _undoable
Constructor Detail |
---|
public GraphTransformer(TransformationRule transformationRule, java.util.List<MatchResult> matchResults)
transformationRule
- The transformation rule.matchResults
- The list of match results.public GraphTransformer(TransformationRule transformationRule, MatchResult matchResult)
transformationRule
- The transformation rule.matchResult
- The match result.Method Detail |
---|
public void addTransformationListener(TransformationListener listener)
listener
- The TransformationListener.removeTransformationListener(TransformationListener)
public MatchResult getMatchResult()
public Pattern getPattern()
public Replacement getReplacement()
public void removeTransformationListener(TransformationListener listener)
listener
- The TransformationListener.addTransformationListener(TransformationListener)
public static void startUndoableTransformation(boolean mergeWithPrevious)
mergeWithPrevious
- Whether the undo entries should be merged with
previous undo entries.public static void stopUndoableTransformation()
public static void transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults) throws TransformationException
transformationRule
- The transformation rule.matchResults
- The list of match results.
TransformationException
- If the pattern is not matched to any
host model in the match results.public static void transform(TransformationRule transformationRule, java.util.List<MatchResult> matchResults, TransformationListener listener) throws TransformationException
transformationRule
- The transformation rule.matchResults
- The list of match results.listener
- The TransformationListener to listen to the
transformation.
TransformationException
- If the pattern is not matched to any
host model in the match results.public static void transform(TransformationRule transformationRule, MatchResult matchResult) throws TransformationException
transformationRule
- The transformation rule.matchResult
- The match result.
TransformationException
- If the pattern is not matched to any
host model in the match result.public static void transform(TransformationRule transformationRule, MatchResult matchResult, TransformationListener listener) throws TransformationException
transformationRule
- The transformation rule.matchResult
- The match result.listener
- The TransformationListener to listen to the
transformation.
TransformationException
- If the pattern is not matched to any
host model in the match result.protected void _addConnections() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _addObjects() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _execute() throws TransformationException
_execute
in class ChangeRequest
TransformationException
- If transformation is unsuccessful.protected void _hideRelations()
protected void _init() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _performOperations() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _recordMoML() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _removeLinks()
protected void _removeObjects() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _restoreParameterValues() throws TransformationException
TransformationException
- If transformation is unsuccessful.protected void _wrapup() throws TransformationException
TransformationException
- If transformation is unsuccessful.private void _addObjects(NamedObj replacement, NamedObj host, boolean copyAttributes) throws TransformationException
replacement
- A container in the replacement.host
- A container in the host model.copyAttributes
- Whether attributes of the container in the
replacement, if it is a CompositeEntity, should be copied to the
container in the host model.
TransformationException
- If transformation is unsuccessful.private void _addObjectsWithCreationAttributes(NamedObj pattern) throws TransformationException
CreationAttribute
s from a container in the
pattern to the container that that container matches in the host model.
pattern
- A container in the pattern.
TransformationException
- If transformation is unsuccessful.private void _addReplacementToHostEntries(NamedObj host)
host
- A container in the host model.private GraphTransformer.CreateObjectChangeRequest _createAddObjectRequest(NamedObj context, java.lang.String moml)
context
- The context.moml
- The MoML to be executed to add the object.
private MoMLChangeRequest _createChangeRequest(NamedObj context, java.lang.String moml)
context
- The context.moml
- The MoML to be executed.
private Token _getAttribute(NamedObj container, java.lang.String name, java.lang.Class<? extends Parameter> attributeClass)
container
- The container to start the search with.name
- The name of the attribute to be searched for.attributeClass
- The class of the attribute to be searched for.
private double[] _getBestLocation(java.util.List<?> linkedObjectList)
linkedObjectList
- The list of objects that a relation is linked
to.
private java.lang.String _getLinkMoML(NamedObj object, Relation relation)
object
- The object.relation
- The relation.
private java.lang.String _getMoML(NamedObj host)
host
- An object in the host model.
private GraphTransformer.ReplacementObjectAttribute _getReplacementObjectAttribute(NamedObj object)
object
- The object.
private void _hideRelations(CompositeEntity host)
host
- A container in the host model.private void _initPatternToReplacement(NamedObj replacement)
replacement
- The replacement.private void _initPreservedObjects(NamedObj pattern)
pattern
- The pattern.private void _initReplacementObjectAttributes(NamedObj replacement) throws TransformationException
replacement
- A container in the replacement.
TransformationException
- If attributes cannot be created.private void _initReplacementToHost() throws TransformationException
TransformationException
- If attributes cannot be created.private boolean _isAttributeCopied(Attribute attribute)
attribute
- The attribute to test.
private void _recordMirroredObjects(NamedObj pattern, NamedObj host)
pattern
- An object in the pattern.host
- An object in the host model corresponding to the object in
the pattern.private boolean _relink(Relation preserved, Relation removed)
preserved
- The preserved relation.removed
- The removed relation.
private void _removeLinks(CompositeEntity pattern)
pattern
- A container in the pattern that contains the links to be
removed.private java.util.Set<NamedObj> _removeObject(NamedObj object, boolean shallowRemoval) throws TransformationException
object
- The object in the host model to be removed.shallowRemoval
- Whether the removal is shallow. If it is and the
object to be removed is a CompositeEntity, then the entities and the
connections between them in the CompositeEntity are moved to the upper
level.
TransformationException
- If transformation is unsuccessful.private void _removeObjects(CompositeEntity host) throws TransformationException
host
- A container in the host model.
TransformationException
- If transformation is unsuccessful.private void _removeReplacementObjectAttributes(NamedObj object)
object
- The object whose ReplacementObjectAttributes need to be
removed.private void _removeReplacementToHostEntries(NamedObj host)
host
- A container in the host model.private void _replaceMatchResultEntries(NamedObj oldHost, NamedObj newHost)
oldHost
- The old host object.newHost
- The new host object.private void _setReplacementObjectAttribute(NamedObj object, java.lang.String replacementObjectCode) throws TransformationException
object
- An object in the host model.replacementObjectCode
- The code to be set in the
ReplacementObjectAttribute.
TransformationException
- If the attribute cannot be created.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |