| Line | Hits | Source |
|---|---|---|
| 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) { | |
| 60 | 0 | super(); |
| 61 | 0 | // TODO Auto-generated constructor stub |
| 62 | 0 | this.workstationPanel = workstationPanel; |
| 63 | 0 | this.workstation = workstation; |
| 64 | 0 | this.createWorkstation = createWorkstation; |
| 65 | 0 | } |
| 66 | 0 | |
| 67 | /* | |
| 68 | * (non-Javadoc) | |
| 69 | * | |
| 70 | * @see ui.command.Command#prologo() | |
| 71 | */ | |
| 72 | @Override | |
| 73 | protected void prologo() { | |
| 74 | 0 | name = getWorkstationPanel().getWorkstationName(); |
| 75 | 0 | type = getWorkstationPanel().getWorkstationType(); |
| 76 | 0 | location = getWorkstationPanel().getWorkstationLocation(); |
| 77 | 0 | description = getWorkstationPanel().getWorkstationDescription(); |
| 78 | 0 | address = getWorkstationPanel().getWorkstationAddress(); |
| 79 | 0 | port = getWorkstationPanel().getWorkstationPort(); |
| 80 | 0 | inUse = getWorkstationPanel().getWorkstationInUse(); |
| 81 | 0 | |
| 82 | 0 | if (isValidWorkstationData(name, type, location, description, address, |
| 83 | 0 | port, inUse)) |
| 84 | 0 | setStatus(EXECUTE_STATUS); |
| 85 | 0 | else |
| 86 | 0 | setStatus(ERROR_STATUS); |
| 87 | 0 | } |
| 88 | 0 | |
| 89 | private boolean isValidWorkstationData(String name, String type, | |
| 90 | String location, String description, Inet4Address address, | |
| 91 | int port, boolean inUse) { | |
| 92 | 0 | if (name == null || name.length() == 0) { |
| 93 | 0 | this.getWorkstationPanel().setNameError(true); |
| 94 | 0 | return false; |
| 95 | 0 | } else |
| 96 | 0 | this.getWorkstationPanel().setNameError(false); |
| 97 | 0 | if (!Control.isValidUDPPort(port)) { |
| 98 | 0 | this.getWorkstationPanel().setPortError(true); |
| 99 | 0 | return false; |
| 100 | 0 | } |
| 101 | 0 | this.getWorkstationPanel().setPortError(false); |
| 102 | 0 | return true; |
| 103 | 0 | } |
| 104 | ||
| 105 | /* | |
| 106 | * (non-Javadoc) | |
| 107 | * | |
| 108 | * @see ui.command.Command#execution() | |
| 109 | */ | |
| 110 | @Override | |
| 111 | protected void execution() throws Exception { | |
| 112 | 0 | switch (getStatus()) { |
| 113 | 0 | case ERROR_STATUS: |
| 114 | 0 | break; |
| 115 | 0 | case VETOED_STATUS: |
| 116 | 0 | break; |
| 117 | 0 | case EXECUTE_STATUS: |
| 118 | 0 | if (createWorkstation) { |
| 119 | 0 | workstation = WorkstationFactory.newWorkstation(name, type, |
| 120 | 0 | description, address, port, inUse); |
| 121 | 0 | NetworkManager.getInstance().addClientWorkstation(workstation); |
| 122 | 0 | setStatus(SUCCESS_STATUS); |
| 123 | 0 | } else { |
| 124 | 0 | workstation.setName(name); |
| 125 | 0 | workstation.setType(type); |
| 126 | 0 | workstation.setLocation(location); |
| 127 | 0 | workstation.setDescription(description); |
| 128 | 0 | workstation.setAddress(address); |
| 129 | 0 | workstation.setPort(port); |
| 130 | 0 | workstation.setInUse(inUse); |
| 131 | 0 | setStatus(SUCCESS_STATUS); |
| 132 | 0 | } |
| 133 | break; | |
| 134 | } | |
| 135 | 0 | } |
| 136 | 0 | |
| 137 | /** | |
| 138 | * @return Returns the workstationPanel. | |
| 139 | */ | |
| 140 | private WorkstationPanel getWorkstationPanel() { | |
| 141 | 0 | return workstationPanel; |
| 142 | } | |
| 143 | ||
| 144 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |