1
/*******************************************************************************
2
* Copyright (c) 2004, 2006 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.debug.internal.core.sourcelookup;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.Path;
15
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
16
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
17
import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
18
import org.w3c.dom.Document;
19
import org.w3c.dom.Element;
20
import org.w3c.dom.Node;
23
* See <code>CDirectorySourceContainer</code>.
25
public class CDirectorySourceContainerType extends AbstractSourceContainerTypeDelegate {
28
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String)
30
public ISourceContainer createSourceContainer(String memento) throws CoreException {
31
Node node = parseDocument(memento);
32
if (node.getNodeType() == Node.ELEMENT_NODE) {
33
Element element = (Element) node;
34
if ("directory".equals(element.getNodeName())) { //$NON-NLS-1$
35
String string = element.getAttribute("path"); //$NON-NLS-1$
36
if (string == null || string.length() == 0) {
37
abort(InternalSourceLookupMessages.CDirectorySourceContainerType_0, null);
39
String nest = element.getAttribute("nest"); //$NON-NLS-1$
40
boolean nested = "true".equals(nest); //$NON-NLS-1$
41
return new DirectorySourceContainer(new Path(string), nested);
43
abort(InternalSourceLookupMessages.CDirectorySourceContainerType_1, null);
45
abort(InternalSourceLookupMessages.CDirectorySourceContainerType_2, null);
50
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer)
52
public String getMemento(ISourceContainer container) throws CoreException {
53
DirectorySourceContainer folder = (DirectorySourceContainer) container;
54
Document document = newDocument();
55
Element element = document.createElement("directory"); //$NON-NLS-1$
56
element.setAttribute("path", folder.getDirectory().getAbsolutePath()); //$NON-NLS-1$
57
String nest = "false"; //$NON-NLS-1$
58
if (folder.isComposite()) {
59
nest = "true"; //$NON-NLS-1$
61
element.setAttribute("nest", nest); //$NON-NLS-1$
62
document.appendChild(element);
63
return serializeDocument(document);