Class SettingsManagerBase<T,​L extends SettingsListener>

  • Type Parameters:
    T - Settings JAXB Type
    L - Settings Listener Type

    public abstract class SettingsManagerBase<T,​L extends SettingsListener>
    extends Object
    Class which handels the settings
    • Field Detail

      • logger

        protected org.slf4j.Logger logger
        Logger for this class
      • jaxbContext

        protected final javax.xml.bind.JAXBContext jaxbContext
        JAXB Context
      • settings

        protected T settings
        Settings
      • settingsFolder

        protected final File settingsFolder
        Settings Folder
      • settingsFile

        protected final File settingsFile
        Settings File
      • settingsBackupFile

        protected final File settingsBackupFile
        Settings Backup File
      • defaultSettingsResourcePath

        protected final String defaultSettingsResourcePath
        Resource path to default settings file
      • settingsSchemaResourcePath

        protected final String settingsSchemaResourcePath
        Resource path to schema file
    • Constructor Detail

      • SettingsManagerBase

        protected SettingsManagerBase​(Class<?> objectFactoryClass,
                                      String defaultSettingsResourcePath,
                                      String settingsSchemaResourcePath)
                               throws javax.xml.bind.JAXBException
        Dummy Constructor. ONLY USE FOR UNIT TESTS.
        Parameters:
        objectFactoryClass - Object Factory Class
        defaultSettingsResourcePath - Resource path to default settings file
        settingsSchemaResourcePath - Resource path to schema file
        Throws:
        javax.xml.bind.JAXBException
      • SettingsManagerBase

        public SettingsManagerBase​(String strSettingsFolder,
                                   String strSettingsFilename,
                                   Class<?> objectFactoryClass,
                                   String defaultSettingsResourcePath,
                                   String settingsSchemaResourcePath)
                            throws javax.xml.bind.JAXBException
        Constructor
        Parameters:
        strSettingsFolder - Settings Folder
        strSettingsFilename - Settings Filename
        objectFactoryClass - Object Factory Class
        defaultSettingsResourcePath - Resource path to default settings file
        settingsSchemaResourcePath - Resource path to schema file
        Throws:
        javax.xml.bind.JAXBException
    • Method Detail

      • restoreSettingsFileFromBackupFile

        protected boolean restoreSettingsFileFromBackupFile()
        Restore settings file from backup file
        Returns:
        True if settings file could be restored, false otherwise
      • backupSettingsFile

        protected boolean backupSettingsFile()
        Backup settings file
        Returns:
        True if settings file could be backed up, false otherwise
      • createDirectoryIfNotExists

        protected boolean createDirectoryIfNotExists​(File directory)
        Create directory if it not exists
        Parameters:
        directory - Directory
        Returns:
        True if successful, false otherwise
      • loadDefaultSettingsFile

        protected T loadDefaultSettingsFile()
                                     throws IOException,
                                            SAXException,
                                            javax.xml.bind.JAXBException
        Load Default Settings File
        Returns:
        Settings
        Throws:
        IOException
        SAXException
        javax.xml.bind.JAXBException
      • loadSettingsFile

        protected T loadSettingsFile​(InputStream in,
                                     boolean validateSchema)
                              throws SAXException,
                                     javax.xml.bind.JAXBException
        Load Settings File
        Parameters:
        in - InputStream
        validateSchema - True if schema should be validated, false otherwise. Schema should only be validated for the default settings file and not for user settings files, because also settings files created with older versions of the program must be loaded.
        Returns:
        Settings
        Throws:
        SAXException
        javax.xml.bind.JAXBException
      • writeSettingsFile

        protected void writeSettingsFile​(T settings,
                                         OutputStream out,
                                         boolean validateSchema)
                                  throws SAXException,
                                         javax.xml.bind.JAXBException
        Write Settings File
        Parameters:
        settings - Settings
        out - OutputStream
        validateSchema - True if schema should be validated, false otherwise. Schema should only be validated for the default settings file and not for user settings files, because also settings files created with older versions of the program must be loaded.
        Throws:
        SAXException
        javax.xml.bind.JAXBException
      • settingsChanged

        protected void settingsChanged()
        Settings Changed
      • addSettingsListener

        public void addSettingsListener​(L l)
        Add listener
        Parameters:
        l - Listener
      • removeSettingsListener

        public void removeSettingsListener​(L l)
        Remove listener
        Parameters:
        l - Listener
      • getSettings

        public T getSettings()
        Returns the settings
        Returns:
        settings