Coverage details for ui.command.IO.SaveClientWorkstationCommand

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.net.Inet4Address;
23  
24 import ui.command.Command;
25 import ui.panel.WorkstationPanel;
26 import base.Control;
27 import base.network.NetworkManager;
28 import base.network.Workstation;
29 import base.network.WorkstationFactory;
30  
31 public class SaveClientWorkstationCommand extends Command {
32  
33     private WorkstationPanel workstationPanel;
34  
35     private Workstation workstation;
36  
37     private boolean createWorkstation;
38  
39     private String name;
40  
41     private String type;
42  
43     private String location;
44  
45     private String description;
46  
47     private Inet4Address address;
48  
49     private int port;
50  
51     private boolean inUse;
52  
53     /**
54      * @param workstationPanel
55      * @param workstation
56      * @param createWorkstation
57      */
58     public SaveClientWorkstationCommand(WorkstationPanel workstationPanel,
59             Workstation workstation, boolean createWorkstation) {
600        super();
610        // TODO Auto-generated constructor stub
620        this.workstationPanel = workstationPanel;
630        this.workstation = workstation;
640        this.createWorkstation = createWorkstation;
650    }
660 
67     /*
68      * (non-Javadoc)
69      *
70      * @see ui.command.Command#prologo()
71      */
72     @Override
73     protected void prologo() {
740        name = getWorkstationPanel().getWorkstationName();
750        type = getWorkstationPanel().getWorkstationType();
760        location = getWorkstationPanel().getWorkstationLocation();
770        description = getWorkstationPanel().getWorkstationDescription();
780        address = getWorkstationPanel().getWorkstationAddress();
790        port = getWorkstationPanel().getWorkstationPort();
800        inUse = getWorkstationPanel().getWorkstationInUse();
810 
820        if (isValidWorkstationData(name, type, location, description, address,
830                port, inUse))
840            setStatus(EXECUTE_STATUS);
850        else
860            setStatus(ERROR_STATUS);
870    }
880 
89     private boolean isValidWorkstationData(String name, String type,
90             String location, String description, Inet4Address address,
91             int port, boolean inUse) {
920        if (name == null || name.length() == 0) {
930            this.getWorkstationPanel().setNameError(true);
940            return false;
950        } else
960            this.getWorkstationPanel().setNameError(false);
970        if (!Control.isValidUDPPort(port)) {
980            this.getWorkstationPanel().setPortError(true);
990            return false;
1000        }
1010        this.getWorkstationPanel().setPortError(false);
1020        return true;
1030    }
104  
105     /*
106      * (non-Javadoc)
107      *
108      * @see ui.command.Command#execution()
109      */
110     @Override
111     protected void execution() throws Exception {
1120        switch (getStatus()) {
1130        case ERROR_STATUS:
1140            break;
1150        case VETOED_STATUS:
1160            break;
1170        case EXECUTE_STATUS:
1180            if (createWorkstation) {
1190                workstation = WorkstationFactory.newWorkstation(name, type,
1200                        description, address, port, inUse);
1210                NetworkManager.getInstance().addClientWorkstation(workstation);
1220                setStatus(SUCCESS_STATUS);
1230            } else {
1240                workstation.setName(name);
1250                workstation.setType(type);
1260                workstation.setLocation(location);
1270                workstation.setDescription(description);
1280                workstation.setAddress(address);
1290                workstation.setPort(port);
1300                workstation.setInUse(inUse);
1310                setStatus(SUCCESS_STATUS);
1320            }
133             break;
134         }
1350    }
1360 
137     /**
138      * @return Returns the workstationPanel.
139      */
140     private WorkstationPanel getWorkstationPanel() {
1410        return workstationPanel;
142     }
143  
144 }

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.