Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 182665
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/XMLMemento.java (-2 / +46 lines)
Lines 162-196 Link Here
162
     * Method declared in IMemento.
162
     * Method declared in IMemento.
163
     */
163
     */
164
    public IMemento createChild(String type) {
164
    public IMemento createChild(String type) {
165
        Element child = factory.createElement(type);
165
    	synchronized (element) {
166
    	Element child = factory.createElement(type);
166
        element.appendChild(child);
167
        element.appendChild(child);
167
        return new XMLMemento(factory, child);
168
        return new XMLMemento(factory, child);
169
    	}
168
    }
170
    }
169
171
170
    /* (non-Javadoc)
172
    /* (non-Javadoc)
171
     * Method declared in IMemento.
173
     * Method declared in IMemento.
172
     */
174
     */
173
    public IMemento createChild(String type, String id) {
175
    public IMemento createChild(String type, String id) {
176
    	synchronized (element) {
174
        Element child = factory.createElement(type);
177
        Element child = factory.createElement(type);
175
        child.setAttribute(TAG_ID, id == null ? "" : id); //$NON-NLS-1$
178
        child.setAttribute(TAG_ID, id == null ? "" : id); //$NON-NLS-1$
176
        element.appendChild(child);
179
        element.appendChild(child);
177
        return new XMLMemento(factory, child);
180
        return new XMLMemento(factory, child);
181
    	}
178
    }
182
    }
179
183
180
    /* (non-Javadoc)
184
    /* (non-Javadoc)
181
     * Method declared in IMemento.
185
     * Method declared in IMemento.
182
     */
186
     */
183
    public IMemento copyChild(IMemento child) {
187
    public IMemento copyChild(IMemento child) {
188
    	synchronized (element) {
184
        Element childElement = ((XMLMemento) child).element;
189
        Element childElement = ((XMLMemento) child).element;
185
        Element newElement = (Element) factory.importNode(childElement, true);
190
        Element newElement = (Element) factory.importNode(childElement, true);
186
        element.appendChild(newElement);
191
        element.appendChild(newElement);
187
        return new XMLMemento(factory, newElement);
192
        return new XMLMemento(factory, newElement);
193
    	}
188
    }
194
    }
189
195
190
    /* (non-Javadoc)
196
    /* (non-Javadoc)
191
     * Method declared in IMemento.
197
     * Method declared in IMemento.
192
     */
198
     */
193
    public IMemento getChild(String type) {
199
    public IMemento getChild(String type) {
200
    	synchronized (element) {
194
201
195
        // Get the nodes.
202
        // Get the nodes.
196
        NodeList nodes = element.getChildNodes();
203
        NodeList nodes = element.getChildNodes();
Lines 212-223 Link Here
212
219
213
        // A child was not found.
220
        // A child was not found.
214
        return null;
221
        return null;
222
    	}
215
    }
223
    }
216
224
217
    /* (non-Javadoc)
225
    /* (non-Javadoc)
218
     * Method declared in IMemento.
226
     * Method declared in IMemento.
219
     */
227
     */
220
    public IMemento[] getChildren(String type) {
228
    public IMemento[] getChildren(String type) {
229
    	synchronized (element) {
221
230
222
        // Get the nodes.
231
        // Get the nodes.
223
        NodeList nodes = element.getChildNodes();
232
        NodeList nodes = element.getChildNodes();
Lines 245-256 Link Here
245
            results[x] = new XMLMemento(factory, (Element) list.get(x));
254
            results[x] = new XMLMemento(factory, (Element) list.get(x));
246
        }
255
        }
247
        return results;
256
        return results;
257
    	}
248
    }
258
    }
249
259
250
    /* (non-Javadoc)
260
    /* (non-Javadoc)
251
     * Method declared in IMemento.
261
     * Method declared in IMemento.
252
     */
262
     */
253
    public Float getFloat(String key) {
263
    public Float getFloat(String key) {
264
    	synchronized (element) {
254
        Attr attr = element.getAttributeNode(key);
265
        Attr attr = element.getAttributeNode(key);
255
        if (attr == null) {
266
        if (attr == null) {
256
			return null;
267
			return null;
Lines 263-288 Link Here
263
                    + key + " value: " + strValue, e); //$NON-NLS-1$
274
                    + key + " value: " + strValue, e); //$NON-NLS-1$
264
            return null;
275
            return null;
265
        }
276
        }
277
    	}
266
    }
278
    }
267
279
268
	/**
280
	/**
269
	 * @since 3.4
281
	 * @since 3.4
270
	 */
282
	 */
271
	public String getType() {
283
	public String getType() {
284
    	synchronized (element) {
272
		return element.getNodeName();
285
		return element.getNodeName();
286
    	}
273
	}
287
	}
