root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / imp / DefaultPreferencesNode.java @ 31496
History | View | Annotate | Download (4.09 KB)
1 |
package org.gvsig.app.imp; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import org.gvsig.andami.PluginServices; |
6 |
import org.gvsig.app.PreferencesNode; |
7 |
import org.gvsig.utils.StringUtilities; |
8 |
import org.gvsig.utils.XMLEntity; |
9 |
|
10 |
public class DefaultPreferencesNode implements PreferencesNode { |
11 |
|
12 |
private String name; |
13 |
private XMLEntity node;
|
14 |
|
15 |
public DefaultPreferencesNode() {
|
16 |
this.name = null; |
17 |
} |
18 |
|
19 |
public DefaultPreferencesNode(String nodeName) { |
20 |
this.name = nodeName;
|
21 |
} |
22 |
|
23 |
protected XMLEntity getRootNode() {
|
24 |
XMLEntity node = PluginServices.getPluginServices("org.gvsig.app") .getPersistentXML();
|
25 |
return node;
|
26 |
} |
27 |
|
28 |
protected XMLEntity getNode() {
|
29 |
if( this.node == null ) { |
30 |
if( this.name == null ) { |
31 |
this.node = this.getRootNode(); |
32 |
} else {
|
33 |
this.node = this.getRootNode().firstChild(this.name); |
34 |
} |
35 |
} |
36 |
return this.node; |
37 |
} |
38 |
|
39 |
public String name() { |
40 |
return this.name; |
41 |
} |
42 |
|
43 |
public String[] keys() throws Exception { |
44 |
XMLEntity node = this.getNode();
|
45 |
int count = node.getChildrenCount();
|
46 |
String[] keys = new String[count]; |
47 |
for(int i=0 ; i<count ; i++ ) { |
48 |
keys[i] = node.getChild(i).getName(); |
49 |
} |
50 |
return keys;
|
51 |
} |
52 |
|
53 |
public void clear() throws Exception { |
54 |
XMLEntity node = this.getNode();
|
55 |
node.removeAllChildren(); |
56 |
} |
57 |
|
58 |
public void flush() throws Exception { |
59 |
// do nothing
|
60 |
} |
61 |
|
62 |
public String get(String name, String defaultValue) { |
63 |
XMLEntity node = this.getNode();
|
64 |
|
65 |
if (!node.contains(name)) {
|
66 |
return defaultValue;
|
67 |
} |
68 |
String value = node.getStringProperty(name);
|
69 |
return value;
|
70 |
} |
71 |
|
72 |
public boolean getBoolean(String name, boolean defaultValue) { |
73 |
XMLEntity node = this.getNode();
|
74 |
|
75 |
if (!node.contains(name)) {
|
76 |
return defaultValue;
|
77 |
} |
78 |
boolean value = node.getBooleanProperty(name);
|
79 |
return value;
|
80 |
} |
81 |
|
82 |
public byte[] getByteArray(String name, byte[] defaultValue) { |
83 |
XMLEntity node = this.getNode();
|
84 |
|
85 |
if (!node.contains(name)) {
|
86 |
return defaultValue;
|
87 |
} |
88 |
byte[] value = node.getByteArrayProperty(name); |
89 |
return value;
|
90 |
} |
91 |
|
92 |
public double getDouble(String name, double defaultValue) { |
93 |
XMLEntity node = this.getNode();
|
94 |
|
95 |
if (!node.contains(name)) {
|
96 |
return defaultValue;
|
97 |
} |
98 |
double value = node.getDoubleProperty(name);
|
99 |
return value;
|
100 |
} |
101 |
|
102 |
public float getFloat(String name, float defaultValue) { |
103 |
XMLEntity node = this.getNode();
|
104 |
|
105 |
if (!node.contains(name)) {
|
106 |
return defaultValue;
|
107 |
} |
108 |
float value = node.getFloatProperty(name);
|
109 |
return value;
|
110 |
} |
111 |
|
112 |
public int getInt(String name, int defaultValue) { |
113 |
XMLEntity node = this.getNode();
|
114 |
|
115 |
if (!node.contains(name)) {
|
116 |
return defaultValue;
|
117 |
} |
118 |
int value = node.getIntProperty(name);
|
119 |
return value;
|
120 |
} |
121 |
|
122 |
public long getLong(String name, long defaultValue) { |
123 |
XMLEntity node = this.getNode();
|
124 |
|
125 |
if (!node.contains(name)) {
|
126 |
return defaultValue;
|
127 |
} |
128 |
long value = node.getLongProperty(name);
|
129 |
return value;
|
130 |
} |
131 |
|
132 |
public Color getColor(String name, Color defaultValue) { |
133 |
XMLEntity node = this.getNode();
|
134 |
|
135 |
if (!node.contains(name)) {
|
136 |
return defaultValue;
|
137 |
} |
138 |
String value = node.getStringProperty(name);
|
139 |
return StringUtilities.string2Color(value);
|
140 |
} |
141 |
|
142 |
public void put(String name, String value) { |
143 |
XMLEntity node = this.getNode();
|
144 |
|
145 |
node.putProperty(name, value); |
146 |
} |
147 |
|
148 |
public void putBoolean(String name, boolean value) { |
149 |
XMLEntity node = this.getNode();
|
150 |
|
151 |
node.putProperty(name, value); |
152 |
} |
153 |
|
154 |
public void putByteArray(String name, byte[] value) { |
155 |
XMLEntity node = this.getNode();
|
156 |
|
157 |
node.putProperty(name, value); |
158 |
} |
159 |
|
160 |
public void putDouble(String name, double value) { |
161 |
XMLEntity node = this.getNode();
|
162 |
|
163 |
node.putProperty(name, value); |
164 |
} |
165 |
|
166 |
public void putFloat(String name, float value) { |
167 |
XMLEntity node = this.getNode();
|
168 |
|
169 |
node.putProperty(name, value); |
170 |
} |
171 |
|
172 |
public void putInt(String name, int value) { |
173 |
XMLEntity node = this.getNode();
|
174 |
|
175 |
node.putProperty(name, value); |
176 |
} |
177 |
|
178 |
public void putLong(String name, long value) { |
179 |
XMLEntity node = this.getNode();
|
180 |
|
181 |
node.putProperty(name, value); |
182 |
} |
183 |
|
184 |
public void remove(String name) { |
185 |
XMLEntity node = this.getNode();
|
186 |
|
187 |
if (!node.contains(name)) {
|
188 |
return;
|
189 |
} |
190 |
node.remove(name); |
191 |
} |
192 |
|
193 |
public void sync() throws Exception { |
194 |
// do nothing
|
195 |
} |
196 |
|
197 |
} |