Class SettingsManagerBase<T,L extends SettingsListener>
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.settings.SettingsManagerBase<T,L>
-
- Type Parameters:
T- Settings JAXB TypeL- Settings Listener Type
public abstract class SettingsManagerBase<T,L extends SettingsListener> extends Object
Class which handels the settings
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdefaultSettingsResourcePathResource path to default settings fileprotected javax.xml.bind.JAXBContextjaxbContextJAXB Contextprotected List<L>listenersListenerprotected org.slf4j.LoggerloggerLogger for this classprotected TsettingsSettingsprotected FilesettingsBackupFileSettings Backup Fileprotected FilesettingsFileSettings Fileprotected FilesettingsFolderSettings Folderprotected StringsettingsSchemaResourcePathResource path to schema file
-
Constructor Summary
Constructors Modifier Constructor Description protectedSettingsManagerBase(Class<?> objectFactoryClass, String defaultSettingsResourcePath, String settingsSchemaResourcePath)Dummy Constructor.SettingsManagerBase(String strSettingsFolder, String strSettingsFilename, Class<?> objectFactoryClass, String defaultSettingsResourcePath, String settingsSchemaResourcePath)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSettingsListener(L l)Add listenerprotected booleanbackupSettingsFile()Backup settings fileprotected booleancreateDirectoryIfNotExists(File directory)Create directory if it not existsTgetSettings()Returns the settingsprotected TloadDefaultSettingsFile()Load Default Settings Fileprotected TloadSettingsFile(InputStream in, boolean validateSchema)Load Settings Fileprotected TloadUserSettingsFile()Load User Settings FilevoidremoveSettingsListener(L l)Remove listenerprotected booleanrestoreSettingsFileFromBackupFile()Restore settings file from backup fileprotected voidsettingsChanged()Settings Changedprotected voidwriteSettingsFile(T settings, OutputStream out, boolean validateSchema)Write Settings File
-
-
-
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
-
listeners
protected List<L extends SettingsListener> listeners
Listener
-
-
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 ClassdefaultSettingsResourcePath- Resource path to default settings filesettingsSchemaResourcePath- 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 FolderstrSettingsFilename- Settings FilenameobjectFactoryClass- Object Factory ClassdefaultSettingsResourcePath- Resource path to default settings filesettingsSchemaResourcePath- 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
-
loadUserSettingsFile
protected T loadUserSettingsFile() throws IOException, SAXException, javax.xml.bind.JAXBException
Load User Settings File- Returns:
- Settings
- Throws:
IOExceptionSAXExceptionjavax.xml.bind.JAXBException
-
loadDefaultSettingsFile
protected T loadDefaultSettingsFile() throws IOException, SAXException, javax.xml.bind.JAXBException
Load Default Settings File- Returns:
- Settings
- Throws:
IOExceptionSAXExceptionjavax.xml.bind.JAXBException
-
loadSettingsFile
protected T loadSettingsFile(InputStream in, boolean validateSchema) throws SAXException, javax.xml.bind.JAXBException
Load Settings File- Parameters:
in- InputStreamvalidateSchema- 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:
SAXExceptionjavax.xml.bind.JAXBException
-
writeSettingsFile
protected void writeSettingsFile(T settings, OutputStream out, boolean validateSchema) throws SAXException, javax.xml.bind.JAXBException
Write Settings File- Parameters:
settings- Settingsout- OutputStreamvalidateSchema- 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:
SAXExceptionjavax.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
-
-