Package esmska.persistence
Class PersistenceManager
- java.lang.Object
-
- esmska.persistence.PersistenceManager
-
public class PersistenceManager extends java.lang.ObjectLoad and store settings and data
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackupConfigFiles()Proceed with a backup.static booleancanWrite(java.io.File file)Test if it is possible to write to a certain file/directory.static java.io.FilegetConfigDir()Get configuration directorystatic java.io.FilegetDataDir()Get data directoryjava.io.FilegetLogFile()Get file used for loggingstatic voidinstantiate()Create instance of PersistenceManager.booleanisFirstInstance()Checks if this is the first instance of the program.voidloadConfig()Load program configurationvoidloadContacts()Load contactsvoidloadGatewayProperties()Load gateway properties.voidloadGateways()Load gatewaysvoidloadHistory()Load sms historyvoidloadKeyring()Load keyring.voidloadQueue()Load sms queuevoidsaveConfig()Save program configurationvoidsaveContacts()Save contactsvoidsaveGateway(java.lang.String scriptName, java.lang.String scriptContents, byte[] icon)Save new gateway to file.voidsaveGatewayProperties()Save gateway properties.voidsaveHistory()Save sms historyvoidsaveKeyring()Save keyring.voidsaveQueue()Save sms queuestatic voidsetCustomDirs(java.lang.String configDir, java.lang.String dataDir)Set custom directories
-
-
-
Method Detail
-
getConfigDir
public static java.io.File getConfigDir()
Get configuration directory
-
getDataDir
public static java.io.File getDataDir()
Get data directory
-
setCustomDirs
public static void setCustomDirs(java.lang.String configDir, java.lang.String dataDir)Set custom directories
-
instantiate
public static void instantiate() throws java.io.IOExceptionCreate instance of PersistenceManager. Should be called only for inicialization, after that the instance is available in the Context.- Throws:
java.io.IOException- could not read/write configuration files/directories
-
getLogFile
public java.io.File getLogFile()
Get file used for logging
-
saveConfig
public void saveConfig() throws java.io.IOExceptionSave program configuration- Throws:
java.io.IOException
-
loadConfig
public void loadConfig() throws java.lang.ExceptionLoad program configuration- Throws:
java.lang.Exception
-
saveContacts
public void saveContacts() throws java.io.IOExceptionSave contacts- Throws:
java.io.IOException
-
loadContacts
public void loadContacts() throws java.lang.ExceptionLoad contacts- Throws:
java.lang.Exception
-
saveQueue
public void saveQueue() throws java.io.IOExceptionSave sms queue- Throws:
java.io.IOException
-
loadQueue
public void loadQueue() throws java.lang.ExceptionLoad sms queue- Throws:
java.lang.Exception
-
saveHistory
public void saveHistory() throws java.io.IOExceptionSave sms history- Throws:
java.io.IOException
-
loadHistory
public void loadHistory() throws java.lang.ExceptionLoad sms history- Throws:
java.lang.Exception
-
saveKeyring
public void saveKeyring() throws java.lang.ExceptionSave keyring.- Throws:
java.lang.Exception
-
loadKeyring
public void loadKeyring() throws java.lang.ExceptionLoad keyring.- Throws:
java.lang.Exception
-
loadGateways
public void loadGateways() throws java.io.IOException, java.beans.IntrospectionException, org.xml.sax.SAXExceptionLoad gateways- Throws:
java.io.IOException- When there is problem accessing gateway directory or filesjava.beans.IntrospectionException- When current JRE does not support JavaScript executionorg.xml.sax.SAXException- When related XML files are not valid
-
saveGateway
public void saveGateway(java.lang.String scriptName, java.lang.String scriptContents, byte[] icon) throws java.io.IOExceptionSave new gateway to file. New or updated gateway is saved in global gateway directory (if there are sufficient permissions), otherwise in local gateway directory.- Parameters:
scriptName- name of the gateway/script (without suffix), not null nor emptyscriptContents- contents of the gateway script file, not null nor emptyicon- gateway icon, may be null- Throws:
java.io.IOException
-
loadGatewayProperties
public void loadGatewayProperties() throws java.lang.ExceptionLoad gateway properties.- Throws:
java.lang.Exception
-
saveGatewayProperties
public void saveGatewayProperties() throws java.lang.ExceptionSave gateway properties.- Throws:
java.lang.Exception
-
isFirstInstance
public boolean isFirstInstance()
Checks if this is the first instance of the program. Manages instances by using an exclusive lock on a file.- Returns:
- true if this is the first instance run; false otherwise
-
backupConfigFiles
public void backupConfigFiles() throws java.io.IOExceptionProceed with a backup. Backs up today's configuration (if not backed up already). Preserves last 7 backups, older ones are deleted.- Throws:
java.io.IOException
-
canWrite
public static boolean canWrite(java.io.File file)
Test if it is possible to write to a certain file/directory. It doesn't have to exist. This method is available because of Java bug on Windows which does not check permissions in File.canWrite() but only read-only bit (reference1, reference2).- Parameters:
file- File, existing or not existing; not null- Returns:
- true if file can be written, false if not
-
-