Coverage details for ui.command.IO.ExitCommand

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 package ui.command.IO;
21  
22 import java.io.File;
23 import java.io.PrintStream;
24  
25 import javax.swing.JOptionPane;
26 import javax.xml.parsers.DocumentBuilderFactory;
27 import javax.xml.transform.Transformer;
28 import javax.xml.transform.TransformerFactory;
29 import javax.xml.transform.dom.DOMSource;
30 import javax.xml.transform.stream.StreamResult;
31  
32 import org.apache.log4j.Logger;
33 import org.w3c.dom.Document;
34  
35 import ui.Messages;
36 import ui.command.Command;
37 import ui.command.CommandExecutor;
38 import base.ConfigurationManager;
39 import base.InternetCafe;
400import base.InternetCafeManager;
410 
420public class ExitCommand extends Command {
430 
440    private static final transient Logger logger = Logger
450            .getLogger(ExitCommand.class.getName());
460 
470    private boolean saveChanges = true;
480 
490    public void prologo() {
500        InternetCafe.setStatusBarMessage(Messages.getString("command.exitcommand.exiting")); //$NON-NLS-1$
510        Object[] options = { Messages.getString("command.option.exit.yesdiscard"), //$NON-NLS-1$
520                Messages.getString("command.option.exit.yessaving"), Messages.getString("command.option.exit.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$
530        int result = JOptionPane.showOptionDialog(null,
540                Messages.getString("command.exitcommand.message1"), Messages.getString("common.exit"), //$NON-NLS-1$ //$NON-NLS-2$
550                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
560                null, options, options[1]);
570        if (result == JOptionPane.YES_OPTION) {
580            saveChanges = false;
590            setStatus(EXECUTE_STATUS);
600        } else if (result == JOptionPane.NO_OPTION) {
610            saveChanges = true;
620            setStatus(EXECUTE_STATUS);
630        } else
640            setStatus(ABORT_STATUS);
650    }
660 
670    public void execution() throws Exception {
680        switch (getStatus()) {
690        case ABORT_STATUS:
700            break;
710        case VETOED_STATUS:
720            break;
730        case EXECUTE_STATUS:
740            if (saveChanges) {
750                try {
760                    // Save the current configuration...
770                    File configurationFile = new File(
780                            ConfigurationManager.CONFIGURATION_FILE);
790                    if (configurationFile.exists()) {
800                        configurationFile.delete();
810                        configurationFile.createNewFile();
820                    }
830                    Document doc = DocumentBuilderFactory.newInstance()
840                            .newDocumentBuilder().newDocument();
850                    doc.appendChild(ConfigurationManager.getInstance().toXml(
860                            doc));
870                    String fileName = configurationFile.getAbsolutePath();
880                    if (!fileName.endsWith("."+Messages.getString("common.filetype.xml"))) //$NON-NLS-1$ //$NON-NLS-2$
890                        fileName += "."+Messages.getString("common.filetype.xml"); //$NON-NLS-1$ //$NON-NLS-2$
900                    Transformer transformer = TransformerFactory.newInstance()
910                            .newTransformer();
920                    DOMSource source = new DOMSource(doc);
930                    StreamResult streamResult = new StreamResult(
940                            new PrintStream(fileName));
950                    transformer.transform(source, streamResult);
960 
970                    // We must save all to the database
980                    InternetCafeManager.getInstance().store();
990                    
1000                    //If JDBS is integrated we must call its ExitCommand
1010                    CommandExecutor.getInstance().executeCommand(new base.jdbs.ui.command.ExitCommand(),true);
1020                    
1030                    setStatus(SUCCESS_STATUS);
1040                    System.exit(0);
1050                } catch (Exception ex) {
1060                    logger.error(ex.getMessage());
1070                    ex.printStackTrace();
1080                    setStatus(ERROR_STATUS);
109                     
1100                }
1110            } else{
1120                setStatus(SUCCESS_STATUS);
1130                System.exit(0);
114             }
1150            break;
1160        }
1170    }
1180}

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.