tmf: Move TmfTraceType and custom parsers to tmf.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / parsers / custom / CustomTxtEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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.linuxtools.tmf.core.parsers.custom;
14
15 import java.util.regex.Matcher;
16
17 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
18 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
19 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
20 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
21 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
22 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
23 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
24
25 /**
26 * Trace event for custom text parsers.
27 *
28 * @author Patrick Tassé
29 * @since 3.0
30 */
31 public class CustomTxtEvent extends CustomEvent {
32
33 /**
34 * Constructor
35 *
36 * @param definition
37 * Trace definition
38 */
39 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
40 super(definition);
41 setType(new CustomTxtEventType(definition));
42 }
43
44 /**
45 * Construct a custom text event from an existing TmfEvent.
46 *
47 * @param definition
48 * Trace definition
49 * @param other
50 * The TmfEvent object to copy
51 */
52 public CustomTxtEvent(CustomTxtTraceDefinition definition, TmfEvent other) {
53 super(definition, other);
54 }
55
56 /**
57 * Full constructor.
58 *
59 * @param definition
60 * Trace definition
61 * @param parentTrace
62 * Parent trace object
63 * @param timestamp
64 * Timestamp of this event
65 * @param source
66 * Source of this event
67 * @param type
68 * Event type
69 * @param reference
70 * Reference if this event
71 */
72 public CustomTxtEvent(CustomTxtTraceDefinition definition,
73 ITmfTrace parentTrace, ITmfTimestamp timestamp, String source,
74 TmfEventType type, String reference) {
75 super(definition, parentTrace, timestamp, source, type, reference);
76 }
77
78 @Override
79 public void setContent(ITmfEventField content) {
80 super.setContent(content);
81 }
82
83 /**
84 * Process an entry in the trace file
85 *
86 * @param input
87 * The input line to read
88 * @param matcher
89 * The regex matcher to use
90 */
91 public void processGroups(InputLine input, Matcher matcher) {
92 if (input.columns == null) {
93 return;
94 }
95 for (int i = 0; i < input.columns.size(); i++) {
96 InputData column = input.columns.get(i);
97 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
98 String value = matcher.group(i + 1).trim();
99 if (value.length() == 0) {
100 continue;
101 }
102 String name = column.name;
103 if (column.action == CustomTraceDefinition.ACTION_SET) {
104 fData.put(name, value);
105 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
106 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
107 }
108 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
109 String s = fData.get(name);
110 if (s != null) {
111 fData.put(name, s + value);
112 } else {
113 fData.put(name, value);
114 }
115 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
116 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
117 if (timeStampInputFormat != null) {
118 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
119 } else {
120 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
121 }
122 }
123 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
124 String s = fData.get(name);
125 if (s != null) {
126 fData.put(name, s + " | " + value); //$NON-NLS-1$
127 } else {
128 fData.put(name, value);
129 }
130 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
131 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
132 if (timeStampInputFormat != null) {
133 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
134 } else {
135 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
136 }
137 }
138 }
139 }
140 }
141 }
142
143 }
This page took 0.039919 seconds and 5 git commands to generate.