Class GraphTransformer


  • public class GraphTransformer
    extends ChangeRequest
    Model transformation with a given match of the pattern. The transformation is implemented as a ChangeRequest, so its execution can be deferred. When it is executed, it generates a bunch of MoMLChangeRequests 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)
    • 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

      • 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.
      • 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.
      • _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.