Coverage details for base.jdbs.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.jdbs;
21  
22 import java.io.File;
23 import java.util.Date;
24 import java.util.Hashtable;
25 import java.util.Observable;
26  
27 import org.apache.log4j.Logger;
28 import org.w3c.dom.Document;
29 import org.w3c.dom.Element;
30 import org.w3c.dom.Node;
31 import org.w3c.dom.NodeList;
32  
33 import base.IXMLSaveable;
34  
35 public class Backup extends Observable implements IXMLSaveable {
360 
370    private static final transient Logger logger = Logger
380            .getLogger(Backup.class.getName());
39  
40     /** The backups' global unique identifier.* */
41     private String guId;
42  
43     /** The backups' name.* */
44     private String name;
45  
46     /** The backups' description.* */
47     private String description;
48  
49     /** The backups' creationDate associated to the life cycle.* */
50     private Date creationDate;
510 
52     /** The backups' expirationDate associated to the life cycle.* */
53     private Date expirationDate;
540 
55     /** The backus'security level, one between private or public.* */
560    private SecurityLevel securityLevel = SecurityLevel.PRIVATE;
57  
58     /** The backupped files.* */
590    private Hashtable<String, FileDescriptor> file = new Hashtable<String, FileDescriptor>();
60  
61     /**
62      * @param guId
63      * The backups' global unique identifier.
640     * @param name
650     * The backups' name.
660     * @param description
670     * The backups' description.
680     * @param creationDate
690     * The backups' creation date.
700     * @param expirationDate
710     * The backups' expiration date.
72      * @param securityLevel
73      * The backups' security level.
74      */
75     protected Backup(String guId, String name, String description,
760            Date creationDate, Date expirationDate, SecurityLevel securityLevel) {
770        this.guId = guId;
780        this.name = name;
790        this.description = description;
800        this.creationDate = creationDate;
810        this.expirationDate = expirationDate;
820        this.securityLevel = securityLevel;
830    }
840 
85     /**
86      * @return Returns the guId.
87      */
88     public String getGuId() {
890        return guId;
90     }
910 
920    /**
93      * @return Returns the description.
94      */
95     public String getDescription() {
960        return description;
97     }
980 
99     /**
100      * @param description
101      * The description to set.
102      */
103     public void setDescription(String description) {
1040        this.description = description;
1050    }
1060 
107     /**
108      * @return Returns the name.
109      */
110     public String getName() {
1110        return name;
1120    }
113  
114     /**
115      * @param name
116      * The name to set.
117      */
118     public void setName(String name) {
1190        this.name = name;
1200    }
121  
122     /**
123      * @return Returns the creationDate.
124      */
125     public Date getCreationDate() {
1260        return creationDate;
127     }
128  
129     /**
130      * @return Returns the expirationDate.
131      */
132     public Date getExpirationDate() {
1330        return expirationDate;
1340    }
1350 
1360    /**
1370     * @return the securityLevel
1380     */
139     public SecurityLevel getSecurityLevel() {
1400        return securityLevel;
141     }
142  
143     /**
144      * This method adds a file to the backups' collection.
1450     *
1460     * @param file
1470     * The file to be added to the backups'collection.
1480     */
1490    public void addFile(File file) {
1500        logger.debug("Backup.addFile(" + file + ")");
1510        this.setChanged();
1520        this.file.put(createFileKey(file), new FileDescriptor(file));
1530        this.notifyObservers();
1540    }
155  
1560    /**
1570     * This method removes a file from the backup's collection.
1580     *
1590     * @param file
1600     * The file to be removed from the backup's collection.
1610     */
162     public void removeFile(File file) {
1630        logger.debug("Backup.removeFile(" + file + ")");
1640        this.setChanged();
1650        this.file.remove(createFileKey(file));
1660        this.notifyObservers();
1670    }
1680 
1690    /**
1700     * This method adds a set of files to the backups' collection.
1710     *
1720     * @param file
1730     * The file set to be added to the backups'collection.
174      */
175     public void addAllFile(File[] file) {
1760        logger.debug("Backup.addAllFile(" + file.length + ")");
1770        this.setChanged();
1780        for (int i = 0; i < file.length; i++)
1790            this.file.put(createFileKey(file[i]), new FileDescriptor(file[i]));
1800        this.notifyObservers();
1810    }
182  
183     /**
184      * This method removes a set of files from the backups' collection.
185      *
186      * @param file
187      * The file set to be removed from the backups'collection.
188      */
1890    public void removeAllFile(File[] file) {
1900        logger.debug("Backup.removeAllFile(" + file.length + ")");
1910        this.setChanged();
1920        for (int i = 0; i < file.length; i++)
1930            this.file.remove(createFileKey(file[i]));
1940        this.notifyObservers();
1950    }
1960 
1970    /**
1980     * This method returns an array of backups'collected files.
1990     *
2000     * @return The file collection associated to the backup.
2010     */
2020    public FileDescriptor[] getFileDescriptor() {
2030        return file.values().toArray(new FileDescriptor[0]);
2040    }
2050 
2060    /**
2070     * This method builds a unique key to be associated to a file in the
208      * backups'collection.
2090     *
2100     * @param file
2110     * The file from which the key must be built.
212      * @return A key rappresentation for the input file.
213      */
214     private String createFileKey(File file) {
2150        return file.getAbsolutePath();
216     }
217  
2180    public Backup(Document document) {
2190        NodeList nodeList = document.getElementsByTagName("Backup");
2200        for (int i = 0; i < nodeList.item(0).getChildNodes().getLength(); i++) {
2210            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
222                     "GUID"))
2230                this.guId = nodeList.item(0).getChildNodes().item(i)
2240                        .getAttributes().getNamedItem("value").getNodeValue()
2250                        .toString();
2260            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
2270                    "Name"))
2280                this.name = nodeList.item(0).getChildNodes().item(i)
2290                        .getAttributes().getNamedItem("value").getNodeValue()
230                         .toString();
2310            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
2320                    "Description"))
2330                this.description = nodeList.item(0).getChildNodes().item(i)
234                         .getAttributes().getNamedItem("value").getNodeValue()
2350                        .toString();
2360            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
2370                    "CreationDate"))
2380                this.creationDate = new Date(Long.parseLong(nodeList.item(0)
2390                        .getChildNodes().item(i).getAttributes().getNamedItem(
2400                                "value").getNodeValue().toString()));
2410            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
242                     "ExpirationDate"))
2430                this.expirationDate = new Date(Long.parseLong(nodeList.item(0)
2440                        .getChildNodes().item(i).getAttributes().getNamedItem(
2450                                "value").getNodeValue().toString()));
2460            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
2470                    "SecurityLevel"))
2480                this.securityLevel = nodeList.item(0).getChildNodes().item(i)
2490                        .getAttributes().getNamedItem("value").getNodeValue()
2500                        .toString().equalsIgnoreCase(SecurityLevel.level[0]) ? SecurityLevel.PUBLIC
2510                        : SecurityLevel.PRIVATE;
2520            if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals(
253                     "File")) {
2540                NodeList fileEntry = nodeList.item(0).getChildNodes().item(i)
255                         .getChildNodes();
2560                for (int k = 0; k < fileEntry.getLength(); k++)
2570                    this.addFile(new File(fileEntry.item(k).getAttributes()
258                             .getNamedItem("value").getNodeValue().toString()));
259             }
260  
261         }
2620    }
2630 
2640    /*
265      * (non-Javadoc)
266      *
267      * @see base.IXMLSaveable#toXml(org.w3c.dom.Document)
268      */
269     public Node toXml(Document document) {
2700        Element backupElement = document.createElement("Backup");
2710 
2720        Element guIdElement = document.createElement("GUID");
2730        guIdElement.setAttribute("value", this.guId);
2740        backupElement.appendChild(guIdElement);
275  
2760        Element nameElement = document.createElement("Name");
2770        nameElement.setAttribute("value", this.name);
2780        backupElement.appendChild(nameElement);
279  
2800        Element descriptionElement = document.createElement("Description");
2810        descriptionElement.setAttribute("value", this.description);
2820        backupElement.appendChild(descriptionElement);
283  
2840        Element creationDateElement = document.createElement("CreationDate");
2850        creationDateElement.setAttribute("value", ""
286                 + this.creationDate.getTime());
2870        backupElement.appendChild(creationDateElement);
288  
2890        Element expirationDateElement = document
290                 .createElement("ExpirationDate");
2910        expirationDateElement.setAttribute("value", ""
292                 + this.expirationDate.getTime());
2930        backupElement.appendChild(expirationDateElement);
294  
2950        Element securityLevelElement = document.createElement("SecurityLevel");
2960        securityLevelElement.setAttribute("value", "" + this.securityLevel);
2970        backupElement.appendChild(securityLevelElement);
298  
2990        Element fileElement = document.createElement("File");
3000        FileDescriptor[] file = this.getFileDescriptor();
3010        for (int i = 0; i < file.length; i++) {
3020            Element fileEntryElement = document.createElement("FileEntry");
3030            fileEntryElement.setAttribute("value", "" + file[i].getFile());
3040            fileElement.appendChild(fileEntryElement);
305         }
3060        backupElement.appendChild(fileElement);
307  
3080        return backupElement;
309     }
310  
311     /**
312      * @param creationDate
313      * The creationDate to set.
314      */
315     public void setCreationDate(Date creationDate) {
3160        this.creationDate = creationDate;
3170    }
318  
319     /**
320      * @param expirationDate
321      * The expirationDate to set.
322      */
323     public void setExpirationDate(Date expirationDate) {
3240        this.expirationDate = expirationDate;
3250    }
326  
327     /**
328      * @param securityLevel
329      * The securityLevel to set.
330      */
331     public void setSecurityLevel(SecurityLevel securityLevel) {
3320        this.securityLevel = securityLevel;
3330    }
334  
335 }

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.