Class Patch


  • public class Patch
    extends Object
    The Class Patch storing all operations necessary to transfer one document into another.
    Author:
    Martin Scharm
    See Also:
    delta documentation
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static URI PATCH_FILE_NAME
      The default file name of the path.
    • Constructor Summary

      Constructors 
      Constructor Description
      Patch()
      Instantiates a new patch.
      Patch​(boolean fullDiff)
      Instantiates a new patch specifying the fullDiff flag.
      Patch​(boolean fullDiff, DiffAnnotator diffAnnotator)
      Instantiates a new patch specifying the fullDiff flag and an annotator to annotate the differences.
      Patch​(boolean fullDiff, URI patchFileName)
      Instantiates a new patch specifying the fullDiff flag and the file name of the resulting patch.
      Patch​(boolean fullDiff, URI patchFileName, DiffAnnotator diffAnnotator)
      Instantiates a new patch specifying the fullDiff flag, the file name of the resulting patch, and an annotator to annotate the differences.
      Patch​(DiffAnnotator diffAnnotator)
      Instantiates a new patch specifying.
      Patch​(URI patchFileName)
      Instantiates a new patch specifying the file name of the resulting patch.
      Patch​(URI patchFileName, DiffAnnotator diffAnnotator)
      Instantiates a new patch specifying the file name of the resulting patch and an annotator to annotate the differences.
    • Field Detail

      • PATCH_FILE_NAME

        public static URI PATCH_FILE_NAME
        The default file name of the path. This name will be used in the annotations to refer to elements in the path file.
    • Constructor Detail

      • Patch

        public Patch​(URI patchFileName,
                     DiffAnnotator diffAnnotator)
        Instantiates a new patch specifying the file name of the resulting patch and an annotator to annotate the differences. This will result in a patch of type fullDiff.
        Parameters:
        patchFileName - the file name of the final patch
        diffAnnotator - the annotator for detected differences
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(DiffAnnotator diffAnnotator)
        Instantiates a new patch specifying. an annotator to annotate the differences. This constructor assumes that the final patch will be called PATCH_FILE_NAME. This will result in a patch of type fullDiff.
        Parameters:
        diffAnnotator - the annotator for detected differences
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(boolean fullDiff,
                     URI patchFileName,
                     DiffAnnotator diffAnnotator)
        Instantiates a new patch specifying the fullDiff flag, the file name of the resulting patch, and an annotator to annotate the differences. If the fullDiff flag is set to false only a partially delta will be generated. Thus, the delta will briefly describe the modifications, but cannot be used to transform one version of a document into the other. Set it to true to obtain a full delta.
        Parameters:
        fullDiff - the fullDiff flag
        patchFileName - the file name of the final patch
        diffAnnotator - the annotator for detected differences
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(boolean fullDiff,
                     DiffAnnotator diffAnnotator)
        Instantiates a new patch specifying the fullDiff flag and an annotator to annotate the differences. If the fullDiff flag is set to false only a partial delta will be generated. Thus, the delta will briefly describe the modifications, but cannot be used to transform one version of a document into the other. Set it to true to obtain a full delta. This constructor assumes that the final patch will be called PATCH_FILE_NAME.
        Parameters:
        fullDiff - the fullDiff flag
        diffAnnotator - the annotator for detected differences
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(URI patchFileName)
        Instantiates a new patch specifying the file name of the resulting patch. This constructor assumes that the final patch will be called PATCH_FILE_NAME. To annotate the differences a new instance of the DefaultDiffAnnotator will be created. This will result in a patch of type fullDiff.
        Parameters:
        patchFileName - the file name of the final patch
        See Also:
        fullDiff documentation
      • Patch

        public Patch()
        Instantiates a new patch. This constructor assumes that the final patch will be called PATCH_FILE_NAME. To annotate the differences a new instance of the DefaultDiffAnnotator will be created. This will result in a patch of type fullDiff.
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(boolean fullDiff,
                     URI patchFileName)
        Instantiates a new patch specifying the fullDiff flag and the file name of the resulting patch. If the fullDiff flag is set to false only a partial delta will be generated. Thus, the delta will briefly describe the modifications, but cannot be used to transform one version of a document into the other. Set it to true to obtain a full delta. To annotate the differences a new instance of the DefaultDiffAnnotator will be created.
        Parameters:
        fullDiff - the fullDiff flag
        patchFileName - the file name of the final patch
        See Also:
        fullDiff documentation
      • Patch

        public Patch​(boolean fullDiff)
        Instantiates a new patch specifying the fullDiff flag. If the fullDiff flag is set to false only a partial delta will be generated. Thus, the delta will briefly describe the modifications, but cannot be used to transform one version of a document into the other. Set it to true to obtain a full delta. This constructor assumes that the final patch will be called PATCH_FILE_NAME. To annotate the differences a new instance of the DefaultDiffAnnotator will be created.
        Parameters:
        fullDiff - the fullDiff flag
        See Also:
        fullDiff documentation
    • Method Detail

      • getNumMoves

        public int getNumMoves()
        Gets the number of stored move operations.
        Returns:
        the number of moves
      • getNumUpdates

        public int getNumUpdates()
        Gets the number of stored update operations.
        Returns:
        the number of updates
      • getNumDeletes

        public int getNumDeletes()
        Gets the number of stored delete operations.
        Returns:
        the number of deletes
      • getNumInserts

        public int getNumInserts()
        Gets the number of stored insert operations.
        Returns:
        the number of inserts
      • getDeletes

        public org.jdom2.Element getDeletes()
        Gets the deletes.
        Returns:
        the deletes
      • getInserts

        public org.jdom2.Element getInserts()
        Gets the inserts.
        Returns:
        the inserts
      • getUpdates

        public org.jdom2.Element getUpdates()
        Gets the updates.
        Returns:
        the updates
      • getMoves

        public org.jdom2.Element getMoves()
        Gets the moves.
        Returns:
        the moves
      • getNumNodeChanges

        public int getNumNodeChanges()
        Gets the number of node changes. That is the number of differences in this patch that affect XML nodes.
        Returns:
        the number of node changes
      • getNumTextChanges

        public int getNumTextChanges()
        Gets the number of text changes. That is the number of differences in this patch that affect XML text nodes.
        Returns:
        the number of text changes
      • getNumAttributeChanges

        public int getNumAttributeChanges()
        Gets the number of attribute changes. That is the number of differences in this patch that affect XML attributes.
        Returns:
        the number of attribute changes
      • getDocument

        public org.jdom2.Document getDocument​(boolean inclAnnotations)
        Gets the document containing all changes. If inclAnnotations is set to true the patch will have an embedded RDF subtree with annotations of the differences.
        Parameters:
        inclAnnotations - should the annotations be embedded into the patch
        Returns:
        the document
      • getNumAnnotations

        public int getNumAnnotations()
        Gets the number of annotations for the differences in this patch.
        Returns:
        the number annotations
      • getDocument

        public org.jdom2.Document getDocument()
        Gets the document containing all changes.
        Returns:
        the document
      • getAnnotationDocumentXml

        public String getAnnotationDocumentXml()
        Gets the annotation document encoded in XML.
        Returns:
        the annotation document
      • getAnnotations

        public de.unirostock.sems.comodi.ChangeFactory getAnnotations()
        Gets the actual annotations.
        Returns:
        the annotations
      • deleteSubtree

        public void deleteSubtree​(de.unirostock.sems.xmlutils.ds.TreeNode toDelete,
                                  int chainId)
        Mark a whole subtree as deleted.
        Parameters:
        toDelete - the node rooting the subtree to delete
        chainId - the chain id: id of the trigger, if this modification was triggered, or <1 otherwise
      • deleteNode

        public void deleteNode​(de.unirostock.sems.xmlutils.ds.TreeNode toDelete,
                               int chainId)
        Delete a single node.
        Parameters:
        toDelete - the node to delete
        chainId - the chain id: id of the trigger, if this modification was triggered, or <1 otherwise
      • insertSubtree

        public void insertSubtree​(de.unirostock.sems.xmlutils.ds.TreeNode toInsert,
                                  int chainId)
        Mark a whole subtree as inserted.
        Parameters:
        toInsert - the node rooting the subtree to insert
        chainId - the chain id: id of the trigger, if this modification was triggered, or <1 otherwise
      • insertNode

        public void insertNode​(de.unirostock.sems.xmlutils.ds.TreeNode toInsert,
                               int chainId)
        Insert a single node.
        Parameters:
        toInsert - the node to insert
        chainId - the chain id: id of the trigger, if this modification was triggered, or <1 otherwise
      • insertNode

        public int insertNode​(de.unirostock.sems.xmlutils.ds.DocumentNode toInsert,
                              int chainId)
        Insert a single node.
        Parameters:
        toInsert - the document node to insert
        chainId - the chain id: id of the trigger, if this modification was triggered, or <1 otherwise
        Returns:
        the id of the insert-operation-node in the XML delta
      • updateNode

        public void updateNode​(NodeConnection c,
                               SimpleConnectionManager conMgmt)
        Update a node.
        Parameters:
        c - the connection between the old version of the node and the new version of it.
        conMgmt - the connection manager
      • annotatePatch

        public void annotatePatch()
        Annotate the whole patch.