Class PlatformSettings

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected RwAutoLock lock
      Locking mechanism.
      protected boolean readonly
      Read-only flag.
      protected java.io.File settingsdir
      The settings dir.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object fromJson​(java.lang.String json)
      Converts JSON to object.
      byte[] loadFile​(java.lang.String filename)
      Directly loads a file from the settings directory.
      java.lang.Object loadState​(java.lang.String id)
      Loads arbitrary state form a persistent directory.
      void saveFile​(java.lang.String filename, byte[] content)
      Directly saves a file in the settings directory.
      void saveState​(java.lang.String id, java.lang.Object state)
      Saves arbitrary state to a persistent directory as JSON.
      static java.lang.String toJson​(java.lang.Object object)
      Converts object to JSON.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • settingsdir

        protected java.io.File settingsdir
        The settings dir.
      • readonly

        protected boolean readonly
        Read-only flag.
      • lock

        protected RwAutoLock lock
        Locking mechanism.
    • Constructor Detail

      • PlatformSettings

        public PlatformSettings​(IComponentIdentifier id,
                                boolean readonly)
        Creates the settings manager.
    • Method Detail

      • saveState

        public void saveState​(java.lang.String id,
                              java.lang.Object state)
        Saves arbitrary state to a persistent directory as JSON. Object must be serializable and the ID must be unique.
        Specified by:
        saveState in interface IPlatformSettings
        Parameters:
        id - Unique ID for the saved state.
        state - The state being saved.
      • loadState

        public java.lang.Object loadState​(java.lang.String id)
        Loads arbitrary state form a persistent directory.
        Specified by:
        loadState in interface IPlatformSettings
        Parameters:
        id - Unique ID for the saved state.
        Returns:
        The state or null if none was found or corrupt.
      • saveFile

        public void saveFile​(java.lang.String filename,
                             byte[] content)
        Directly saves a file in the settings directory.
        Specified by:
        saveFile in interface IPlatformSettings
        Parameters:
        filename - Name of the file.
        content - The file content.
      • loadFile

        public byte[] loadFile​(java.lang.String filename)
        Directly loads a file from the settings directory.
        Specified by:
        loadFile in interface IPlatformSettings
        Parameters:
        filename - Name of the file.
        Returns:
        Content of the file or null if not found.
      • toJson

        public static final java.lang.String toJson​(java.lang.Object object)
        Converts object to JSON.
        Parameters:
        object - Object.
        Returns:
        JSON string.
      • fromJson

        public static final java.lang.Object fromJson​(java.lang.String json)
        Converts JSON to object.
        Parameters:
        json - JSON.
        Returns:
        Object.