| 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 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 { | |
| 36 | 0 | |
| 37 | 0 | private static final transient Logger logger = Logger |
| 38 | 0 | .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; | |
| 51 | 0 | |
| 52 | /** The backups' expirationDate associated to the life cycle.* */ | |
| 53 | private Date expirationDate; | |
| 54 | 0 | |
| 55 | /** The backus'security level, one between private or public.* */ | |
| 56 | 0 | private SecurityLevel securityLevel = SecurityLevel.PRIVATE; |
| 57 | ||
| 58 | /** The backupped files.* */ | |
| 59 | 0 | private Hashtable<String, FileDescriptor> file = new Hashtable<String, FileDescriptor>(); |
| 60 | ||
| 61 | /** | |
| 62 | * @param guId | |
| 63 | * The backups' global unique identifier. | |
| 64 | 0 | * @param name |
| 65 | 0 | * The backups' name. |
| 66 | 0 | * @param description |
| 67 | 0 | * The backups' description. |
| 68 | 0 | * @param creationDate |
| 69 | 0 | * The backups' creation date. |
| 70 | 0 | * @param expirationDate |
| 71 | 0 | * The backups' expiration date. |
| 72 | * @param securityLevel | |
| 73 | * The backups' security level. | |
| 74 | */ | |
| 75 | protected Backup(String guId, String name, String description, | |
| 76 | 0 | Date creationDate, Date expirationDate, SecurityLevel securityLevel) { |
| 77 | 0 | this.guId = guId; |
| 78 | 0 | this.name = name; |
| 79 | 0 | this.description = description; |
| 80 | 0 | this.creationDate = creationDate; |
| 81 | 0 | this.expirationDate = expirationDate; |
| 82 | 0 | this.securityLevel = securityLevel; |
| 83 | 0 | } |
| 84 | 0 | |
| 85 | /** | |
| 86 | * @return Returns the guId. | |
| 87 | */ | |
| 88 | public String getGuId() { | |
| 89 | 0 | return guId; |
| 90 | } | |
| 91 | 0 | |
| 92 | 0 | /** |
| 93 | * @return Returns the description. | |
| 94 | */ | |
| 95 | public String getDescription() { | |
| 96 | 0 | return description; |
| 97 | } | |
| 98 | 0 | |
| 99 | /** | |
| 100 | * @param description | |
| 101 | * The description to set. | |
| 102 | */ | |
| 103 | public void setDescription(String description) { | |
| 104 | 0 | this.description = description; |
| 105 | 0 | } |
| 106 | 0 | |
| 107 | /** | |
| 108 | * @return Returns the name. | |
| 109 | */ | |
| 110 | public String getName() { | |
| 111 | 0 | return name; |
| 112 | 0 | } |
| 113 | ||
| 114 | /** | |
| 115 | * @param name | |
| 116 | * The name to set. | |
| 117 | */ | |
| 118 | public void setName(String name) { | |
| 119 | 0 | this.name = name; |
| 120 | 0 | } |
| 121 | ||
| 122 | /** | |
| 123 | * @return Returns the creationDate. | |
| 124 | */ | |
| 125 | public Date getCreationDate() { | |
| 126 | 0 | return creationDate; |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * @return Returns the expirationDate. | |
| 131 | */ | |
| 132 | public Date getExpirationDate() { | |
| 133 | 0 | return expirationDate; |
| 134 | 0 | } |
| 135 | 0 | |
| 136 | 0 | /** |
| 137 | 0 | * @return the securityLevel |
| 138 | 0 | */ |
| 139 | public SecurityLevel getSecurityLevel() { | |
| 140 | 0 | return securityLevel; |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * This method adds a file to the backups' collection. | |
| 145 | 0 | * |
| 146 | 0 | * @param file |
| 147 | 0 | * The file to be added to the backups'collection. |
| 148 | 0 | */ |
| 149 | 0 | public void addFile(File file) { |
| 150 | 0 | logger.debug("Backup.addFile(" + file + ")"); |
| 151 | 0 | this.setChanged(); |
| 152 | 0 | this.file.put(createFileKey(file), new FileDescriptor(file)); |
| 153 | 0 | this.notifyObservers(); |
| 154 | 0 | } |
| 155 | ||
| 156 | 0 | /** |
| 157 | 0 | * This method removes a file from the backup's collection. |
| 158 | 0 | * |
| 159 | 0 | * @param file |
| 160 | 0 | * The file to be removed from the backup's collection. |
| 161 | 0 | */ |
| 162 | public void removeFile(File file) { | |
| 163 | 0 | logger.debug("Backup.removeFile(" + file + ")"); |
| 164 | 0 | this.setChanged(); |
| 165 | 0 | this.file.remove(createFileKey(file)); |
| 166 | 0 | this.notifyObservers(); |
| 167 | 0 | } |
| 168 | 0 | |
| 169 | 0 | /** |
| 170 | 0 | * This method adds a set of files to the backups' collection. |
| 171 | 0 | * |
| 172 | 0 | * @param file |
| 173 | 0 | * The file set to be added to the backups'collection. |
| 174 | */ | |
| 175 | public void addAllFile(File[] file) { | |
| 176 | 0 | logger.debug("Backup.addAllFile(" + file.length + ")"); |
| 177 | 0 | this.setChanged(); |
| 178 | 0 | for (int i = 0; i < file.length; i++) |
| 179 | 0 | this.file.put(createFileKey(file[i]), new FileDescriptor(file[i])); |
| 180 | 0 | this.notifyObservers(); |
| 181 | 0 | } |
| 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 | */ | |
| 189 | 0 | public void removeAllFile(File[] file) { |
| 190 | 0 | logger.debug("Backup.removeAllFile(" + file.length + ")"); |
| 191 | 0 | this.setChanged(); |
| 192 | 0 | for (int i = 0; i < file.length; i++) |
| 193 | 0 | this.file.remove(createFileKey(file[i])); |
| 194 | 0 | this.notifyObservers(); |
| 195 | 0 | } |
| 196 | 0 | |
| 197 | 0 | /** |
| 198 | 0 | * This method returns an array of backups'collected files. |
| 199 | 0 | * |
| 200 | 0 | * @return The file collection associated to the backup. |
| 201 | 0 | */ |
| 202 | 0 | public FileDescriptor[] getFileDescriptor() { |
| 203 | 0 | return file.values().toArray(new FileDescriptor[0]); |
| 204 | 0 | } |
| 205 | 0 | |
| 206 | 0 | /** |
| 207 | 0 | * This method builds a unique key to be associated to a file in the |
| 208 | * backups'collection. | |
| 209 | 0 | * |
| 210 | 0 | * @param file |
| 211 | 0 | * 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) { | |
| 215 | 0 | return file.getAbsolutePath(); |
| 216 | } | |
| 217 | ||
| 218 | 0 | public Backup(Document document) { |
| 219 | 0 | NodeList nodeList = document.getElementsByTagName("Backup"); |
| 220 | 0 | for (int i = 0; i < nodeList.item(0).getChildNodes().getLength(); i++) { |
| 221 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 222 | "GUID")) | |
| 223 | 0 | this.guId = nodeList.item(0).getChildNodes().item(i) |
| 224 | 0 | .getAttributes().getNamedItem("value").getNodeValue() |
| 225 | 0 | .toString(); |
| 226 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 227 | 0 | "Name")) |
| 228 | 0 | this.name = nodeList.item(0).getChildNodes().item(i) |
| 229 | 0 | .getAttributes().getNamedItem("value").getNodeValue() |
| 230 | .toString(); | |
| 231 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 232 | 0 | "Description")) |
| 233 | 0 | this.description = nodeList.item(0).getChildNodes().item(i) |
| 234 | .getAttributes().getNamedItem("value").getNodeValue() | |
| 235 | 0 | .toString(); |
| 236 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 237 | 0 | "CreationDate")) |
| 238 | 0 | this.creationDate = new Date(Long.parseLong(nodeList.item(0) |
| 239 | 0 | .getChildNodes().item(i).getAttributes().getNamedItem( |
| 240 | 0 | "value").getNodeValue().toString())); |
| 241 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 242 | "ExpirationDate")) | |
| 243 | 0 | this.expirationDate = new Date(Long.parseLong(nodeList.item(0) |
| 244 | 0 | .getChildNodes().item(i).getAttributes().getNamedItem( |
| 245 | 0 | "value").getNodeValue().toString())); |
| 246 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 247 | 0 | "SecurityLevel")) |
| 248 | 0 | this.securityLevel = nodeList.item(0).getChildNodes().item(i) |
| 249 | 0 | .getAttributes().getNamedItem("value").getNodeValue() |
| 250 | 0 | .toString().equalsIgnoreCase(SecurityLevel.level[0]) ? SecurityLevel.PUBLIC |
| 251 | 0 | : SecurityLevel.PRIVATE; |
| 252 | 0 | if (nodeList.item(0).getChildNodes().item(i).getNodeName().equals( |
| 253 | "File")) { | |
| 254 | 0 | NodeList fileEntry = nodeList.item(0).getChildNodes().item(i) |
| 255 | .getChildNodes(); | |
| 256 | 0 | for (int k = 0; k < fileEntry.getLength(); k++) |
| 257 | 0 | this.addFile(new File(fileEntry.item(k).getAttributes() |
| 258 | .getNamedItem("value").getNodeValue().toString())); | |
| 259 | } | |
| 260 | ||
| 261 | } | |
| 262 | 0 | } |
| 263 | 0 | |
| 264 | 0 | /* |
| 265 | * (non-Javadoc) | |
| 266 | * | |
| 267 | * @see base.IXMLSaveable#toXml(org.w3c.dom.Document) | |
| 268 | */ | |
| 269 | public Node toXml(Document document) { | |
| 270 | 0 | Element backupElement = document.createElement("Backup"); |
| 271 | 0 | |
| 272 | 0 | Element guIdElement = document.createElement("GUID"); |
| 273 | 0 | guIdElement.setAttribute("value", this.guId); |
| 274 | 0 | backupElement.appendChild(guIdElement); |
| 275 | ||
| 276 | 0 | Element nameElement = document.createElement("Name"); |
| 277 | 0 | nameElement.setAttribute("value", this.name); |
| 278 | 0 | backupElement.appendChild(nameElement); |
| 279 | ||
| 280 | 0 | Element descriptionElement = document.createElement("Description"); |
| 281 | 0 | descriptionElement.setAttribute("value", this.description); |
| 282 | 0 | backupElement.appendChild(descriptionElement); |
| 283 | ||
| 284 | 0 | Element creationDateElement = document.createElement("CreationDate"); |
| 285 | 0 | creationDateElement.setAttribute("value", "" |
| 286 | + this.creationDate.getTime()); | |
| 287 | 0 | backupElement.appendChild(creationDateElement); |
| 288 | ||
| 289 | 0 | Element expirationDateElement = document |
| 290 | .createElement("ExpirationDate"); | |
| 291 | 0 | expirationDateElement.setAttribute("value", "" |
| 292 | + this.expirationDate.getTime()); | |
| 293 | 0 | backupElement.appendChild(expirationDateElement); |
| 294 | ||
| 295 | 0 | Element securityLevelElement = document.createElement("SecurityLevel"); |
| 296 | 0 | securityLevelElement.setAttribute("value", "" + this.securityLevel); |
| 297 | 0 | backupElement.appendChild(securityLevelElement); |
| 298 | ||
| 299 | 0 | Element fileElement = document.createElement("File"); |
| 300 | 0 | FileDescriptor[] file = this.getFileDescriptor(); |
| 301 | 0 | for (int i = 0; i < file.length; i++) { |
| 302 | 0 | Element fileEntryElement = document.createElement("FileEntry"); |
| 303 | 0 | fileEntryElement.setAttribute("value", "" + file[i].getFile()); |
| 304 | 0 | fileElement.appendChild(fileEntryElement); |
| 305 | } | |
| 306 | 0 | backupElement.appendChild(fileElement); |
| 307 | ||
| 308 | 0 | return backupElement; |
| 309 | } | |
| 310 | ||
| 311 | /** | |
| 312 | * @param creationDate | |
| 313 | * The creationDate to set. | |
| 314 | */ | |
| 315 | public void setCreationDate(Date creationDate) { | |
| 316 | 0 | this.creationDate = creationDate; |
| 317 | 0 | } |
| 318 | ||
| 319 | /** | |
| 320 | * @param expirationDate | |
| 321 | * The expirationDate to set. | |
| 322 | */ | |
| 323 | public void setExpirationDate(Date expirationDate) { | |
| 324 | 0 | this.expirationDate = expirationDate; |
| 325 | 0 | } |
| 326 | ||
| 327 | /** | |
| 328 | * @param securityLevel | |
| 329 | * The securityLevel to set. | |
| 330 | */ | |
| 331 | public void setSecurityLevel(SecurityLevel securityLevel) { | |
| 332 | 0 | this.securityLevel = securityLevel; |
| 333 | 0 | } |
| 334 | ||
| 335 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |