Coverage details for base.backup.Backup

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.backup;
21  
22 import java.io.File;
23 import java.util.Date;
24  
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27 import org.w3c.dom.Node;
28 import org.w3c.dom.NodeList;
29  
30 import base.ICXmlTags;
31  
32 public class Backup {
33     private final int id;
34  
35     private String name;
36  
37     private String description;
38  
39     private Date date;
400 
41     private String dbLocationPath;
42  
43     private String zipLocationPath;
44  
450    private long size = -1;
460 
47     /**
48      * @param id
49      * The backup's id.
50      * @param name
51      * The backup's name.
52      * @param description
53      * The backup's description.
54      * @param date
55      * The backup's date.
560     * @param dbLocationPath
570     * The backup's database file dbLocationPath.
580     * @param zipLocationPath
590     */
600    protected Backup(int id, String name, String description, Date date,
610            String dbLocationPath, String zipLocationPath) {
620        this.id = id;
630        this.name = name;
640        this.description = description;
650        this.date = date;
660        this.dbLocationPath = dbLocationPath;
670        this.zipLocationPath = zipLocationPath;
680    }
690 
700    public Backup(Document document) {
710        NodeList detailsNodeList = document
720                .getElementsByTagName(ICXmlTags.BACKUP_DETAILS_TAG);
730        Node detailsNode = detailsNodeList.item(0);
74  
750        this.id = new Integer(detailsNode.getAttributes().getNamedItem(
76                 ICXmlTags.BACKUP_ID_ATTRIBUTE).getNodeValue());
770        this.name = detailsNode.getAttributes().getNamedItem(
78                 ICXmlTags.BACKUP_NAME_ATTRIBUTE).getNodeValue();
790        this.date = new Date(new Long(detailsNode.getAttributes().getNamedItem(
800                ICXmlTags.BACKUP_DATE_ATTRIBUTE).getNodeValue()));
810 
820        for (int i = 0; i < detailsNode.getChildNodes().getLength(); i++) {
830            if (detailsNode.getChildNodes().item(i).getNodeName().equals(
840                    ICXmlTags.BACKUP_DB_LOCATION_PATH_TAG)) {
850                this.dbLocationPath = detailsNode.getChildNodes().item(i)
86                         .getAttributes().getNamedItem(
87                                 ICXmlTags.BACKUP_DB_LOCATION_PATH_ATTRIBUTE)
880                        .getNodeValue();
890            }
900 
910            if (detailsNode.getChildNodes().item(i).getNodeName().equals(
92                     ICXmlTags.BACKUP_DESCRIPTION_TAG)) {
930                this.description = detailsNode.getChildNodes().item(i)
94                         .getAttributes().getNamedItem(
950                                ICXmlTags.BACKUP_DESCRIPTION_ATTRIBUTE)
96                         .getNodeValue();
97             }
980        }
990    }
100  
1010    /**
102      * @return Returns the date.
103      */
104     public Date getDate() {
1050        return date;
106     }
107  
108     /**
1090     * @param date
1100     * The date to set.
111      */
112     protected void setDate(Date date) {
1130        this.date = date;
1140    }
115  
1160    /**
117      * @return Returns the description.
118      */
119     public String getDescription() {
1200        return description;
121     }
122  
123     /**
1240     * @param description
1250     * The description to set.
126      */
1270    protected void setDescription(String description) {
1280        this.description = description;
1290    }
130  
1310    /**
1320     * @return Returns the name.
1330     */
134     public String getName() {
1350        return name;
136     }
137  
138     /**
1390     * @param name
1400     * The name to set.
141      */
142     protected void setName(String name) {
1430        this.name = name;
1440    }
145  
1460    /**
147      * @return Returns the dbLocationPath.
1480     */
1490    public String getDbLocationPath() {
1500        return dbLocationPath;
1510    }
1520 
1530    /**
1540     * @return Returns the id.
1550     */
1560    public int getId() {
1570        return id;
1580    }
1590 
1600    public String getBackupFileName() {
1610        return this.getDbLocationPath().substring(
1620                this.getDbLocationPath().lastIndexOf("" + File.pathSeparator),
1630                this.getDbLocationPath().length());
1640    }
1650 
1660    /**
1670     * @return Returns the zipLocationPath.
168      */
1690    public String getZipLocationPath() {
1700        return zipLocationPath;
1710    }
1720 
1730    /**
1740     * @param currentBackupLocationPath
1750     * The currentBackupLocationPath to set.
1760     */
177     public void setCurrentBackupLocationPath(String currentBackupLocationPath) {
1780        this.zipLocationPath = currentBackupLocationPath;
1790    }
1800 
1810    public Node toXml(Document document) {
1820        Element detailsElement = document
1830                .createElement(ICXmlTags.BACKUP_DETAILS_TAG);
1840 
1850        detailsElement.setAttribute(ICXmlTags.BACKUP_ID_ATTRIBUTE, ""
1860                + this.getId());
1870        detailsElement.setAttribute(ICXmlTags.BACKUP_NAME_ATTRIBUTE, this
1880                .getName());
1890        detailsElement.setAttribute(ICXmlTags.BACKUP_DATE_ATTRIBUTE, ""
1900                + this.getDate().getTime());
1910 
1920        Element originalDestinationPathElement = document
1930                .createElement(ICXmlTags.BACKUP_DB_LOCATION_PATH_TAG);
194  
1950        originalDestinationPathElement.setAttribute(
1960                ICXmlTags.BACKUP_DB_LOCATION_PATH_ATTRIBUTE, this
1970                        .getDbLocationPath());
1980        detailsElement.appendChild(originalDestinationPathElement);
1990 
2000        Element descriptionElement = document
2010                .createElement(ICXmlTags.BACKUP_DESCRIPTION_TAG);
202  
2030        descriptionElement.setAttribute(ICXmlTags.BACKUP_DESCRIPTION_ATTRIBUTE,
204                 this.getDescription());
2050        detailsElement.appendChild(descriptionElement);
206  
2070        return detailsElement;
2080    }
2090 
2100    /**
211      * @param dbLocationPath
212      * The dbLocationPath to set.
213      */
214     protected void setDbLocationPath(String dbLocationPath) {
2150        this.dbLocationPath = dbLocationPath;
2160    }
2170 
2180    /**
219      * @param zipLocationPath
220      * The zipLocationPath to set.
221      */
2220    protected void setZipLocationPath(String zipLocationPath) {
2230        this.zipLocationPath = zipLocationPath;
2240    }
2250 
2260    /**
2270     * @return Returns the size.
2280     */
2290    public long getSize() {
2300        if (getZipLocationPath() == null) {
2310            return size = -1;
2320        }
233  
2340        File zipFile = new File(getZipLocationPath());
235  
2360        if (!zipFile.exists()) {
2370            return size = -1;
238         }
239  
2400        return (size != -1) ? size : (size = BackupFactory
241                 .fileSizeInKB(zipFile));
242     }
243 }

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.