Coverage details for base.network.Workstation

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 base.network;
21  
22 import java.net.InetAddress;
23 import java.net.UnknownHostException;
24  
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27 import org.w3c.dom.Node;
28  
29 import base.ICXmlTags;
30 import base.IXMLSaveable;
31  
32 public class Workstation implements IXMLSaveable {
33  
34     private final int id;
35  
360    private String name = "";
37  
380    private String location = "";
39  
400    private String description = "";
41  
420    private String type = WorkstationType.WORKSTATION_TYPE[0];
43  
44     private InetAddress address;
45  
460    private int port = -1;
47  
480    private boolean inUse = false;
49  
50     // private final String role;
51  
520    protected Workstation(final int id) {
530        this.id = id;
54         // this.role = role;
55         try {
560            this.address = InetAddress.getLocalHost();
570            this.port = 9000;
580        } catch (UnknownHostException e) {
59             // TODO Auto-generated catch block
600            e.printStackTrace();
610        }
620    }
63  
640    protected Workstation(final int id, String name, String type,
650            String description, InetAddress address, boolean inUse) {
660        this.id = id;
670        this.name = name;
680        this.type = type;
690        this.description = description;
700        this.address = address;
710        this.port = 9000;
720        this.inUse = inUse;
730    }
74  
750    protected Workstation(final int id, String name, String type,
760            String description, InetAddress address, int port, boolean inUse) {
770        this.id = id;
780        this.name = name;
790        this.type = type;
800        this.description = description;
810        this.address = address;
820        this.port = port;
830        this.inUse = inUse;
840    }
85  
86     /**
87      * @return Returns the address.
88      */
89     public InetAddress getAddress() {
900        return address;
91     }
92  
93     /**
94      * @param address
95      * The address to set.
96      */
97     public void setAddress(InetAddress address) {
980        this.address = address;
990    }
100  
101     /**
102      * @return Returns the description.
103      */
104     public String getDescription() {
1050        return description;
106     }
107  
108     /**
109      * @param description
110      * The description to set.
111      */
112     public void setDescription(String description) {
1130        this.description = description;
1140    }
115  
116     /**
117      * @return Returns the inUse.
118      */
119     public boolean isInUse() {
1200        return inUse;
121     }
122  
123     /**
124      * @param inUse
125      * The inUse to set.
126      */
127     public void setInUse(boolean inUse) {
1280        this.inUse = inUse;
1290    }
130  
131     /**
132      * @return Returns the name.
133      */
134     public String getName() {
1350        return name;
136     }
137  
138     /**
139      * @param name
140      * The name to set.
141      */
142     public void setName(String name) {
1430        this.name = name;
1440    }
145  
146     /**
147      * @return Returns the type.
148      */
149     public String getType() {
1500        return type;
151     }
152  
153     /**
154      * @param type
155      * The type to set.
156      */
157     public void setType(String type) {
1580        this.type = type;
1590    }
160  
161     /*
162      * (non-Javadoc)
163      *
164      * @see java.lang.Object#toString()
165      */
166     @Override
167     public String toString() {
1680        StringBuffer sb = new StringBuffer();
1690        sb.append("WORKSTATION");
1700        sb.append("\n");
1710        sb.append("id: " + id);
1720        sb.append("\n");
1730        sb.append("name: " + name);
1740        sb.append("\n");
1750        sb.append("description: " + description);
1760        sb.append("\n");
1770        sb.append("type: " + type);
1780        sb.append("\n");
1790        sb.append("address: " + address);
1800        sb.append("\n");
1810        sb.append("port: " + port);
1820        sb.append("\n");
1830        sb.append("in use: " + inUse);
1840        return sb.toString();
185     }
186  
187     /**
188      * @return Returns the id.
189      */
190     public int getId() {
1910        return id;
192     }
193  
194     /**
195      * @return Returns true if this workstation is a server, false otherwise.
196      */
197     public boolean isServer() {
1980        return this.id == 0; // Dummy...we can also access the
199         // InternetCafeManager
200     }
201  
202     /**
203      * @return Returns the port.
204      */
205     public int getPort() {
2060        return port;
207     }
208  
209     /**
210      * @param port
211      * The port to set.
212      */
213     public void setPort(int port) {
2140        this.port = port;
2150    }
216  
217     /**
218      * @return Returns the location.
219      */
220     public String getLocation() {
2210        return location;
222     }
223  
224     /**
225      * @param location
226      * The location to set.
227      */
228     public void setLocation(String location) {
2290        this.location = location;
2300    }
231  
232     /*
233      * (non-Javadoc)
234      *
235      * @see test.base.IXMLSaveable#toXml(org.w3c.dom.Document)
236      */
237     public Node toXml(Document document) {
2380        Element workstationElement = document
2390                .createElement(ICXmlTags.IC_WORKSTATION_TAG);
2400        workstationElement.setAttribute(ICXmlTags.IC_WORKSTATION_ID_ATTRIBUTE,
2410                "" + this.id);
2420        workstationElement.setAttribute(
2430                ICXmlTags.IC_WORKSTATION_IN_USE_ATTRIBUTE, "" + this.inUse);
244  
2450        Element nameElement = document
2460                .createElement(ICXmlTags.IC_WORKSTATION_NAME_TAG);
2470        nameElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.name);
2480        workstationElement.appendChild(nameElement);
249  
2500        Element typeElement = document
2510                .createElement(ICXmlTags.IC_WORKSTATION_TYPE_TAG);
2520        typeElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, this.type);
2530        workstationElement.appendChild(typeElement);
254         // FIXME
2550        workstationElement
2560                .appendChild(document
2570                        .createComment("We must find a way to retrieve the machine's MAC address..."));
2580        Element addressElement = document
2590                .createElement(ICXmlTags.IC_WORKSTATION_ADDRESS_TAG);
2600        addressElement.setAttribute(ICXmlTags.IC_WORKSTATION_ADDRESS_ATTRIBUTE,
2610                this.address.getHostAddress());
2620        addressElement.setAttribute(ICXmlTags.IC_WORKSTATION_PORT_ATTRIBUTE, ""
2630                + this.port);
2640        workstationElement.appendChild(addressElement);
265  
2660        Element locationElement = document
2670                .createElement(ICXmlTags.IC_WORKSTATION_LOCATION_TAG);
2680        locationElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
2690                this.location);
2700        workstationElement.appendChild(locationElement);
271  
2720        Element descriptionElement = document
2730                .createElement(ICXmlTags.IC_WORKSTATION_DESCRIPTION_TAG);
2740        descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
2750                this.description);
2760        workstationElement.appendChild(descriptionElement);
277  
2780        return workstationElement;
279     }
280  
281 }

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.