Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2010, 2014 Ericsson |
6151d86c PT |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.parsers.custom; |
6151d86c | 14 | |
ca5b04ad | 15 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
16 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
17 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
18 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
19 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; | |
20 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
6151d86c | 21 | |
a0a88f65 AM |
22 | /** |
23 | * Trace event for custom XML traces. | |
24 | * | |
25 | * @author Patrick Tassé | |
26 | */ | |
6151d86c PT |
27 | public class CustomXmlEvent extends CustomEvent { |
28 | ||
a0a88f65 AM |
29 | /** |
30 | * Constructor defining only the trace definition | |
31 | * | |
32 | * @param definition | |
33 | * Trace definition | |
34 | */ | |
6151d86c PT |
35 | public CustomXmlEvent(CustomXmlTraceDefinition definition) { |
36 | super(definition); | |
37 | setType(new CustomXmlEventType(definition)); | |
38 | } | |
39 | ||
a0a88f65 AM |
40 | /** |
41 | * Build a custom trace event from an existing TmfEvent. | |
42 | * | |
43 | * @param definition | |
44 | * Trace definition | |
45 | * @param other | |
46 | * Other TmfEvent to copy | |
47 | */ | |
ca5b04ad | 48 | public CustomXmlEvent(CustomXmlTraceDefinition definition, @NonNull TmfEvent other) { |
6151d86c PT |
49 | super(definition, other); |
50 | } | |
51 | ||
a0a88f65 AM |
52 | /** |
53 | * Full constructor | |
54 | * | |
55 | * @param definition | |
56 | * Trace definition | |
57 | * @param parentTrace | |
58 | * Parent trace object | |
59 | * @param timestamp | |
60 | * Timestamp of the event | |
a0a88f65 AM |
61 | * @param type |
62 | * Event type | |
a0a88f65 | 63 | */ |
e1de2fd4 AM |
64 | public CustomXmlEvent(CustomXmlTraceDefinition definition, |
65 | ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) { | |
66 | super(definition, parentTrace, timestamp, type); | |
6151d86c PT |
67 | } |
68 | ||
69 | @Override | |
70 | public void setContent(ITmfEventField content) { | |
71 | super.setContent(content); | |
72 | } | |
73 | ||
a0a88f65 AM |
74 | /** |
75 | * Parse an entry. | |
76 | * | |
77 | * @param value Value | |
78 | * @param name Name | |
79 | * @param inputAction Input action | |
80 | * @param inputFormat Input format | |
81 | */ | |
6151d86c PT |
82 | public void parseInput(String value, String name, int inputAction, String inputFormat) { |
83 | if (value.length() == 0) { | |
84 | return; | |
85 | } | |
86 | if (inputAction == CustomTraceDefinition.ACTION_SET) { | |
87 | fData.put(name, value); | |
88 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
89 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); | |
90 | } | |
91 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { | |
92 | String s = fData.get(name); | |
93 | if (s != null) { | |
94 | fData.put(name, s + value); | |
95 | } else { | |
96 | fData.put(name, value); | |
97 | } | |
98 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
99 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
100 | if (timeStampInputFormat != null) { | |
101 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat); | |
102 | } else { | |
103 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); | |
104 | } | |
105 | } | |
106 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
107 | String s = fData.get(name); | |
108 | if (s != null) { | |
109 | fData.put(name, s + " | " + value); //$NON-NLS-1$ | |
110 | } else { | |
111 | fData.put(name, value); | |
112 | } | |
113 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
114 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
115 | if (timeStampInputFormat != null) { | |
116 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ | |
117 | } else { | |
118 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); | |
119 | } | |
120 | } | |
121 | } | |
122 | } | |
123 | ||
124 | } |