Coverage details for ui.command.IO.LoadBackupCommand

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20  
21 package ui.command.IO;
22  
230import java.io.File;
24  
250import javax.swing.JFileChooser;
26  
27 import org.apache.log4j.Logger;
28  
29 import ui.Messages;
30 import ui.command.Command;
31 import ui.util.FileExtensionFilter;
32 import base.InternetCafe;
33 import base.InternetCafeManager;
34 import base.backup.Backup;
35 import base.backup.BackupFactory;
36  
370/**
380 * @author skunk
390 *
400 */
410public class LoadBackupCommand extends Command {
420 
430    private static final transient Logger logger = Logger
440            .getLogger(LoadBackupCommand.class.getName());
450 
460    private File backupFile;
470 
480    /*
490     * (non-Javadoc)
50      *
51      * @see ui.command.Command#prologo()
52      */
53     @Override
540    protected void prologo() {
550        InternetCafe.setStatusBarMessage(Messages.getString("command.loadbackupcommand.loadingbackup")); //$NON-NLS-1$
560        JFileChooser chooser = new JFileChooser();
570        chooser.setDialogTitle(Messages.getString("command.loadbackupcommand.loadbackup")); //$NON-NLS-1$
580        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
590        chooser.setApproveButtonText(Messages.getString("button.load")); //$NON-NLS-1$
600        chooser.setFileFilter(new FileExtensionFilter(Messages.getString("common.filetype.zip"), //$NON-NLS-1$
610                Messages.getString("common.filetype.zip"))); //$NON-NLS-1$
620        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
630            backupFile = new File(chooser.getSelectedFile().getAbsolutePath());
640            setStatus(EXECUTE_STATUS);
650        } else
660            setStatus(ABORT_STATUS);
670    }
680 
690    /*
700     * (non-Javadoc)
71      *
720     * @see ui.command.Command#execution()
730     */
74     @Override
750    protected void execution() throws Exception {
760        switch (getStatus()) {
770        case ABORT_STATUS:
780            break;
790        case VETOED_STATUS:
800            break;
810        case EXECUTE_STATUS:
820            Backup backup = null;
830            try {
840                backup = BackupFactory.newBackupFromZipArchive(backupFile);
850                InternetCafeManager.getInstance().addBackup(backup);
860            } catch (Exception ex) {
870                logger.error(ex.getMessage());
880                ex.printStackTrace();
890            } finally {
900                if (backup != null)
910                    setStatus(SUCCESS_STATUS);
920                else
930                    setStatus(ERROR_STATUS);
940            }
95             break;
960        }
970    }
98 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.