blob: 7d620f5bd8643f55efa165d6616a73411e56fb9f (
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
|
/*******************************************************************************
* Copyright (c) 2008 Red Hat, Inc.
* 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:
* Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata;
import java.util.ArrayList;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor;
import org.xml.sax.Attributes;
/**
* XML handler class for dependent images (<image> tags under <dependent>)
*/
public class DependentProcessor extends XMLProcessor {
//XML tags parsed by this processor
private static final String IMAGE_TAG = "image"; //$NON-NLS-1$
private static final String SYMBOLS_TAG = "symbols"; //$NON-NLS-1$
private static final String DEPENDENT_TAG = "dependent"; //$NON-NLS-1$
//attribute tags
private static final String ATTR_IMAGENAME = "name"; //$NON-NLS-1$
private static final String ATTR_COUNT = "count"; //$NON-NLS-1$
/**
* the current image being constructed
*/
private OpModelImage image;
/**
* a list of all the dependent images
*/
private ArrayList<OpModelImage> imageList;
/**
* processor used for symbols of an image
*/
private SymbolsProcessor _symbolsProcessor = new SymbolsProcessor();
@Override
public void reset(Object callData) {
image = new OpModelImage();
imageList = new ArrayList<OpModelImage>();
}
/**
* @see org.eclipse.linuxtools.internal.oprofile.core.XMLProcessor#startElement(String)
*/
@Override
public void startElement(String name, Attributes attrs, Object callData) {
if (name.equals(IMAGE_TAG)) {
image.setName(valid_string(attrs.getValue(ATTR_IMAGENAME)));
image.setCount(Integer.parseInt(attrs.getValue(ATTR_COUNT)));
} else if (name.equals(SYMBOLS_TAG)) {
OprofileSAXHandler.getInstance(callData).push(_symbolsProcessor);
}
}
/**
* @see org.eclipse.linuxtools.internal.oprofile.core.XMLProcessor#endElement(String)
*/
@Override
public void endElement(String name, Object callData) {
if (name.equals(IMAGE_TAG)) {
imageList.add(image);
image = new OpModelImage();
} else if (name.equals(SYMBOLS_TAG)) {
image.setSymbols(_symbolsProcessor.getSymbols());
} else if (name.equals(DEPENDENT_TAG)) {
OprofileSAXHandler.getInstance(callData).pop(DEPENDENT_TAG);
}
}
public OpModelImage[] getImages() {
OpModelImage[] images = new OpModelImage[imageList.size()];
imageList.toArray(images);
return images;
}
}
|