1 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 ; 21 import org.w3c.dom.Element ; 22 import org.w3c.dom.Node ; 23 24 29 public class PackageFragmentRootSourceContainerTypeDelegate extends AbstractSourceContainerTypeDelegate { 30 31 34 public ISourceContainer createSourceContainer(String memento) throws CoreException { 35 Node node = parseDocument(memento); 36 if (node.getNodeType() == Node.ELEMENT_NODE) { 37 Element element = (Element)node; 38 if ("packageFragmentRoot".equals(element.getNodeName())) { String string = element.getAttribute("handle"); 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 58 public String getMemento(ISourceContainer container) throws CoreException { 59 PackageFragmentRootSourceContainer root = (PackageFragmentRootSourceContainer) container; 60 Document document = newDocument(); 61 Element element = document.createElement("packageFragmentRoot"); element.setAttribute("handle", root.getPackageFragmentRoot().getHandleIdentifier()); document.appendChild(element); 64 return serializeDocument(document); 65 } 66 } 67 | Popular Tags |