KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > core > sourcelookup > containers > DirectorySourceContainerType


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.core.sourcelookup.containers;
12
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.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages;
19 import org.w3c.dom.Document JavaDoc;
20 import org.w3c.dom.Element JavaDoc;
21 import org.w3c.dom.Node JavaDoc;
22
23 /**
24  * A folder in the local file system.
25  *
26  * @since 3.0
27  */

28 public class DirectorySourceContainerType extends AbstractSourceContainerTypeDelegate {
29
30     /* (non-Javadoc)
31      * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#createSourceContainer(java.lang.String)
32      */

33     public ISourceContainer createSourceContainer(String JavaDoc memento) throws CoreException {
34         Node JavaDoc node = parseDocument(memento);
35         if (node.getNodeType() == Node.ELEMENT_NODE) {
36             Element JavaDoc element = (Element JavaDoc)node;
37             if ("directory".equals(element.getNodeName())) { //$NON-NLS-1$
38
String JavaDoc string = element.getAttribute("path"); //$NON-NLS-1$
39
if (string == null || string.length() == 0) {
40                     abort(SourceLookupMessages.DirectorySourceContainerType_10, null);
41                 }
42                 String JavaDoc nest = element.getAttribute("nest"); //$NON-NLS-1$
43
boolean nested = "true".equals(nest); //$NON-NLS-1$
44
return new DirectorySourceContainer(new Path(string), nested);
45             }
46             abort(SourceLookupMessages.DirectorySourceContainerType_11, null);
47         }
48         abort(SourceLookupMessages.DirectorySourceContainerType_12, null);
49         return null;
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerType#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer)
54      */

55     public String JavaDoc getMemento(ISourceContainer container) throws CoreException {
56         DirectorySourceContainer folder = (DirectorySourceContainer) container;
57         Document JavaDoc document = newDocument();
58         Element JavaDoc element = document.createElement("directory"); //$NON-NLS-1$
59
element.setAttribute("path", folder.getDirectory().getAbsolutePath()); //$NON-NLS-1$
60
String JavaDoc nest = "false"; //$NON-NLS-1$
61
if (folder.isComposite()) {
62             nest = "true"; //$NON-NLS-1$
63
}
64         element.setAttribute("nest", nest); //$NON-NLS-1$
65
document.appendChild(element);
66         return serializeDocument(document);
67     }
68     
69 }
70
Popular Tags