Class ModelCommentsPersistencer

java.lang.Object
net.ssehub.easy.varModel.management.ModelCommentsPersistencer

public class ModelCommentsPersistencer extends 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
  • Field Details

    • repository

      private net.ssehub.easy.basics.modelManagement.IModelManagementRepository<Project> repository
  • Constructor Details

    • ModelCommentsPersistencer

      ModelCommentsPersistencer(net.ssehub.easy.basics.modelManagement.IModelManagementRepository<Project> repository)
      Prevents creating instances from outside this package.
      Parameters:
      repository - the repository instance for callbacks
  • Method Details

    • storeComments

      public boolean storeComments(net.ssehub.easy.basics.modelManagement.ModelInfo<Project> info) throws 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:
      IOException - in case that writing of the comments resource caused an error
    • storeComments

      public boolean storeComments(net.ssehub.easy.basics.modelManagement.ModelInfo<Project> info, boolean considerImports) throws 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:
      IOException - in case that writing of the comments resource caused an error
    • loadComments

      void loadComments(net.ssehub.easy.basics.modelManagement.ModelInfo<Project> info) throws 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:
      IOException - in case that reading the comments resource caused an error
    • getComments

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

      private static CommentResource getComments(net.ssehub.easy.basics.modelManagement.ModelInfo<Project> info) throws 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:
      IOException - in case of I/O problems
    • readResourceFromFile

      private static void readResourceFromFile(CommentResource resource, File file) throws IOException
      Reads the comment resource from the given file.
      Parameters:
      resource - the resource to be modified
      file - the file
      Throws:
      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 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