274
288
275
    /* (non-Javadoc)
289
    /* (non-Javadoc)
276
     * Method declared in IMemento.
290
     * Method declared in IMemento.
277
     */
291
     */
278
    public String getID() {
292
    public String getID() {
293
    	synchronized (element) {
279
        return element.getAttribute(TAG_ID);
294
        return element.getAttribute(TAG_ID);
295
    	}
280
    }
296
    }
281
297
282
    /* (non-Javadoc)
298
    /* (non-Javadoc)
283
     * Method declared in IMemento.
299
     * Method declared in IMemento.
284
     */
300
     */
285
    public Integer getInteger(String key) {
301
    public Integer getInteger(String key) {
302
    	synchronized (element) {
286
        Attr attr = element.getAttributeNode(key);
303
        Attr attr = element.getAttributeNode(key);
287
        if (attr == null) {
304
        if (attr == null) {
288
			return null;
305
			return null;
Lines 296-340 Link Here
296
                            + " value: " + strValue, e); //$NON-NLS-1$
313
                            + " value: " + strValue, e); //$NON-NLS-1$
297
            return null;
314
            return null;
298
        }
315
        }
299
    }
316
    	}
317
   	}
300
318
301
    /* (non-Javadoc)
319
    /* (non-Javadoc)
302
     * Method declared in IMemento.
320
     * Method declared in IMemento.
303
     */
321
     */
304
    public String getString(String key) {
322
    public String getString(String key) {
323
    	synchronized (element) {
305
        Attr attr = element.getAttributeNode(key);
324
        Attr attr = element.getAttributeNode(key);
306
        if (attr == null) {
325
        if (attr == null) {
307
			return null;
326
			return null;
308
		}
327
		}
309
        return attr.getValue();
328
        return attr.getValue();
329
    	}
310
    }
330
    }
311
331
312
	/**
332
	/**
313
	 * @since 3.4
333
	 * @since 3.4
314
	 */
334
	 */
315
	public Boolean getBoolean(String key) {
335
	public Boolean getBoolean(String key) {
336
    	synchronized (element) {
316
        Attr attr = element.getAttributeNode(key);
337
        Attr attr = element.getAttributeNode(key);
317
        if (attr == null) {
338
        if (attr == null) {
318
			return null;
339
			return null;
319
		}
340
		}
320
        return Boolean.valueOf(attr.getValue());
341
        return Boolean.valueOf(attr.getValue());
342
    	}
321
	}
343
	}
322
344
323
    /* (non-Javadoc)
345
    /* (non-Javadoc)
324
     * Method declared in IMemento.
346
     * Method declared in IMemento.
325
     */
347
     */
326
    public String getTextData() {
348
    public String getTextData() {
349
    	synchronized (element) {
327
        Text textNode = getTextNode();
350
        Text textNode = getTextNode();
328
        if (textNode != null) {
351
        if (textNode != null) {
329
            return textNode.getData();
352
            return textNode.getData();
330
        }
353
        }
331
        return null;
354
        return null;
355
    	}
332
    }
356
    }
333
357
334
	/**
358
	/**
335
	 * @since 3.4
359
	 * @since 3.4
336
	 */
360
	 */
337
	public String[] getAttributeKeys() {
361
	public String[] getAttributeKeys() {
362
    	synchronized (element) {
338
		NamedNodeMap map = element.getAttributes();
363
		NamedNodeMap map = element.getAttributes();
339
		int size = map.getLength();
364
		int size = map.getLength();
340
		String[] attributes = new String[size];
365
		String[] attributes = new String[size];
Lines 343-348 Link Here
343
			attributes[i] = node.getNodeName();
368
			attributes[i] = node.getNodeName();
344
		}
369
		}
345
		return attributes;
370
		return attributes;
371
    	}
346
	}
372
	}
347
373
348
    /**
374
    /**
Lines 353-358 Link Here
353
     * the memento has no Text node.
379
     * the memento has no Text node.
354
     */
380
     */
355
    private Text getTextNode() {
381
    private Text getTextNode() {
382
    	synchronized (element) {
356
        // Get the nodes.
383
        // Get the nodes.
357
        NodeList nodes = element.getChildNodes();
384
        NodeList nodes = element.getChildNodes();
358
        int size = nodes.getLength();
385
        int size = nodes.getLength();
Lines 367-372 Link Here
367
        }
394
        }
368
        // a Text node was not found
395
        // a Text node was not found
369
        return null;
396
        return null;
397
    	}
370
    }
398
    }
371
399
372
    /**
400
    /**
Lines 374-379 Link Here
374
     * @param copyText true if the first text node should be copied
402
     * @param copyText true if the first text node should be copied
375
     */
403
     */
