KickJava   Java API By Example, From Geeks To Geeks.

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


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.runtime.CoreException;
14 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
15 import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
16 import org.eclipse.jdt.core.IJavaElement;
17 import org.eclipse.jdt.core.IPackageFragmentRoot;
18 import org.eclipse.jdt.core.JavaCore;
19 import org.eclipse.jdt.launching.sourcelookup.containers.PackageFragmentRootSourceContainer;
20 import org.w3c.dom.Document JavaDoc;
21 import org.w3c.dom.Element JavaDoc;
22 import org.w3c.dom.Node JavaDoc;
23
24 /**
25  * Package fragment root source container type.
26  *
27  * @since 3.0
28  */

29 public class PackageFragmentRootSourceContainerTypeDelegate 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 element = (Element)node;
38             if ("packageFragmentRoot".equals(element.getNodeName())) { //$NON-NLS-1$
39
String JavaDoc string = element.getAttribute("handle"); //$NON-NLS-1$
40
if (string == null || string.length() == 0) {
41                     abort(LaunchingMessages.PackageFragmentRootSourceContainerTypeDelegate_6, null);
42                 }
43                 IJavaElement root = JavaCore.create(string);
44                 if (root != null && root instanceof IPackageFragmentRoot) {
45                     return new PackageFragmentRootSourceContainer((IPackageFragmentRoot)root);
46                 }
47                 abort(LaunchingMessages.PackageFragmentRootSourceContainerTypeDelegate_7, null);
48             } else {
49                 abort(LaunchingMessages.PackageFragmentRootSourceContainerTypeDelegate_8, null);
50             }
51         }
52         abort(LaunchingMessages.JavaProjectSourceContainerTypeDelegate_7, null);
53         return null;
54     }
55     /* (non-Javadoc)
56      * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.internal.core.sourcelookup.ISourceContainer)
57      */

58     public String JavaDoc getMemento(ISourceContainer container) throws CoreException {
59         PackageFragmentRootSourceContainer root = (PackageFragmentRootSourceContainer) container;
60         Document JavaDoc document = newDocument();
61         Element element = document.createElement("packageFragmentRoot"); //$NON-NLS-1$
62
element.setAttribute("handle", root.getPackageFragmentRoot().getHandleIdentifier()); //$NON-NLS-1$
63
document.appendChild(element);
64         return serializeDocument(document);
65     }
66 }
67
Popular Tags