Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 743624912441855fb68943dbfafc1bfe2e03a66e (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
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2004 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:
 *    Keith Seitz <keiths@redhat.com> - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.linuxtools.internal.oprofile.core.opxml.sessions;

import java.util.ArrayList;

import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelEvent;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSession;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor;
import org.xml.sax.Attributes;


/**
 * A processor for sessions.
 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.OpxmlRunner
 */
public class SessionsProcessor extends XMLProcessor {
	public static class SessionInfo {
		/**
		 *  A list of SessionEvents
		 */
		public ArrayList<OpModelEvent> list;
		
		public SessionInfo(ArrayList<OpModelEvent> list){
			this.list = list;
		}
	}
	
	// XML tags recognized by this processor
	public static final String SESSION_TAG = "session"; //$NON-NLS-1$
	private static final String SESSION_NAME_ATTR = "name"; //$NON-NLS-1$
	public static final String SAMPLE_COUNT_TAG = "count"; //$NON-NLS-1$
	public static final String EVENT_TAG = "event"; //$NON-NLS-1$
	private static final String EVENT_NAME_ATTR = "name"; //$NON-NLS-1$
	
	/**
	 *  The current session being constructed
	 */
	private OpModelSession currentSession;
	
	/**
	 *  The current event being constructed
	 */
	private OpModelEvent currentEvent;
	
	/**
	 *  A list of all sessions
	 */
	private ArrayList<OpModelSession> sessionList;
	
	/**
	 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor#startElement(java.lang.String, org.xml.sax.Attributes, java.lang.Object)
	 */
	@Override
	public void startElement(String name, Attributes attrs, Object callData) {
		if (name.equals(SESSION_TAG)) {
			String sessionName = valid_string(attrs.getValue(SESSION_NAME_ATTR));
			currentSession = new OpModelSession(currentEvent, sessionName);
		} else if (name.equals(EVENT_TAG)) {
			String eventName = attrs.getValue(EVENT_NAME_ATTR);
			currentEvent = new OpModelEvent(eventName);
			sessionList = new ArrayList<>();
		} else {
			super.startElement(name, attrs, callData);
		}
	}
	
	/**
	 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor#endElement(java.lang.String, java.lang.Object)
	 */
	@Override
	public void endElement(String name, Object callData) {
		if (name.equals(SESSION_TAG)) {
			// Got end of session -- save in session list
			sessionList.add(currentSession);
			currentSession = null;
		} else if (name.equals(EVENT_TAG)) {
			// Got end of event -- save session list into current OpModelEvent and
			// save current event into call data
			OpModelSession[] s = new OpModelSession[sessionList.size()];
			sessionList.toArray(s);
			currentEvent.setSessions(s);
			SessionInfo info = (SessionInfo) callData;
			info.list.add(currentEvent);
			currentEvent = null;
			sessionList = null;
		} else {
			super.endElement(name, callData);
		}
	}
}

Back to the top