Class ModelCommentsPersistencer


  • public class ModelCommentsPersistencer
    extends java.lang.Object
    Implements (internationalized) comment persistence mechanisms on model level. Instances of this class cannot be created directly rather than being obtained from VarModel.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • ModelCommentsPersistencer

        ModelCommentsPersistencer​(IModelManagementRepository<Project> repository)
        Prevents creating instances from outside this package.
        Parameters:
        repository - the repository instance for callbacks
    • Method Detail

      • storeComments

        public boolean storeComments​(ModelInfo<Project> info)
                              throws java.io.IOException
        Stores the comments stored in the resolved project of info. Existing data will be overwritten. Currently, this method considers only containable model elements.
        Parameters:
        info - the project information the comments shall be stored for
        Returns:
        true if the comments have been stored, false if no exception occurred but also the data was not stored, e.g. because info is not resolved or ModelInfo.getCommentsResource() is invalid
        Throws:
        java.io.IOException - in case that writing of the comments resource caused an error
      • storeComments

        public boolean storeComments​(ModelInfo<Project> info,
                                     boolean considerImports)
                              throws java.io.IOException
        Stores the comments stored in the resolved project of info and optionally for all imported projects. Existing data will be overwritten. Currently, this method considers only containable model elements.
        Parameters:
        info - the project information the comments shall be stored for
        considerImports - consider also (resolved) imported projects
        Returns:
        true if the comments have been stored, false if no exception occurred but also the data was not stored, e.g. because info is not resolved or ModelInfo.getCommentsResource() is invalid
        Throws:
        java.io.IOException - in case that writing of the comments resource caused an error
      • loadComments

        void loadComments​(ModelInfo<Project> info)
                   throws java.io.IOException
        Loads comments from the resolved project of info. Existing comments in the related project will be overridden. This method affects only the directly related project!
        Parameters:
        info - the information object to load comments for
        Throws:
        java.io.IOException - in case that reading the comments resource caused an error
      • getComments

        public static CommentResource getComments​(Project project)
                                           throws java.io.IOException
        Returns the comment resource for the given project.
        Parameters:
        project - the project
        Returns:
        the comment resource, may be null
        Throws:
        java.io.IOException - in case of I/O problems
      • getComments

        private static CommentResource getComments​(ModelInfo<Project> info)
                                            throws java.io.IOException
        Determines the comment resource for the specified model information object/project.
        Parameters:
        info - the model information object
        Returns:
        the comment resource, may be null
        Throws:
        java.io.IOException - in case of I/O problems
      • readResourceFromFile

        private static void readResourceFromFile​(CommentResource resource,
                                                 java.io.File file)
                                          throws java.io.IOException
        Reads the comment resource from the given file.
        Parameters:
        resource - the resource to be modified
        file - the file
        Throws:
        java.io.IOException - in case of I/O problems
      • assignCommentsToProject

        private void assignCommentsToProject​(Project project,
                                             CommentResource props)
        Assign the comments stored in props to the containable model elements in project.
        Parameters:
        project - the project to assign the comments to (may be modified as a side effect)
        props - the properties containing the comments (fqn-comment mapping)
      • assignComments

        private void assignComments​(IDecisionVariableContainer container,
                                    CommentResource props)
        Assign the comments stored in props to the model elements in container.
        Parameters:
        container - the container to assign the comments to (may be modified as a side effect)
        props - the properties containing the comments (fqn-comment mapping)
      • assignComment

        private void assignComment​(ContainableModelElement elt,
                                   CommentResource props)
        Assigns a comment from props (if exists) to elt.
        Parameters:
        elt - the element to assign to (modified as a side effect)
        props - the comment resource containing the comments
      • getKey

        public static java.lang.String getKey​(Constraint cons)
        Returns the key for a constraint.
        Parameters:
        cons - the key
        Returns:
        the constraint key, may be empty for none, e.g., if cons is null