esmska.persistence
Class PersistenceManager

java.lang.Object
  extended by esmska.persistence.PersistenceManager

public class PersistenceManager
extends java.lang.Object

Load and store settings and data


Method Summary
 void backupConfigFiles()
          Proceed with a backup.
static boolean canWrite(java.io.File file)
          Test if it is possible to write to a certain file/directory.
static java.io.File getConfigDir()
          Get configuration directory
static java.io.File getDataDir()
          Get data directory
 java.io.File getLogFile()
          Get file used for logging
static void instantiate()
          Create instance of PersistenceManager.
 boolean isFirstInstance()
          Checks if this is the first instance of the program.
 void loadConfig()
          Load program configuration
 void loadContacts()
          Load contacts
 void loadGatewayProperties()
          Load gateway properties.
 void loadGateways()
          Load gateways
 void loadHistory()
          Load sms history
 void loadKeyring()
          Load keyring.
 void loadQueue()
          Load sms queue
 void saveConfig()
          Save program configuration
 void saveContacts()
          Save contacts
 void saveGateway(java.lang.String scriptName, java.lang.String scriptContents, byte[] icon)
          Save new gateway to file.
 void saveGatewayProperties()
          Save gateway properties.
 void saveHistory()
          Save sms history
 void saveKeyring()
          Save keyring.
 void saveQueue()
          Save sms queue
static void setCustomDirs(java.lang.String configDir, java.lang.String dataDir)
          Set custom directories
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.IOException
Create 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.IOException
Save program configuration

Throws:
java.io.IOException

loadConfig

public void loadConfig()
                throws java.lang.Exception
Load program configuration

Throws:
java.lang.Exception

saveContacts

public void saveContacts()
                  throws java.io.IOException
Save contacts

Throws:
java.io.IOException

loadContacts

public void loadContacts()
                  throws java.lang.Exception
Load contacts

Throws:
java.lang.Exception

saveQueue

public void saveQueue()
               throws java.io.IOException
Save sms queue

Throws:
java.io.IOException

loadQueue

public void loadQueue()
               throws java.lang.Exception
Load sms queue

Throws:
java.lang.Exception

saveHistory

public void saveHistory()
                 throws java.io.IOException
Save sms history

Throws:
java.io.IOException

loadHistory

public void loadHistory()
                 throws java.lang.Exception
Load sms history

Throws:
java.lang.Exception

saveKeyring

public void saveKeyring()
                 throws java.lang.Exception
Save keyring.

Throws:
java.lang.Exception

loadKeyring

public void loadKeyring()
                 throws java.lang.Exception
Load keyring.

Throws:
java.lang.Exception

loadGateways

public void loadGateways()
                  throws java.io.IOException,
                         java.beans.IntrospectionException,
                         org.xml.sax.SAXException
Load gateways

Throws:
java.io.IOException - When there is problem accessing gateway directory or files
java.beans.IntrospectionException - When current JRE does not support JavaScript execution
org.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.IOException
Save 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 empty
scriptContents - contents of the gateway script file, not null nor empty
icon - gateway icon, may be null
Throws:
java.io.IOException

loadGatewayProperties

public void loadGatewayProperties()
                           throws java.lang.Exception
Load gateway properties.

Throws:
java.lang.Exception

saveGatewayProperties

public void saveGatewayProperties()
                           throws java.lang.Exception
Save 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.IOException
Proceed 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