Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
53f17e49 | 2 | * Copyright (c) 2010, 2016 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; | |
f5cc6ed1 | 19 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
6151d86c | 22 | |
a0a88f65 AM |
23 | /** |
24 | * Trace event for custom XML traces. | |
25 | * | |
26 | * @author Patrick Tassé | |
27 | */ | |
6151d86c PT |
28 | public class CustomXmlEvent extends CustomEvent { |
29 | ||
a0a88f65 AM |
30 | /** |
31 | * Constructor defining only the trace definition | |
32 | * | |
33 | * @param definition | |
34 | * Trace definition | |
35 | */ | |
6151d86c PT |
36 | public CustomXmlEvent(CustomXmlTraceDefinition definition) { |
37 | super(definition); | |
6151d86c PT |
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 | |
f5cc6ed1 | 81 | * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead. |
a0a88f65 | 82 | */ |
f5cc6ed1 | 83 | @Deprecated |
6151d86c | 84 | public void parseInput(String value, String name, int inputAction, String inputFormat) { |
f5cc6ed1 PT |
85 | } |
86 | ||
87 | /** | |
88 | * Parse an entry. | |
89 | * | |
90 | * @param value Value | |
91 | * @param inputTag Input tag | |
92 | * @param inputName Input name | |
93 | * @param inputAction Input action | |
94 | * @param inputFormat Input format | |
95 | * @since 2.1 | |
96 | */ | |
97 | public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) { | |
6151d86c PT |
98 | if (value.length() == 0) { |
99 | return; | |
100 | } | |
f5cc6ed1 | 101 | Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag); |
6151d86c | 102 | if (inputAction == CustomTraceDefinition.ACTION_SET) { |
f5cc6ed1 PT |
103 | fData.put(key, value); |
104 | if (key.equals(Tag.TIMESTAMP)) { | |
105 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); | |
6151d86c PT |
106 | } |
107 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { | |
f5cc6ed1 | 108 | String s = fData.get(key); |
6151d86c | 109 | if (s != null) { |
f5cc6ed1 | 110 | fData.put(key, s + value); |
6151d86c | 111 | } else { |
f5cc6ed1 | 112 | fData.put(key, value); |
6151d86c | 113 | } |
f5cc6ed1 PT |
114 | if (key.equals(Tag.TIMESTAMP)) { |
115 | String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); | |
6151d86c | 116 | if (timeStampInputFormat != null) { |
f5cc6ed1 | 117 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat); |
6151d86c | 118 | } else { |
f5cc6ed1 | 119 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); |
6151d86c PT |
120 | } |
121 | } | |
122 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
f5cc6ed1 | 123 | String s = fData.get(key); |
6151d86c | 124 | if (s != null) { |
f5cc6ed1 | 125 | fData.put(key, s + " | " + value); //$NON-NLS-1$ |
6151d86c | 126 | } else { |
f5cc6ed1 | 127 | fData.put(key, value); |
6151d86c | 128 | } |
f5cc6ed1 PT |
129 | if (key.equals(Tag.TIMESTAMP)) { |
130 | String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); | |
6151d86c | 131 | if (timeStampInputFormat != null) { |
f5cc6ed1 | 132 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ |
6151d86c | 133 | } else { |
f5cc6ed1 | 134 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); |
6151d86c PT |
135 | } |
136 | } | |
137 | } | |
138 | } | |
139 | ||
140 | } |