1 |
1 |
package org.txm.core.preferences;
|
2 |
2 |
|
3 |
|
import java.lang.reflect.Field;
|
4 |
3 |
import java.util.ArrayList;
|
5 |
4 |
import java.util.Arrays;
|
|
5 |
import java.util.Iterator;
|
|
6 |
import java.util.Set;
|
6 |
7 |
|
7 |
8 |
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
8 |
9 |
import org.eclipse.core.runtime.preferences.DefaultScope;
|
... | ... | |
10 |
11 |
import org.eclipse.core.runtime.preferences.IScopeContext;
|
11 |
12 |
import org.eclipse.core.runtime.preferences.InstanceScope;
|
12 |
13 |
import org.osgi.service.prefs.BackingStoreException;
|
13 |
|
import org.txm.core.results.ITXMResult;
|
|
14 |
import org.txm.core.results.TXMResult;
|
|
15 |
import org.txm.core.results.TXMParameters;
|
14 |
16 |
|
15 |
17 |
|
16 |
18 |
|
... | ... | |
23 |
25 |
* - alternative specified global value
|
24 |
26 |
* - alternative specified default value
|
25 |
27 |
* TODO: methods that puts a value in the local node does not check if the value is the default value of the parent, it should be removed from the local node if it's the default value
|
26 |
|
* of command scope or alternative scope so the preference will not be saved in the local scope .prefs file if its a default value.
|
|
28 |
* of command scope or alternative scope so the preference will not be saved in the local scope .prefs file if its a default value.
|
27 |
29 |
* TODO: when we'll use IProject for managing Corporas, the local node should be stored in the ProjectScope instead of in the InstanceScope.
|
28 |
30 |
* TODO: need to determine if we'll use this class to persistence of TXM results. At this moment, we persist result by calling flush() that creates a file named by the result node qualifier,
|
29 |
31 |
* eg. org.txm.partition.core.functions.PartitionDimensions@732982cb.prefs
|
30 |
32 |
* (We can also define a custom Scope to do that, for example to change the saved object location or the filename)
|
31 |
|
*
|
32 |
|
*
|
|
33 |
*
|
|
34 |
*
|
33 |
35 |
* @author sjacquot
|
34 |
36 |
*
|
35 |
37 |
*/
|
... | ... | |
38 |
40 |
// Otherwise, to avoid that we need to define our own Scope, but the problem will disappear when
|
39 |
41 |
// we'll use the ProjectScope.
|
40 |
42 |
public abstract class TXMPreferences extends AbstractPreferenceInitializer {
|
41 |
|
|
42 |
|
// FIXME: here we must use a ProjectScope when we use IProject for the corporas of TXM
|
|
43 |
|
|
44 |
// FIXME: here we must use a ProjectScope when we'll use IProject for the corporas of TXM
|
43 |
45 |
public static IScopeContext scope = InstanceScope.INSTANCE;
|
44 |
|
|
|
46 |
|
45 |
47 |
/**
|
46 |
48 |
* Alternative nodes to look up when getting a preference.
|
47 |
49 |
*/
|
48 |
50 |
public static ArrayList<String> alternativeNodesQualifiers = new ArrayList<String>();
|
49 |
|
|
|
51 |
|
50 |
52 |
/**
|
51 |
53 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
52 |
54 |
* @param result
|
53 |
55 |
* @param key
|
54 |
56 |
* @param value
|
55 |
57 |
*/
|
56 |
|
public static void putLocalBoolean(ITXMResult result, String key, boolean value) {
|
57 |
|
scope.getNode(getId(result)).putBoolean(key, value);
|
|
58 |
public static void putLocalBoolean(TXMResult result, String key, boolean value) {
|
|
59 |
scope.getNode(result.getUUID()).putBoolean(key, value);
|
58 |
60 |
}
|
59 |
|
|
60 |
|
|
61 |
61 |
|
|
62 |
|
62 |
63 |
/**
|
|
64 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
65 |
* Returns the value of a key in the specified parameters if exists.
|
|
66 |
* Otherwise try to get it from the local result node if exists.
|
|
67 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
68 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
69 |
* Returns <code>false</code> if no value has been found for the specified key.
|
|
70 |
* @param commandParameters
|
|
71 |
* @param nodeQualifier
|
|
72 |
* @param result
|
|
73 |
* @param key
|
|
74 |
* @return
|
|
75 |
*/
|
|
76 |
public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
77 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
78 |
return (Boolean) commandParameters.get(key);
|
|
79 |
}
|
|
80 |
return getBoolean(key, result, nodeQualifier);
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
public static boolean getBoolean(String key, TXMParameters commandParameters, TXMResult result) {
|
|
85 |
return getBoolean(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
63 |
89 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
64 |
90 |
* Returns the value of the local result node if exists.
|
65 |
91 |
* Otherwise try to get it from the specified node qualifier if exists.
|
66 |
92 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
67 |
|
* Returns <code>true</code> if no value has been found for the specified key.
|
|
93 |
* Returns defaultValue if no value has been found for the specified key.
|
68 |
94 |
* @param nodeQualifier
|
69 |
95 |
* @param result
|
70 |
96 |
* @param key
|
71 |
97 |
* @return
|
72 |
98 |
*/
|
73 |
|
public static boolean getBoolean(String nodeQualifier, ITXMResult result, String key, boolean defaultValue) {
|
|
99 |
public static boolean getBoolean(String key, TXMResult result, String nodeQualifier, boolean defaultValue) {
|
74 |
100 |
|
75 |
101 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
76 |
|
|
|
102 |
|
77 |
103 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getBoolean(key, defaultValue);
|
78 |
104 |
return scope.getNode(nodeQualifier).getBoolean(key, defaultValue);
|
79 |
105 |
}
|
80 |
|
|
81 |
|
public static boolean getBoolean(String nodeQualifier, ITXMResult result, String key) {
|
82 |
|
return getBoolean(nodeQualifier, result, key, false);
|
83 |
|
}
|
84 |
|
|
|
106 |
|
85 |
107 |
/**
|
86 |
|
*
|
|
108 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
109 |
* Returns the value of the local result node if exists.
|
|
110 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
111 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
112 |
* Returns <code>false</code> if no value has been found for the specified key.
|
87 |
113 |
* @param nodeQualifier
|
|
114 |
* @param result
|
88 |
115 |
* @param key
|
89 |
116 |
* @return
|
90 |
117 |
*/
|
91 |
|
public static boolean getBoolean(String nodeQualifier, String key, boolean defaultValue) {
|
92 |
|
return getBoolean(nodeQualifier, null, key, defaultValue);
|
|
118 |
public static boolean getBoolean(String key, TXMResult result, String nodeQualifier) {
|
|
119 |
return getBoolean(key, result, nodeQualifier, false);
|
93 |
120 |
}
|
94 |
|
|
|
121 |
|
95 |
122 |
/**
|
96 |
|
*
|
|
123 |
*
|
97 |
124 |
* @param nodeQualifier
|
98 |
125 |
* @param key
|
99 |
126 |
* @return
|
100 |
127 |
*/
|
101 |
|
public static boolean getBoolean(String nodeQualifier, String key) {
|
102 |
|
return getBoolean(nodeQualifier, null, key, false);
|
|
128 |
public static boolean getBoolean(String key, String nodeQualifier) {
|
|
129 |
return getBoolean(key, null, nodeQualifier);
|
103 |
130 |
}
|
104 |
|
|
|
131 |
|
105 |
132 |
/**
|
106 |
|
*
|
|
133 |
*
|
107 |
134 |
* @param result
|
108 |
135 |
* @param key
|
109 |
136 |
* @return
|
110 |
137 |
*/
|
111 |
|
public static boolean getBoolean(ITXMResult result, String key) {
|
112 |
|
return getBoolean(null, result, key);
|
|
138 |
public static boolean getBoolean(String key, TXMResult result) {
|
|
139 |
return getBoolean(key, result, null);
|
113 |
140 |
}
|
114 |
|
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
115 |
145 |
/**
|
|
146 |
* Try to cast and create a typed object from the String value of the key.
|
|
147 |
* @param commandParameters
|
|
148 |
* @param result
|
|
149 |
* @param nodeQualifier
|
|
150 |
* @param key
|
|
151 |
* @return
|
|
152 |
*/
|
|
153 |
//FIXME: does not work, need to test furthermore
|
|
154 |
// public static Object get(TXMCommandParameters commandParameters, TXMResult result, String nodeQualifier, String key) {
|
|
155 |
//
|
|
156 |
//
|
|
157 |
// if(commandParameters != null && commandParameters.get(key) != null) {
|
|
158 |
// return commandParameters.get(key);
|
|
159 |
// }
|
|
160 |
//
|
|
161 |
// nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
|
162 |
//
|
|
163 |
// String stringValue = getString(nodeQualifier, key);
|
|
164 |
//
|
|
165 |
// try {
|
|
166 |
// // double
|
|
167 |
// try {
|
|
168 |
// return Double.parseDouble(stringValue);
|
|
169 |
// }
|
|
170 |
// catch(NumberFormatException e) {
|
|
171 |
// }
|
|
172 |
// // float
|
|
173 |
// try {
|
|
174 |
// return Float.parseFloat(stringValue);
|
|
175 |
// }
|
|
176 |
// catch(NumberFormatException e) {
|
|
177 |
// }
|
|
178 |
// // long
|
|
179 |
// try {
|
|
180 |
// return Long.parseLong(stringValue);
|
|
181 |
// }
|
|
182 |
// catch(NumberFormatException e) {
|
|
183 |
// }
|
|
184 |
// // integer
|
|
185 |
// try {
|
|
186 |
// return Integer.parseInt(stringValue);
|
|
187 |
// }
|
|
188 |
// catch(NumberFormatException e) {
|
|
189 |
// }
|
|
190 |
// // short
|
|
191 |
// try {
|
|
192 |
// return Short.parseShort(stringValue);
|
|
193 |
// }
|
|
194 |
// catch(NumberFormatException e) {
|
|
195 |
// }
|
|
196 |
// // boolean
|
|
197 |
// try {
|
|
198 |
// return Boolean.parseBoolean(stringValue);
|
|
199 |
// }
|
|
200 |
// catch(NumberFormatException e) {
|
|
201 |
// }
|
|
202 |
// }
|
|
203 |
// catch(Exception e) {
|
|
204 |
// // TODO Auto-generated catch block
|
|
205 |
// e.printStackTrace();
|
|
206 |
// System.err.println("TXMPreferences.get(): can't parse and primitive cast the specified string value: " + stringValue + "."); //$NON-NLS-1$
|
|
207 |
// }
|
|
208 |
// return stringValue;
|
|
209 |
// }
|
|
210 |
|
|
211 |
/**
|
116 |
212 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
117 |
213 |
* @param result
|
118 |
214 |
* @param key
|
119 |
215 |
* @param value
|
120 |
216 |
*/
|
121 |
|
public static void putLocalString(ITXMResult result, String key, String value) {
|
122 |
|
scope.getNode(getId(result)).put(key, value);
|
|
217 |
public static void putLocalString(TXMResult result, String key, String value) {
|
|
218 |
scope.getNode(result.getUUID()).put(key, value);
|
123 |
219 |
}
|
124 |
|
|
125 |
220 |
|
|
221 |
|
|
222 |
|
126 |
223 |
/**
|
127 |
|
* Looks for the value of the specified <code>key</code> in preference nodes.
|
128 |
|
* Returns the value of the local result node if exists.
|
|
224 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
225 |
* Returns the value of a key in the specified parameters if exists.
|
|
226 |
* Otherwise try to get it from the local result node if exists.
|
129 |
227 |
* Otherwise try to get it from the specified node qualifier if exists.
|
130 |
228 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
131 |
229 |
* Returns an empty <code>String</code> if no value has been found for the specified key.
|
|
230 |
* @param commandParameters
|
132 |
231 |
* @param nodeQualifier
|
133 |
232 |
* @param result
|
134 |
233 |
* @param key
|
135 |
234 |
* @return
|
136 |
235 |
*/
|
137 |
|
public static String getString(String nodeQualifier, ITXMResult result, String key) {
|
138 |
|
String defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).get(key, "");
|
139 |
|
return getString(nodeQualifier, result, key, defaultValue);
|
|
236 |
public static String getString(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
237 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
238 |
return (String) commandParameters.get(key);
|
|
239 |
}
|
|
240 |
return getString(key, result, nodeQualifier);
|
140 |
241 |
}
|
|
242 |
|
|
243 |
public static String getString(String key, TXMParameters commandParameters, TXMResult result) {
|
|
244 |
return getString(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
245 |
}
|
141 |
246 |
|
142 |
|
public static String getString(String nodeQualifier, String key, String defaultValue) {
|
143 |
|
return getString(nodeQualifier, null, key, defaultValue);
|
144 |
|
}
|
145 |
247 |
|
146 |
|
public static String getString(String nodeQualifier, ITXMResult result, String key, String defaultValue) {
|
|
248 |
/**
|
|
249 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
250 |
* Returns the value of the local result node if exists.
|
|
251 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
252 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
253 |
* Returns defaultValue if no value has been found for the specified key.
|
|
254 |
* @param nodeQualifier
|
|
255 |
* @param result
|
|
256 |
* @param key
|
|
257 |
* @return
|
|
258 |
*/
|
|
259 |
public static String getString(String key, TXMResult result, String nodeQualifier, String defaultValue) {
|
147 |
260 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
148 |
|
return scope.getNode(nodeQualifier).get(key, defaultValue);
|
|
261 |
|
|
262 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).get(key, defaultValue);
|
|
263 |
return scope.getNode(nodeQualifier).get(key, defaultValue);
|
149 |
264 |
}
|
150 |
|
|
|
265 |
|
|
266 |
|
151 |
267 |
/**
|
152 |
|
*
|
|
268 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
269 |
* Returns the value of the local result node if exists.
|
|
270 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
271 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
272 |
* Returns an empty <code>String</code> if no value has been found for the specified key.
|
153 |
273 |
* @param nodeQualifier
|
|
274 |
* @param result
|
154 |
275 |
* @param key
|
155 |
276 |
* @return
|
156 |
277 |
*/
|
157 |
|
public static String getString(String nodeQualifier, String key) {
|
158 |
|
String defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).get(key, "");
|
159 |
|
return getString(nodeQualifier, null, key, defaultValue);
|
|
278 |
public static String getString(String key, TXMResult result, String nodeQualifier) {
|
|
279 |
return getString(key, result, nodeQualifier, "");
|
160 |
280 |
}
|
161 |
|
|
162 |
|
|
|
281 |
|
|
282 |
|
163 |
283 |
/**
|
164 |
|
*
|
|
284 |
*
|
|
285 |
* @param nodeQualifier
|
|
286 |
* @param key
|
|
287 |
* @return
|
|
288 |
*/
|
|
289 |
public static String getString(String key, String nodeQualifier) {
|
|
290 |
return getString(key, null, nodeQualifier);
|
|
291 |
}
|
|
292 |
|
|
293 |
|
|
294 |
/**
|
|
295 |
*
|
165 |
296 |
* @param result
|
166 |
297 |
* @param key
|
167 |
298 |
* @return
|
168 |
299 |
*/
|
169 |
|
public static String getString(ITXMResult result, String key) {
|
170 |
|
return getString(null, result, key);
|
|
300 |
public static String getString(String key, TXMResult result) {
|
|
301 |
return getString(key, result, null);
|
171 |
302 |
}
|
172 |
303 |
|
|
304 |
|
|
305 |
|
173 |
306 |
/**
|
174 |
307 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
175 |
308 |
* @param result
|
176 |
309 |
* @param key
|
177 |
310 |
* @param value
|
178 |
311 |
*/
|
179 |
|
public static void putLocalInt(ITXMResult result, String key, int value) {
|
180 |
|
scope.getNode(getId(result)).putInt(key, value);
|
|
312 |
public static void putLocalInt(TXMResult result, String key, int value) {
|
|
313 |
scope.getNode(result.getUUID()).putInt(key, value);
|
181 |
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
/**
|
|
318 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
319 |
* Returns the value of a key in the specified parameters if exists.
|
|
320 |
* Otherwise try to get it from the local result node if exists.
|
|
321 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
322 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
323 |
* Returns 0 if no value has been found for the specified key.
|
|
324 |
* @param commandParameters
|
|
325 |
* @param nodeQualifier
|
|
326 |
* @param result
|
|
327 |
* @param key
|
|
328 |
* @return
|
|
329 |
*/
|
|
330 |
public static int getInt(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
331 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
332 |
return (Integer) commandParameters.get(key);
|
|
333 |
}
|
|
334 |
return getInt(key, result, nodeQualifier);
|
|
335 |
}
|
|
336 |
|
|
337 |
|
|
338 |
public static int getInt(String key, TXMParameters commandParameters, TXMResult result) {
|
|
339 |
return getInt(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
340 |
}
|
182 |
341 |
|
|
342 |
|
|
343 |
|
183 |
344 |
/**
|
184 |
345 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
185 |
346 |
* Returns the value of the local result node if exists.
|
186 |
347 |
* Otherwise try to get it from the specified node qualifier if exists.
|
187 |
348 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
188 |
|
* Returns -1 if no value has been found for the specified key.
|
|
349 |
* Returns defaultValue if no value has been found for the specified key.
|
189 |
350 |
* @param nodeQualifier
|
190 |
351 |
* @param result
|
191 |
352 |
* @param key
|
192 |
353 |
* @param defaultValue
|
193 |
354 |
* @return
|
194 |
355 |
*/
|
195 |
|
public static int getInt(String nodeQualifier, ITXMResult result, String key, int defaultValue) {
|
|
356 |
public static int getInt(String key, TXMResult result, String nodeQualifier, int defaultValue) {
|
|
357 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
196 |
358 |
|
197 |
|
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
|
359 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getInt(key, defaultValue);
|
198 |
360 |
return scope.getNode(nodeQualifier).getInt(key, defaultValue);
|
199 |
|
|
|
361 |
|
200 |
362 |
}
|
201 |
|
|
|
363 |
|
202 |
364 |
/**
|
203 |
365 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
204 |
366 |
* Returns the value of the local result node if exists.
|
205 |
367 |
* Otherwise try to get it from the specified node qualifier if exists.
|
206 |
368 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
207 |
|
* Returns -1 if no value has been found for the specified key.
|
|
369 |
* Returns 0 if no value has been found for the specified key.
|
208 |
370 |
* @param nodeQualifier
|
209 |
371 |
* @param result
|
210 |
372 |
* @param key
|
|
373 |
* @param defaultValue
|
211 |
374 |
* @return
|
212 |
375 |
*/
|
213 |
|
public static int getInt(String nodeQualifier, ITXMResult result, String key) {
|
214 |
|
int defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getInt(key, 0);
|
215 |
|
return getInt(nodeQualifier, result, key, defaultValue);
|
|
376 |
public static int getInt(String key, TXMResult result, String nodeQualifier) {
|
|
377 |
return getInt(key, result, nodeQualifier, 0);
|
216 |
378 |
}
|
217 |
|
|
|
379 |
|
218 |
380 |
/**
|
219 |
|
*
|
|
381 |
*
|
220 |
382 |
* @param nodeQualifier
|
221 |
383 |
* @param key
|
|
384 |
* @return
|
|
385 |
*/
|
|
386 |
public static int getInt(String key, String nodeQualifier) {
|
|
387 |
return getInt(key, null, nodeQualifier);
|
|
388 |
}
|
|
389 |
|
|
390 |
/**
|
|
391 |
*
|
|
392 |
* @param result
|
|
393 |
* @param key
|
|
394 |
* @return
|
|
395 |
*/
|
|
396 |
public static int getInt(String key, TXMResult result) {
|
|
397 |
return getInt(key, result, null);
|
|
398 |
}
|
|
399 |
|
|
400 |
|
|
401 |
/**
|
|
402 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
|
403 |
* @param result
|
|
404 |
* @param key
|
|
405 |
* @param value
|
|
406 |
*/
|
|
407 |
public static void putLocalLong(TXMResult result, String key, long value) {
|
|
408 |
scope.getNode(result.getUUID()).putLong(key, value);
|
|
409 |
}
|
|
410 |
|
|
411 |
|
|
412 |
/**
|
|
413 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
414 |
* Returns the value of a key in the specified parameters if exists.
|
|
415 |
* Otherwise try to get it from the local result node if exists.
|
|
416 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
417 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
418 |
* Returns 0L if no value has been found for the specified key.
|
|
419 |
* @param commandParameters
|
|
420 |
* @param nodeQualifier
|
|
421 |
* @param result
|
|
422 |
* @param key
|
|
423 |
* @return
|
|
424 |
*/
|
|
425 |
public static long getLong(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
426 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
427 |
return (Long) commandParameters.get(key);
|
|
428 |
}
|
|
429 |
return getLong(key, result, nodeQualifier);
|
|
430 |
}
|
|
431 |
|
|
432 |
public static long getLong(String key, TXMParameters commandParameters, TXMResult result) {
|
|
433 |
return getLong(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
434 |
}
|
|
435 |
|
|
436 |
|
|
437 |
|
|
438 |
/**
|
|
439 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
440 |
* Returns the value of the local result node if exists.
|
|
441 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
442 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
443 |
* Returns defaultValue if no value has been found for the specified key.
|
|
444 |
* @param nodeQualifier
|
|
445 |
* @param result
|
|
446 |
* @param key
|
222 |
447 |
* @param defaultValue
|
223 |
448 |
* @return
|
224 |
449 |
*/
|
225 |
|
public static int getInt(String nodeQualifier, String key, int defaultValue) {
|
226 |
|
return getInt(nodeQualifier, null, key, defaultValue);
|
|
450 |
public static long getLong(String key, TXMResult result, String nodeQualifier, long defaultValue) {
|
|
451 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
|
452 |
|
|
453 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getLong(key, defaultValue);
|
|
454 |
return scope.getNode(nodeQualifier).getLong(key, defaultValue);
|
|
455 |
|
227 |
456 |
}
|
228 |
|
|
|
457 |
|
229 |
458 |
/**
|
230 |
|
*
|
|
459 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
460 |
* Returns the value of the local result node if exists.
|
|
461 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
462 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
463 |
* Returns 0L if no value has been found for the specified key.
|
231 |
464 |
* @param nodeQualifier
|
|
465 |
* @param result
|
232 |
466 |
* @param key
|
|
467 |
* @param defaultValue
|
233 |
468 |
* @return
|
234 |
469 |
*/
|
235 |
|
public static int getInt(String nodeQualifier, String key) {
|
236 |
|
return getInt(nodeQualifier, null, key);
|
|
470 |
public static long getLong(String key, TXMResult result, String nodeQualifier) {
|
|
471 |
return getLong(key, result, nodeQualifier, 0L);
|
237 |
472 |
}
|
238 |
473 |
|
239 |
|
|
240 |
474 |
/**
|
241 |
|
*
|
|
475 |
*
|
|
476 |
* @param nodeQualifier
|
|
477 |
* @param key
|
|
478 |
* @return
|
|
479 |
*/
|
|
480 |
public static long getLong(String key, String nodeQualifier) {
|
|
481 |
return getLong(key, null, nodeQualifier);
|
|
482 |
}
|
|
483 |
|
|
484 |
/**
|
|
485 |
*
|
242 |
486 |
* @param result
|
243 |
487 |
* @param key
|
244 |
488 |
* @return
|
245 |
489 |
*/
|
246 |
|
public static int getInt(ITXMResult result, String key) {
|
247 |
|
return getInt(null, result, key);
|
|
490 |
public static long getLong(String key, TXMResult result) {
|
|
491 |
return getLong(key, result, null);
|
248 |
492 |
}
|
249 |
493 |
|
250 |
|
|
|
494 |
|
251 |
495 |
/**
|
252 |
496 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
253 |
497 |
* @param result
|
254 |
498 |
* @param key
|
255 |
499 |
* @param value
|
256 |
500 |
*/
|
257 |
|
public static void putLocalDouble(ITXMResult result, String key, double value) {
|
258 |
|
scope.getNode(getId(result)).putDouble(key, value);
|
|
501 |
public static void putLocalDouble(TXMResult result, String key, double value) {
|
|
502 |
scope.getNode(result.getUUID()).putDouble(key, value);
|
259 |
503 |
}
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
/**
|
|
508 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
509 |
* Returns the value of a key in the specified parameters if exists.
|
|
510 |
* Otherwise try to get it from the local result node if exists.
|
|
511 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
512 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
513 |
* Returns 0.0d if no value has been found for the specified key.
|
|
514 |
* @param commandParameters
|
|
515 |
* @param nodeQualifier
|
|
516 |
* @param result
|
|
517 |
* @param key
|
|
518 |
* @return
|
|
519 |
*/
|
|
520 |
public static double getDouble(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
521 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
522 |
return (Double) commandParameters.get(key);
|
|
523 |
}
|
|
524 |
return getDouble(key, result, nodeQualifier);
|
|
525 |
}
|
|
526 |
|
|
527 |
public static double getDouble(String key, TXMParameters commandParameters, TXMResult result) {
|
|
528 |
return getDouble(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
529 |
}
|
|
530 |
|
260 |
531 |
|
261 |
532 |
/**
|
262 |
533 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
263 |
534 |
* Returns the value of the local result node if exists.
|
264 |
535 |
* Otherwise try to get it from the specified node qualifier if exists.
|
265 |
536 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
266 |
|
* Returns -1 if no value has been found for the specified key.
|
|
537 |
* Returns defaultValue if no value has been found for the specified key.
|
267 |
538 |
* @param nodeQualifier
|
268 |
539 |
* @param result
|
269 |
540 |
* @param key
|
270 |
541 |
* @return
|
271 |
542 |
*/
|
272 |
|
public static double getDouble(String nodeQualifier, ITXMResult result, String key, double defaultValue) {
|
|
543 |
public static double getDouble(String key, String nodeQualifier, TXMResult result, double defaultValue) {
|
273 |
544 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
|
545 |
|
|
546 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getDouble(key, defaultValue);
|
274 |
547 |
return scope.getNode(nodeQualifier).getDouble(key, defaultValue);
|
275 |
548 |
}
|
276 |
|
|
|
549 |
|
277 |
550 |
/**
|
278 |
|
*
|
|
551 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
|
552 |
* Returns the value of the local result node if exists.
|
|
553 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
554 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
555 |
* Returns 0.0d if no value has been found for the specified key.
|
279 |
556 |
* @param nodeQualifier
|
|
557 |
* @param result
|
280 |
558 |
* @param key
|
281 |
559 |
* @return
|
282 |
560 |
*/
|
283 |
|
public static double getDouble(String nodeQualifier, String key, double defaultValue) {
|
284 |
|
return getDouble(nodeQualifier, null, key, defaultValue);
|
|
561 |
public static double getDouble(String key, TXMResult result, String nodeQualifier) {
|
|
562 |
return getDouble(key, nodeQualifier, result, 0.0d);
|
285 |
563 |
}
|
286 |
|
|
|
564 |
|
|
565 |
|
287 |
566 |
/**
|
288 |
|
*
|
|
567 |
*
|
289 |
568 |
* @param nodeQualifier
|
290 |
569 |
* @param key
|
291 |
570 |
* @return
|
292 |
571 |
*/
|
293 |
|
public static double getDouble(String nodeQualifier, String key) {
|
294 |
|
double defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getDouble(key, 0.0d);
|
295 |
|
return getDouble(nodeQualifier, null, key, defaultValue);
|
|
572 |
public static double getDouble(String key, String nodeQualifier) {
|
|
573 |
return getDouble(key, null, nodeQualifier);
|
296 |
574 |
}
|
297 |
575 |
|
|
576 |
|
298 |
577 |
/**
|
299 |
|
*
|
|
578 |
*
|
300 |
579 |
* @param result
|
301 |
580 |
* @param key
|
302 |
581 |
* @return
|
303 |
582 |
*/
|
304 |
|
public static double getDouble(ITXMResult result, String key, double defaultValue) {
|
305 |
|
return getDouble(null, result, key, defaultValue);
|
|
583 |
public static double getDouble(String key, TXMResult result) {
|
|
584 |
return getDouble(key, result, null);
|
306 |
585 |
}
|
307 |
|
|
|
586 |
|
|
587 |
|
308 |
588 |
/**
|
309 |
589 |
* Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
310 |
590 |
* @param result
|
311 |
591 |
* @param key
|
312 |
592 |
* @param value
|
313 |
593 |
*/
|
314 |
|
public static void putLocalFloat(ITXMResult result, String key, float value) {
|
315 |
|
scope.getNode(getId(result)).putFloat(key, value);
|
|
594 |
public static void putLocalFloat(TXMResult result, String key, float value) {
|
|
595 |
scope.getNode(result.getUUID()).putFloat(key, value);
|
316 |
596 |
}
|
|
597 |
|
|
598 |
|
|
599 |
/**
|
|
600 |
* Looks for the value of the specified <code>key</code> in the specified parameters and preference nodes.
|
|
601 |
* Returns the value of a key in the specified parameters if exists.
|
|
602 |
* Otherwise try to get it from the local result node if exists.
|
|
603 |
* Otherwise try to get it from the specified node qualifier if exists.
|
|
604 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
|
605 |
* Returns 0f if no value has been found for the specified key.
|
|
606 |
* @param commandParameters
|
|
607 |
* @param nodeQualifier
|
|
608 |
* @param result
|
|
609 |
* @param key
|
|
610 |
* @return
|
|
611 |
*/
|
|
612 |
public static float getFloat(String key, TXMParameters commandParameters, TXMResult result, String nodeQualifier) {
|
|
613 |
if(commandParameters != null && commandParameters.get(key) != null) {
|
|
614 |
return (Float) commandParameters.get(key);
|
|
615 |
}
|
|
616 |
return getFloat(key, result, nodeQualifier);
|
|
617 |
}
|
|
618 |
|
|
619 |
public static float getFloat(String key, TXMParameters commandParameters, TXMResult result) {
|
|
620 |
return getFloat(key, commandParameters, result, result.getPreferencesNodeQualifier());
|
|
621 |
}
|
317 |
622 |
|
318 |
623 |
/**
|
319 |
624 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
320 |
625 |
* Returns the value of the local result node if exists.
|
321 |
626 |
* Otherwise try to get it from the specified node qualifier if exists.
|
322 |
627 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
323 |
|
* Returns -1 if no value has been found for the specified key.
|
|
628 |
* Returns defaultValue if no value has been found for the specified key.
|
324 |
629 |
* @param nodeQualifier
|
325 |
630 |
* @param result
|
326 |
631 |
* @param key
|
327 |
632 |
* @return
|
328 |
633 |
*/
|
329 |
|
public static float getFloat(String nodeQualifier, ITXMResult result, String key, float defaultValue) {
|
|
634 |
public static float getFloat(String key, String nodeQualifier, TXMResult result, float defaultValue) {
|
|
635 |
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
330 |
636 |
|
331 |
|
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
332 |
|
return scope.getNode(nodeQualifier).getFloat(key, defaultValue);
|
|
637 |
defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getFloat(key, defaultValue);
|
|
638 |
return scope.getNode(nodeQualifier).getFloat(key, defaultValue);
|
333 |
639 |
}
|
334 |
640 |
|
335 |
|
|
|
641 |
|
336 |
642 |
/**
|
337 |
643 |
* Looks for the value of the specified <code>key</code> in preference nodes.
|
338 |
644 |
* Returns the value of the local result node if exists.
|
339 |
645 |
* Otherwise try to get it from the specified node qualifier if exists.
|
340 |
646 |
* Otherwise try to get it from the specified alternative node qualifiers defined in the list <code>TXMPreferences.alternativeNodesQualifiers</code>.
|
341 |
|
* Returns -1 if no value has been found for the specified key.
|
|
647 |
* Returns 0f if no value has been found for the specified key.
|
342 |
648 |
* @param nodeQualifier
|
343 |
649 |
* @param result
|
344 |
650 |
* @param key
|
345 |
651 |
* @return
|
346 |
652 |
*/
|
347 |
|
public static float getFloat(String nodeQualifier, ITXMResult result, String key) {
|
|
653 |
public static float getFloat(String key, TXMResult result, String nodeQualifier) {
|
|
654 |
return getFloat(key, nodeQualifier, result, 0f);
|
|
655 |
}
|
348 |
656 |
|
349 |
|
nodeQualifier = findNodeQualifier(nodeQualifier, result, key);
|
350 |
|
float defaultValue = DefaultScope.INSTANCE.getNode(nodeQualifier).getFloat(key, 0f);
|
351 |
|
return scope.getNode(nodeQualifier).getFloat(key, defaultValue);
|
352 |
|
}
|
353 |
|
|
354 |
|
|
|
657 |
|
355 |
658 |
/**
|
356 |
|
*
|
|
659 |
*
|
357 |
660 |
* @param nodeQualifier
|
358 |
661 |
* @param key
|
359 |
662 |
* @return
|
360 |
663 |
*/
|
361 |
|
public static float getFloat(String nodeQualifier, String key) {
|
362 |
|
return getFloat(nodeQualifier, null, key, 0f);
|
|
664 |
public static float getFloat(String key, String nodeQualifier) {
|
|
665 |
return getFloat(key, null, nodeQualifier);
|
363 |
666 |
}
|
364 |
|
|
365 |
|
|
|
667 |
|
366 |
668 |
/**
|
367 |
|
*
|
|
669 |
*
|
368 |
670 |
* @param result
|
369 |
671 |
* @param key
|
370 |
672 |
* @return
|
371 |
673 |
*/
|
372 |
|
public static float getFloat(ITXMResult result, String key) {
|
373 |
|
return getFloat(null, result, key, 0f);
|
|
674 |
public static float getFloat(String key, TXMResult result) {
|
|
675 |
return getFloat(key, result, null);
|
374 |
676 |
}
|
375 |
677 |
|
376 |
|
|
|
678 |
|
377 |
679 |
/**
|
378 |
680 |
* Checks if a local node exists for the specified TXM result.
|
379 |
681 |
* @param result
|
380 |
682 |
* @return <code>true</code> if the node exists, otherwise <code>false</code>
|
381 |
683 |
*/
|
382 |
|
public static boolean resultScopeNodeExists(ITXMResult result) {
|
|
684 |
public static boolean resultScopeNodeExists(TXMResult result) {
|
383 |
685 |
if(result == null) {
|
384 |
686 |
return false;
|
385 |
687 |
}
|
386 |
|
return scope.getNode(getId(result)) != null;
|
|
688 |
return scope.getNode(result.getUUID()) != null;
|
387 |
689 |
}
|
388 |
|
|
|
690 |
|
389 |
691 |
/**
|
390 |
692 |
* Checks if a key exists in the local node for the specified TXM result.
|
391 |
693 |
* @param result
|
392 |
694 |
* @param key
|
393 |
695 |
* @return <code>true</code> if the node and the key exist, otherwise <code>false</code>
|
394 |
696 |
*/
|
395 |
|
public static boolean resultScopeKeyExists(ITXMResult result, String key) {
|
396 |
|
return keyExists(getId(result), key);
|
|
697 |
public static boolean resultScopeKeyExists(TXMResult result, String key) {
|
|
698 |
return keyExists(result.getUUID(), key);
|
397 |
699 |
}
|
398 |
700 |
|
399 |
701 |
/**
|
... | ... | |
414 |
716 |
return false;
|
415 |
717 |
}
|
416 |
718 |
|
417 |
|
|
|
719 |
|
418 |
720 |
/**
|
419 |
721 |
* Checks if a preference is defined as empty.
|
420 |
722 |
* Can be used to determine whatever a functionality is available or not by overriding the preference as empty.
|
... | ... | |
424 |
726 |
* @return
|
425 |
727 |
*/
|
426 |
728 |
public static boolean isEmpty(String nodeQualifier, String key) {
|
427 |
|
return getString(nodeQualifier, key).equals("");
|
|
729 |
return getString(key, nodeQualifier).equals("");
|
428 |
730 |
}
|
429 |
731 |
|
430 |
|
|
|
732 |
|
431 |
733 |
/**
|
432 |
734 |
* Sets a preference as empty.
|
433 |
735 |
* Can be used to determine whatever a functionality is available or not by overriding the preference as empty.
|
... | ... | |
438 |
740 |
public static void setEmpty(String nodeQualifier, String key) {
|
439 |
741 |
scope.getNode(nodeQualifier).put(key, "");
|
440 |
742 |
}
|
441 |
|
|
442 |
|
|
|
743 |
|
|
744 |
|
443 |
745 |
/**
|
444 |
746 |
* Dumps the keys and values of the specified node.
|
445 |
747 |
* @param nodeQualifier
|
... | ... | |
458 |
760 |
e.printStackTrace();
|
459 |
761 |
}
|
460 |
762 |
}
|
461 |
|
|
462 |
763 |
|
|
764 |
|
463 |
765 |
/**
|
464 |
766 |
* Dumps the keys and values of the specified node, of the specified result node and also of the alternative nodes.
|
465 |
767 |
* @param nodeQualifier
|
466 |
768 |
* @param result
|
467 |
769 |
*/
|
468 |
|
public static void dump(String nodeQualifier, ITXMResult result) {
|
469 |
|
|
|
770 |
public static void dump(String nodeQualifier, TXMResult result) {
|
|
771 |
|
470 |
772 |
// result scope node
|
471 |
773 |
if(result != null) {
|
472 |
774 |
if(resultScopeNodeExists(result)) {
|
473 |
|
System.out.println("TXMPreferences.dump(): Result scope preferences for node " + getId(result) + ":");
|
474 |
|
dump(getId(result));
|
|
775 |
System.out.println("TXMPreferences.dump(): Result scope preferences for node " + result.getUUID() + ":");
|
|
776 |
dump(result.getUUID());
|
475 |
777 |
}
|
476 |
778 |
else {
|
477 |
|
System.out.println("TXMPreferences.dump(): No result scope preferences was found for node" + getId(result) + ".");
|
|
779 |
System.out.println("TXMPreferences.dump(): No result scope preferences was found for node" + result.getUUID() + ".");
|
478 |
780 |
}
|
479 |
781 |
}
|
480 |
782 |
// command scope node
|
... | ... | |
485 |
787 |
else {
|
486 |
788 |
System.out.println("TXMPreferences.dump(): No Command scope was asked to dump.");
|
487 |
789 |
}
|
488 |
|
|
|
790 |
|
489 |
791 |
// alternative global scope nodes
|
490 |
792 |
for(int i = 0; i < alternativeNodesQualifiers.size(); i++) {
|
491 |
793 |
System.out.println("TXMPreferences.dump(): Alternative global scope preferences for node " + alternativeNodesQualifiers.get(i) + ":");
|
492 |
794 |
dump(alternativeNodesQualifiers.get(i));
|
493 |
795 |
}
|
494 |
796 |
}
|
495 |
|
|
496 |
|
|
|
797 |
|
|
798 |
|
497 |
799 |
/**
|
498 |
|
* Save the local preferences to file.
|
|
800 |
* Saves the local preferences to file.
|
499 |
801 |
* @param result
|
500 |
802 |
*/
|
501 |
|
public static void flush(ITXMResult result) {
|
|
803 |
public static void flush(TXMResult result) {
|
502 |
804 |
try {
|
503 |
|
System.err.println("TXMPreferences.flush(): Local preferences for object " + getId(result) + " saved to file.");
|
|
805 |
System.err.println("TXMPreferences.flush(): Local preferences for object " + result.getUUID() + " saved to file.");
|
504 |
806 |
// FIXME: useless?
|
505 |
807 |
//scope.getNode(getId(result)).sync();
|
506 |
|
scope.getNode(getId(result)).flush();
|
|
808 |
scope.getNode(result.getUUID()).flush();
|
507 |
809 |
}
|
508 |
810 |
catch(BackingStoreException e) {
|
509 |
811 |
// TODO Auto-generated catch block
|
510 |
812 |
e.printStackTrace();
|
511 |
813 |
}
|
512 |
814 |
}
|
513 |
|
|
|
815 |
|
514 |
816 |
/**
|
515 |
|
* Gets a unique Id for the object.
|
516 |
|
* @param object
|
|
817 |
* Deletes the local node if exists.
|
|
818 |
* @param result
|
517 |
819 |
*/
|
518 |
|
public static String getId(ITXMResult object) {
|
519 |
|
return object.getClass().getName() + '@' + Integer.toHexString(object.hashCode());
|
|
820 |
public static void delete(TXMResult result) {
|
|
821 |
try {
|
|
822 |
System.err.println("TXMPreferences.delete() Local preferences for object " + result.getUUID() + " deleted.");
|
|
823 |
scope.getNode(result.getUUID()).removeNode();
|
|
824 |
}
|
|
825 |
catch(BackingStoreException e) {
|
|
826 |
// TODO Auto-generated catch block
|
|
827 |
e.printStackTrace();
|
|
828 |
}
|
520 |
829 |
}
|
521 |
830 |
|
|
831 |
|
|
832 |
|
522 |
833 |
/**
|
523 |
834 |
* Internal method to find the node qualifier of a result otherwise look in instance, default scopes and in alternatives nodes qualifiers.
|
524 |
835 |
* @param result
|
525 |
836 |
* @param key
|
526 |
837 |
*/
|
527 |
|
public static String findNodeQualifier(String nodeQualifier, ITXMResult result, String key) {
|
528 |
|
|
|
838 |
public static String findNodeQualifier(String nodeQualifier, TXMResult result, String key) {
|
|
839 |
|
529 |
840 |
boolean keyExists = (result != null && resultScopeKeyExists(result, key));
|
530 |
841 |
|
531 |
842 |
// get the result scope preference
|
532 |
843 |
if(keyExists) {
|
533 |
|
nodeQualifier = getId(result);
|
|
844 |
nodeQualifier = result.getUUID();
|
534 |
845 |
}
|
535 |
846 |
// look in the global alternative preferences nodes
|
536 |
847 |
else if(!keyExists(nodeQualifier, key)) {
|
... | ... | |
541 |
852 |
}
|
542 |
853 |
}
|
543 |
854 |
}
|
544 |
|
|
|
855 |
|
|
856 |
if(nodeQualifier == null) {
|
|
857 |
try {
|
|
858 |
System.err.println("TXMPreferences.findNodeQualifier(): no node qualifier has been founded (key = " + key + ", TXMResult = " + result + ").");
|
|
859 |
}
|
|
860 |
catch(Exception e) {
|
|
861 |
}
|
|
862 |
}
|
|
863 |
|
545 |
864 |
return nodeQualifier;
|
546 |
865 |
}
|
547 |
|
|
|
866 |
|
548 |
867 |
/**
|
549 |
|
*
|
|
868 |
*
|
550 |
869 |
* @param nodeQualifier
|
551 |
870 |
* @param key
|
552 |
871 |
* @param value
|
... | ... | |
554 |
873 |
public static void put(String nodeQualifier, String key, String value) {
|
555 |
874 |
scope.getNode(nodeQualifier).put(key, value);
|
556 |
875 |
}
|
557 |
|
|
|
876 |
|
558 |
877 |
public static void putString(String nodeQualifier, String key, String value) {
|
559 |
878 |
scope.getNode(nodeQualifier).put(key, value);
|
560 |
879 |
}
|
561 |
880 |
|
562 |
881 |
/**
|
563 |
|
*
|
|
882 |
*
|
564 |
883 |
* @param nodeQualifier
|
565 |
884 |
* @param key
|
566 |
885 |
* @param value
|
... | ... | |
570 |
889 |
}
|
571 |
890 |
|
572 |
891 |
/**
|
573 |
|
*
|
|
892 |
*
|
574 |
893 |
* @param nodeQualifier
|
575 |
894 |
* @param key
|
576 |
895 |
* @param value
|
... | ... | |
580 |
899 |
}
|
581 |
900 |
|
582 |
901 |
/**
|
583 |
|
*
|
|
902 |
*
|
584 |
903 |
* @param nodeQualifier
|
585 |
904 |
* @param key
|
586 |
905 |
* @param value
|
... | ... | |
590 |
909 |
}
|
591 |
910 |
|
592 |
911 |
/**
|
593 |
|
*
|
|
912 |
*
|
594 |
913 |
* @param nodeQualifier
|
595 |
914 |
* @param key
|
596 |
915 |
* @param value
|
... | ... | |
600 |
919 |
}
|
601 |
920 |
|
602 |
921 |
/**
|
603 |
|
*
|
|
922 |
*
|
604 |
923 |
* @param nodeQualifier
|
605 |
924 |
* @param key
|
606 |
925 |
* @param value
|
... | ... | |
610 |
929 |
}
|
611 |
930 |
|
612 |
931 |
/**
|
613 |
|
*
|
|
932 |
*
|
614 |
933 |
* @param nodeQualifier
|
615 |
934 |
* @param key
|
616 |
935 |
* @param value
|
... | ... | |
620 |
939 |
}
|
621 |
940 |
|
622 |
941 |
|
623 |
|
|
624 |
|
public static String getNode(String preferenceName) {
|
625 |
|
// TODO Auto-generated method stub
|
626 |
|
return null;
|
|
942 |
/**
|
|
943 |
* Stores the specified parameters pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
|
944 |
* @param result
|
|
945 |
* @param parameters
|
|
946 |
*/
|
|
947 |
public static void putLocalParameters(TXMResult result, TXMParameters parameters) {
|
|
948 |
Set keys = parameters.keySet();
|
|
949 |
Iterator it = keys.iterator();
|
|
950 |
while (it.hasNext()){
|
|
951 |
Object key = it.next();
|
|
952 |
Object value = parameters.get(key);
|
|
953 |
if(value != null) {
|
|
954 |
putLocal(result, (String) key, value);
|
|
955 |
}
|
|
956 |
}
|
627 |
957 |
}
|
628 |
958 |
|
|
959 |
/**
|
|
960 |
* Stores the specified parameters pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
|
|
961 |
* @param result
|
|
962 |
* @param key
|
|
963 |
* @param value
|
|
964 |
*/
|
|
965 |
public static void putLocal(TXMResult result, String key, Object value) {
|
629 |
966 |
|
|
967 |
if(Integer.class.isInstance(value)) {
|
|
968 |
putLocalInt(result, key, (Integer) value);
|
|
969 |
}
|
|
970 |
else if(Double.class.isInstance(value)) {
|
|
971 |
putLocalDouble(result, key, (Double) value);
|
|
972 |
}
|
|
973 |
else if(Float.class.isInstance(value)) {
|
|
974 |
putLocalFloat(result, key, (Float) value);
|
|
975 |
}
|
|
976 |
else if(Long.class.isInstance(value)) {
|
|
977 |
putLocalLong(result, key, (Long) value);
|
|
978 |
}
|
|
979 |
else if(String.class.isInstance(value)) {
|
|
980 |
putLocalString(result, key, (String) value);
|
|
981 |
}
|
|
982 |
else if(Boolean.class.isInstance(value)) {
|
|
983 |
putLocalBoolean(result, key, (Boolean) value);
|
|
984 |
}
|
630 |
985 |
|
631 |
|
|
|
986 |
//FIXME: Debug
|
|
987 |
System.err.println("TXMPreferences.putLocal(): error, can't find a put method that matches the value type: " + value.getClass() + " .");
|
|
988 |
}
|
|
989 |
|
632 |
990 |
//FIXME: this code is dedicated to dynamically retrieve the static field PREFERENCES_NODE of the runtime subclass and use it super class to avoid to pass it to all methods.
|
633 |
991 |
// eg. to use ProgressionPreferences.getBoolean("test") instead of TXMPreferences.getBoolean(ProgressionPreferences.PREFERENCES_NODE, "test")
|
634 |
992 |
// but it doesn"t work, need to continue the tests...
|
635 |
993 |
// /**
|
636 |
|
// *
|
|
994 |
// *
|
637 |
995 |
// * @author sjacquot
|
638 |
996 |
// *
|
639 |
997 |
// */
|
... | ... | |
646 |
1004 |
// return getClassContext()[2];
|
647 |
1005 |
// }
|
648 |
1006 |
// }
|
649 |
|
//
|
650 |
1007 |
//
|
|
1008 |
//
|
651 |
1009 |
// /**
|
652 |
1010 |
// * Gets the static field PREFERENCES_NODE of the runtime subclass.
|
653 |
|
// * Convenience method to avoid to pass it to all methods.
|
|
1011 |
// * Convenience method to avoid to pass it to all methods.
|
654 |
1012 |
// * @return
|
655 |
1013 |
// */
|
656 |
1014 |
// public static String getNodeQualifier() {
|
657 |
1015 |
// String runtimeSubClassNodeQualifier = null;
|
658 |
1016 |
// try {
|
659 |
|
//
|
|
1017 |
//
|
660 |
1018 |
// //System.err.println("TXMPreferences.getNodeQualifier() class name using thread stack = " + Thread.currentThread().getStackTrace()[1].getClassName());
|
661 |
1019 |
// System.err.println("TXMPreferences.getNodeQualifier() class name using encolsing class = " + new Object() { }.getClass().getEnclosingClass());
|
662 |
|
//
|
663 |
|
//
|
|
1020 |
//
|
|
1021 |
//
|
664 |
1022 |
// Class c = new CurrentClassGetter().getCurrentClass();
|
665 |
1023 |
// System.out.println("TXMPreferences.getNodeQualifier(): class = " + c);
|
666 |
1024 |
// Field f = c.getDeclaredField("PREFERENCES_NODE");
|
... | ... | |
685 |
1043 |
// // TODO Auto-generated catch block
|
686 |
1044 |
// e.printStackTrace();
|
687 |
1045 |
// }
|
688 |
|
//
|
|
1046 |
//
|
689 |
1047 |
// //System.out.println("TXMPreferences.getNodeQualifier() runtime class: " + );
|
690 |
|
//// // FIXME: new tests with bundles context class loading
|
|
1048 |
//// // FIXME: new tests with bundles context class loading
|
691 |
1049 |
//// HashSet<ClassLoader> loaders = new HashSet<ClassLoader>();
|
692 |
1050 |
//// BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
|
693 |
|
////
|
|
1051 |
////
|
694 |
1052 |
//// for (Bundle b : bundleContext.getBundles()) {
|
695 |
1053 |
//// BundleWiring bundleWiring = b.adapt(BundleWiring.class);
|
696 |
1054 |
//// loaders.add(bundleWiring.getClassLoader());
|
697 |
|
////
|
|
1055 |
////
|
698 |
1056 |
//// //FIXME: debug
|
699 |
1057 |
//// System.out.println("GSERunner.createGSERunner(): class loader added: " + bundleWiring.getClassLoader());
|
700 |
1058 |
//// }
|
701 |
|
////
|
702 |
|
//
|
|
1059 |
////
|
|
1060 |
//
|
703 |
1061 |
// return runtimeSubClassNodeQualifier;
|
704 |
1062 |
// }
|
705 |
|
//
|
706 |
|
//
|
|
1063 |
//
|
|
1064 |
//
|
707 |
1065 |
// public static String getString(String key) {
|
708 |
1066 |
//// Class c = new CurrentClassGetter().getCurrentClass();
|
709 |
1067 |
//// System.out.println("TXMPreferences.getString(): class = " + c);
|
710 |
1068 |
// return getString(getNodeQualifier(), key);
|
711 |
1069 |
// }
|
712 |
|
//
|
|
1070 |
//
|
713 |
1071 |
//// /**
|
714 |
|
//// *
|
|
1072 |
//// *
|
715 |
1073 |
//// * @param key
|
716 |
1074 |
//// * @return
|
717 |
1075 |
//// */
|
... | ... | |
720 |
1078 |
//// }
|
721 |
1079 |
////
|
722 |
1080 |
//end of fixme
|
723 |
|
|
724 |
|
}
|
|
1081 |
|
|
1082 |
}
|