KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > JavaProjectSourceContainerTypeDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.launching;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IWorkspace;
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
18 import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
19 import org.eclipse.jdt.core.IJavaProject;
20 import org.eclipse.jdt.core.JavaCore;
21 import org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer;
22 import org.w3c.dom.Document JavaDoc;
23 import org.w3c.dom.Element JavaDoc;
24 import org.w3c.dom.Node JavaDoc;
25
26 /**
27  * Java project source container type.
28  */

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

34     public ISourceContainer createSourceContainer(String JavaDoc memento) throws CoreException {
35         Node JavaDoc node = parseDocument(memento);
36         if (node.getNodeType() == Node.ELEMENT_NODE) {
37             Element JavaDoc element = (Element JavaDoc)node;
38             if ("javaProject".equals(element.getNodeName())) { //$NON-NLS-1$
39
String JavaDoc string = element.getAttribute("name"); //$NON-NLS-1$
40
if (string == null || string.length() == 0) {
41                     abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_5, null);
42                 }
43                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
44                 IProject project = workspace.getRoot().getProject(string);
45                 IJavaProject javaProject = JavaCore.create(project);
46                 return new JavaProjectSourceContainer(javaProject);
47             }
48             abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_6, null);
49         }
50         abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_7, null);
51         return null;
52     }
53     /* (non-Javadoc)
54      * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer)
55      */

56     public String JavaDoc getMemento(ISourceContainer container) throws CoreException {
57         JavaProjectSourceContainer project = (JavaProjectSourceContainer) container;
58         Document JavaDoc document = newDocument();
59         Element JavaDoc element = document.createElement("javaProject"); //$NON-NLS-1$
60
element.setAttribute("name", project.getName()); //$NON-NLS-1$
61
document.appendChild(element);
62         return serializeDocument(document);
63     }
64 }
65
Popular Tags