root / trunk / extensions / extProjectBackup / src / org / gvsig / backup / BackupConfig.java @ 27797
History | View | Annotate | Download (3.76 KB)
1 |
package org.gvsig.backup; |
---|---|
2 |
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government
|
4 |
*
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
6 |
* of the Valencian Government (CIT)
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
21 |
* MA 02110-1301, USA.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
import com.iver.andami.PluginServices; |
26 |
import com.iver.utiles.IPersistence; |
27 |
import com.iver.utiles.XMLEntity; |
28 |
|
29 |
/**
|
30 |
* Stores the backup configuration in memory, and offers a simple
|
31 |
* interface to change them.
|
32 |
*
|
33 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
34 |
*/
|
35 |
public class BackupConfig implements IPersistence { |
36 |
public static final String BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID = "backup_project_to_be_overwritten"; |
37 |
|
38 |
protected boolean backupProjectToBeOverwritten = false; // By default -> false |
39 |
protected XMLEntity xmlConfig = null; |
40 |
|
41 |
/**
|
42 |
* Creates a new BackupConfig instance
|
43 |
*/
|
44 |
public BackupConfig() {
|
45 |
super();
|
46 |
|
47 |
initConfig(); |
48 |
} |
49 |
|
50 |
/*
|
51 |
* @see com.iver.utiles.IPersistance#getClassName()
|
52 |
*/
|
53 |
public String getClassName() { |
54 |
return this.getClass().getName(); |
55 |
} |
56 |
|
57 |
/*
|
58 |
* (non-Javadoc)
|
59 |
* @see com.iver.utiles.IPersistance#getXMLEntity()
|
60 |
*/
|
61 |
public XMLEntity getXMLEntity() {
|
62 |
XMLEntity xml = new XMLEntity();
|
63 |
xml.putProperty(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID, backupProjectToBeOverwritten); |
64 |
|
65 |
return xml;
|
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see com.iver.utiles.IPersistance#setXMLEntity(com.iver.utiles.XMLEntity)
|
71 |
*/
|
72 |
public void setXMLEntity(XMLEntity xml) { |
73 |
if (xml.contains(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID)) {
|
74 |
backupProjectToBeOverwritten = xml.getBooleanProperty(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID); |
75 |
} |
76 |
else {
|
77 |
backupProjectToBeOverwritten = false; // By default -> false |
78 |
} |
79 |
} |
80 |
|
81 |
/**
|
82 |
* Sets the XML property {@link BackupConfig#BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID BackupConfig#BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID}
|
83 |
*
|
84 |
* @param b the value to persist
|
85 |
*/
|
86 |
public void setBackupProjectToBeOverwritten(boolean b) { |
87 |
backupProjectToBeOverwritten = b; |
88 |
xmlConfig.putProperty(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID, backupProjectToBeOverwritten); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Gets the XML property {@link BackupConfig#BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID BackupConfig#BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID}
|
93 |
*
|
94 |
* @return the value to persist
|
95 |
*/
|
96 |
public boolean isBackupProjectToBeOverwritten() { |
97 |
return backupProjectToBeOverwritten;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* Initializes the configuration of the associated extension.
|
102 |
*/
|
103 |
private void initConfig() { |
104 |
PluginServices ps = PluginServices.getPluginServices(this);
|
105 |
XMLEntity xml = ps.getPersistentXML(); |
106 |
XMLEntity child; |
107 |
boolean found = false; |
108 |
|
109 |
for (int i=0; i<xml.getChildrenCount(); i++) { |
110 |
child = xml.getChild(i); |
111 |
if (child.contains(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID)) {
|
112 |
setXMLEntity(child); |
113 |
found = true;
|
114 |
xmlConfig = child; |
115 |
backupProjectToBeOverwritten = child.getBooleanProperty(BACKUP_PROJECT_TO_BE_OVERWRITTEN_ID); |
116 |
} |
117 |
} |
118 |
if (!found) {
|
119 |
child = getXMLEntity(); |
120 |
xml.addChild(child); |
121 |
xmlConfig = child; |
122 |
backupProjectToBeOverwritten = false;
|
123 |
} |
124 |
} |
125 |
} |