debuggercdi/com.nokia.cdt.debug.common/src/com/nokia/cdt/debug/common/internal/source/lookup/SymbianSourceContainerType.java
author timkelly
Thu, 11 Mar 2010 13:45:01 -0600
changeset 1096 96e5879cd42d
permissions -rw-r--r--
Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1096
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     1
/*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     3
* All rights reserved.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     4
* This component and the accompanying materials are made available
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     6
* which accompanies this distribution, and is available
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     8
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
     9
* Initial Contributors:
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    11
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    12
* Contributors:
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    13
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    14
* Description: 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    15
*
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    16
*/
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    17
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    18
package com.nokia.cdt.debug.common.internal.source.lookup;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    19
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    20
import java.util.ArrayList;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    21
import java.util.Iterator;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    22
import java.util.List;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    23
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    24
import org.eclipse.cdt.debug.internal.core.sourcelookup.InternalSourceLookupMessages;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    25
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    26
import org.eclipse.core.runtime.CoreException;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    27
import org.eclipse.core.runtime.Path;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    28
import org.eclipse.debug.core.DebugPlugin;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    29
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    30
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    31
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    32
import org.w3c.dom.Document;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    33
import org.w3c.dom.Element;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    34
import org.w3c.dom.Node;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    35
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    36
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    37
public class SymbianSourceContainerType extends AbstractSourceContainerTypeDelegate {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    38
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    39
	private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    40
	private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    41
	private final static String ATTR_EPOCROOT = "epocroot"; //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    42
	private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    43
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    44
	public ISourceContainer createSourceContainer( String memento ) throws CoreException {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    45
		Node node = parseDocument( memento );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    46
		if ( node.getNodeType() == Node.ELEMENT_NODE ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    47
			Element element = (Element)node;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    48
			if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    49
				String epocroot = element.getAttribute( ATTR_EPOCROOT );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    50
				if ( epocroot == null ) 
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    51
					epocroot = ""; //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    52
				List entries = new ArrayList();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    53
				Node childNode = element.getFirstChild();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    54
				while( childNode != null ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    55
					if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    56
						Element child = (Element)childNode;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    57
						if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    58
							String childMemento = child.getAttribute( ATTR_MEMENTO );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    59
							if ( childMemento == null || childMemento.length() == 0 ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    60
								abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    61
							}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    62
							ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    63
							MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    64
							entries.add( entry );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    65
						}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    66
					}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    67
					childNode = childNode.getNextSibling();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    68
				}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    69
				SymbianSourceContainer container = new SymbianSourceContainer( new Path( epocroot ) );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    70
				Iterator it = entries.iterator();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    71
				while( it.hasNext() ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    72
					container.addMapEntry( (MapEntrySourceContainer)it.next() );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    73
				}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    74
				return container;
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    75
			}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    76
			abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.1" ), null ); //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    77
		}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    78
		abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.2" ), null ); //$NON-NLS-1$
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    79
		return null;		
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    80
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    81
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    82
	/* (non-Javadoc)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    83
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    84
	 */
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    85
	public String getMemento( ISourceContainer container ) throws CoreException {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    86
		Document document = newDocument();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    87
		Element element = document.createElement( ELEMENT_MAPPING );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    88
		element.setAttribute( ATTR_EPOCROOT, ((SymbianSourceContainer)container).getEpocRoot().toOSString() );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    89
		ISourceContainer[] entries = ((SymbianSourceContainer)container).getSourceContainers();
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    90
		for ( int i = 0; i < entries.length; ++i ) {
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    91
			Element child = document.createElement( ELEMENT_MAP_ENTRY );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    92
			child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    93
			element.appendChild( child );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    94
		}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    95
		document.appendChild( element );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    96
		return serializeDocument( document );
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    97
	}
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    98
96e5879cd42d Initial commit. Refactor out source mapping support into common plugin to be used with DE and EDC.
timkelly
parents:
diff changeset
    99
}