blob: f25762f07d764a6118bc3cb11c671b8cf416700f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*******************************************************************************
* Copyright (c) 2004, 2005 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* The mapping container type.
*/
public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate {
private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$
private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$
private final static String ATTR_NAME = "name"; //$NON-NLS-1$
private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
*/
public ISourceContainer createSourceContainer( String memento ) throws CoreException {
Node node = parseDocument( memento );
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
Element element = (Element)node;
if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) {
String name = element.getAttribute( ATTR_NAME );
if ( name == null )
name = ""; //$NON-NLS-1$
List entries = new ArrayList();
Node childNode = element.getFirstChild();
while( childNode != null ) {
if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
Element child = (Element)childNode;
if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) {
String childMemento = child.getAttribute( ATTR_MEMENTO );
if ( childMemento == null || childMemento.length() == 0 ) {
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$
}
ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID );
MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento );
entries.add( entry );
}
}
childNode = childNode.getNextSibling();
}
MappingSourceContainer container = new MappingSourceContainer( name );
Iterator it = entries.iterator();
while( it.hasNext() ) {
container.addMapEntry( (MapEntrySourceContainer)it.next() );
}
return container;
}
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.1" ), null ); //$NON-NLS-1$
}
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.2" ), null ); //$NON-NLS-1$
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
*/
public String getMemento( ISourceContainer container ) throws CoreException {
Document document = newDocument();
Element element = document.createElement( ELEMENT_MAPPING );
element.setAttribute( ATTR_NAME, container.getName() );
ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers();
for ( int i = 0; i < entries.length; ++i ) {
Element child = document.createElement( ELEMENT_MAP_ENTRY );
child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) );
element.appendChild( child );
}
document.appendChild( element );
return serializeDocument( document );
}
}
|