bootstrapP
Class FileBackupper

java.lang.Object
  extended by bootstrapP.FileBackupper
All Implemented Interfaces:
BackupperInterface

public class FileBackupper
extends java.lang.Object
implements BackupperInterface

An implementation of a backupper that works on a single file.

Author:
Marco Cornolti

Field Summary
private  java.io.File bkFile
           
 
Constructor Summary
FileBackupper(java.lang.String backupFilePath)
          The file backupper constructor.
 
Method Summary
 void backupMs(ManagedMessageServer ms)
          Backup a single server data.
 void backupSingleData(java.lang.Object obj, boolean remove)
          Backups or removes a single data from the file.
 void backupUser(RegisteredUser reg)
          Backup a single user data.
 void backupWholeData(java.util.List<RegisteredUser> rUsers, java.util.List<ManagedMessageServer> mMss)
          Backups the whole data given by argument replacing completely the previous backups.
 java.lang.String getFilename()
          Get the file name of the backupper.
 void removeBackuppedMs(ManagedMessageServer ms)
          Remove a server contained in the backup.
 void removeBackuppedUser(RegisteredUser reg)
          Remove a user contained in the backup.
 int restoreData(java.util.List<RegisteredUser> restoredUsers, java.util.List<ManagedMessageServer> restoredMss)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bkFile

private java.io.File bkFile
Constructor Detail

FileBackupper

public FileBackupper(java.lang.String backupFilePath)
The file backupper constructor.

Parameters:
backupFilePath - the file path to backup the data to.
Method Detail

getFilename

public java.lang.String getFilename()
Get the file name of the backupper.

Returns:
the backupper file name.

backupWholeData

public void backupWholeData(java.util.List<RegisteredUser> rUsers,
                            java.util.List<ManagedMessageServer> mMss)
                     throws java.io.IOException
Description copied from interface: BackupperInterface
Backups the whole data given by argument replacing completely the previous backups.

Specified by:
backupWholeData in interface BackupperInterface
Parameters:
rUsers - the list of registered users to backup.
mMss - the list of managed message servers to backup.
Throws:
java.io.IOException - if an Input/Output problem occurred.

backupSingleData

public void backupSingleData(java.lang.Object obj,
                             boolean remove)
                      throws java.io.IOException
Backups or removes a single data from the file.

Parameters:
obj - the object to backup.
remove - true if the object must be removed from the backup file, false if the object must be saved.
Throws:
java.io.IOException - if an Input/Output problem occurred.

backupMs

public void backupMs(ManagedMessageServer ms)
              throws java.io.IOException
Description copied from interface: BackupperInterface
Backup a single server data.

Specified by:
backupMs in interface BackupperInterface
Parameters:
ms - the server whose data must be backupped.
Throws:
java.io.IOException - if an error occured while writing.

backupUser

public void backupUser(RegisteredUser reg)
                throws java.io.IOException
Description copied from interface: BackupperInterface
Backup a single user data.

Specified by:
backupUser in interface BackupperInterface
Parameters:
reg - the user whose data must be backupped.
Throws:
java.io.IOException - if an error occured while writing.

removeBackuppedMs

public void removeBackuppedMs(ManagedMessageServer ms)
                       throws java.io.IOException
Description copied from interface: BackupperInterface
Remove a server contained in the backup.

Specified by:
removeBackuppedMs in interface BackupperInterface
Parameters:
ms - the server to remove.
Throws:
java.io.IOException - if an InputOutput exception occurred.

removeBackuppedUser

public void removeBackuppedUser(RegisteredUser reg)
                         throws java.io.IOException
Description copied from interface: BackupperInterface
Remove a user contained in the backup.

Specified by:
removeBackuppedUser in interface BackupperInterface
Parameters:
reg - the user to remove.
Throws:
java.io.IOException - if an InputOutput exception occurred.

restoreData

public int restoreData(java.util.List<RegisteredUser> restoredUsers,
                       java.util.List<ManagedMessageServer> restoredMss)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException,
                       java.io.InvalidClassException,
                       java.io.StreamCorruptedException,
                       java.io.OptionalDataException,
                       java.lang.IllegalArgumentException
Specified by:
restoreData in interface BackupperInterface
Parameters:
restoredUsers - a list where the restored users data must be copied to.
restoredMss - a list where the restored servers data must be copied to.
Returns:
the number of read datas (message servers + users).
Throws:
java.io.IOException - if an Input/Output problem occurred.
java.io.InvalidClassException - if a version compatibility problem occurred.
java.io.StreamCorruptedException - if the input stream could not be read.
java.io.OptionalDataException - if the backupped datas were not expected.
java.lang.ClassNotFoundException - if a version compatibility problem occurred.
java.lang.IllegalArgumentException - if the lists given by argument are null or not empty.