tmf: bug 494698 Add per-event fields to custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
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
13 package org.eclipse.tracecompass.tmf.core.parsers.custom;
14
15 import org.eclipse.jdt.annotation.NonNull;
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.parsers.custom.CustomTraceDefinition.Tag;
20 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22
23 /**
24 * Trace event for custom XML traces.
25 *
26 * @author Patrick Tassé
27 */
28 public class CustomXmlEvent extends CustomEvent {
29
30 private String fLastExtraFieldName = null;
31
32 /**
33 * Constructor defining only the trace definition
34 *
35 * @param definition
36 * Trace definition
37 */
38 public CustomXmlEvent(CustomXmlTraceDefinition definition) {
39 super(definition);
40 }
41
42 /**
43 * Build a custom trace event from an existing TmfEvent.
44 *
45 * @param definition
46 * Trace definition
47 * @param other
48 * Other TmfEvent to copy
49 */
50 public CustomXmlEvent(CustomXmlTraceDefinition definition, @NonNull TmfEvent other) {
51 super(definition, other);
52 }
53
54 /**
55 * Full constructor
56 *
57 * @param definition
58 * Trace definition
59 * @param parentTrace
60 * Parent trace object
61 * @param timestamp
62 * Timestamp of the event
63 * @param type
64 * Event type
65 */
66 public CustomXmlEvent(CustomXmlTraceDefinition definition,
67 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
68 super(definition, parentTrace, timestamp, type);
69 }
70
71 @Override
72 public void setContent(ITmfEventField content) {
73 super.setContent(content);
74 }
75
76 /**
77 * Parse an entry.
78 *
79 * @param value Value
80 * @param name Name
81 * @param inputAction Input action
82 * @param inputFormat Input format
83 * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead.
84 */
85 @Deprecated
86 public void parseInput(String value, String name, int inputAction, String inputFormat) {
87 }
88
89 /**
90 * Parse an entry.
91 *
92 * @param value Value
93 * @param inputTag Input tag
94 * @param inputName Input name
95 * @param inputAction Input action
96 * @param inputFormat Input format
97 * @since 2.1
98 */
99 public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) {
100 if (value.length() == 0) {
101 return;
102 }
103 Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag);
104 if (key.equals(Tag.EXTRA_FIELD_NAME)) {
105 // If tag extra field name, save the extra field name for
106 // the next extra field value and add the field to the map
107 fLastExtraFieldName = value;
108 if (!fData.containsKey(value)) {
109 fData.put(value, null);
110 }
111 return;
112 } else if (key.equals(Tag.EXTRA_FIELD_VALUE)) {
113 // If tag extra field value, use the extra field name as key
114 if (fLastExtraFieldName == null) {
115 return;
116 }
117 key = fLastExtraFieldName;
118 }
119 if (inputAction == CustomTraceDefinition.ACTION_SET) {
120 fData.put(key, value);
121 if (key.equals(Tag.TIMESTAMP)) {
122 fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
123 }
124 } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {
125 String s = fData.get(key);
126 if (s != null) {
127 fData.put(key, s + value);
128 } else {
129 fData.put(key, value);
130 }
131 if (key.equals(Tag.TIMESTAMP)) {
132 String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
133 if (timeStampInputFormat != null) {
134 fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat);
135 } else {
136 fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
137 }
138 }
139 } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
140 String s = fData.get(key);
141 if (s != null) {
142 fData.put(key, s + CustomTraceDefinition.SEPARATOR + value);
143 } else {
144 fData.put(key, value);
145 }
146 if (key.equals(Tag.TIMESTAMP)) {
147 String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
148 if (timeStampInputFormat != null) {
149 fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
150 } else {
151 fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
152 }
153 }
154 }
155 }
156
157 }
This page took 0.034952 seconds and 5 git commands to generate.