376
    private void putElement(Element element, boolean copyText) {
404
    private void putElement(Element element, boolean copyText) {
405
    	synchronized (element) {
377
        NamedNodeMap nodeMap = element.getAttributes();
406
        NamedNodeMap nodeMap = element.getAttributes();
378
        int size = nodeMap.getLength();
407
        int size = nodeMap.getLength();
379
        for (int i = 0; i < size; i++) {
408
        for (int i = 0; i < size; i++) {
Lines 396-447 Link Here
396
                needToCopyText = false;
425
                needToCopyText = false;
397
            }
426
            }
398
        }
427
        }
428
    	}
399
    }
429
    }
400
430
401
    /* (non-Javadoc)
431
    /* (non-Javadoc)
402
     * Method declared in IMemento.
432
     * Method declared in IMemento.
403
     */
433
     */
404
    public void putFloat(String key, float f) {
434
    public void putFloat(String key, float f) {
435
    	synchronized (element) {
405
        element.setAttribute(key, String.valueOf(f));
436
        element.setAttribute(key, String.valueOf(f));
437
    	}
406
    }
438
    }
407
439
408
    /* (non-Javadoc)
440
    /* (non-Javadoc)
409
     * Method declared in IMemento.
441
     * Method declared in IMemento.
410
     */
442
     */
411
    public void putInteger(String key, int n) {
443
    public void putInteger(String key, int n) {
444
    	synchronized (element) {
412
        element.setAttribute(key, String.valueOf(n));
445
        element.setAttribute(key, String.valueOf(n));
446
    	}
413
    }
447
    }
414
448
415
    /* (non-Javadoc)
449
    /* (non-Javadoc)
416
     * Method declared in IMemento.
450
     * Method declared in IMemento.
417
     */
451
     */
418
    public void putMemento(IMemento memento) {
452
    public void putMemento(IMemento memento) {
453
    	synchronized (element) {
419
    	// Do not copy the element's top level text node (this would overwrite the existing text).
454
    	// Do not copy the element's top level text node (this would overwrite the existing text).
420
    	// Text nodes of children are copied.
455
    	// Text nodes of children are copied.
421
        putElement(((XMLMemento) memento).element, false);
456
        putElement(((XMLMemento) memento).element, false);
457
    	}
422
    }
458
    }
423
459
424
    /* (non-Javadoc)
460
    /* (non-Javadoc)
425
     * Method declared in IMemento.
461
     * Method declared in IMemento.
426
     */
462
     */
427
    public void putString(String key, String value) {
463
    public void putString(String key, String value) {
464
    	synchronized (element) {
428
        if (value == null) {
465
        if (value == null) {
429
			return;
466
			return;
430
		}
467
		}
431
        element.setAttribute(key, value);
468
        element.setAttribute(key, value);
469
    	}
432
    }
470
    }
433
471
434
	/**
472
	/**
435
	 * @since 3.4
473
	 * @since 3.4
436
	 */
474
	 */
437
	public void putBoolean(String key, boolean value) {
475
	public void putBoolean(String key, boolean value) {
476
    	synchronized (element) {
438
		element.setAttribute(key, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
477
		element.setAttribute(key, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
478
    	}
439
	}
479
	}
440
480
441
    /* (non-Javadoc)
481
    /* (non-Javadoc)
442
     * Method declared in IMemento.
482
     * Method declared in IMemento.
443
     */
483
     */
444
    public void putTextData(String data) {
484
    public void putTextData(String data) {
485
    	synchronized (element) {
445
        Text textNode = getTextNode();
486
        Text textNode = getTextNode();
446
        if (textNode == null) {
487
        if (textNode == null) {
447
            textNode = factory.createTextNode(data);
488
            textNode = factory.createTextNode(data);
Lines 450-455 Link Here
450
        } else {
491
        } else {
451
            textNode.setData(data);
492
            textNode.setData(data);
452
        }
493
        }
494
    	}
453
    }
495
    }
454
496
455
    /**
497
    /**
Lines 460-471 Link Here
460
     * @throws IOException if there is a problem serializing the document to the stream.
502
     * @throws IOException if there is a problem serializing the document to the stream.
461
     */
503
     */
462
    public void save(Writer writer) throws IOException {
504
    public void save(Writer writer) throws IOException {
505
    	synchronized (element) {
463
    	DOMWriter out = new DOMWriter(writer);
506
    	DOMWriter out = new DOMWriter(writer);
464
        try {
507
        try {
465
        	out.print(element);
508
        	out.print(element);
466
    	} finally {
509
    	} finally {
467
    		out.close();
510
    		out.close();
468
    	}
511
    	}
512
    	}
469
	}
513
	}
470
514
471
	/**
515
	/**

Return to bug 182665