tmf: bug 494698 Add per-event fields to custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomEventAspects.java
CommitLineData
be222f56 1/*******************************************************************************
0fa1aec2 2 * Copyright (c) 2010, 2016 Ericsson
be222f56
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
baafe54c 11 * Alexandre Montplaisir - Update for TmfEventTableColumn
be222f56
PT
12 *******************************************************************************/
13
b04903a2 14package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
be222f56 15
efeeb733
GB
16import java.util.ArrayList;
17import java.util.List;
18
baafe54c 19import org.eclipse.jdt.annotation.NonNull;
9447c7ee 20import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
0fa1aec2
PT
21import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
22import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
2bdf0193
AM
23import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
24import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
0fa1aec2 25import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
be222f56 26
baafe54c
AM
27import com.google.common.collect.ImmutableList;
28
a0a88f65 29/**
b04903a2 30 * Event aspects for Custom {Text|XML} traces.
a0a88f65 31 *
b04903a2
AM
32 * Since this definition will be different for every single custom trace, we
33 * cannot define specific {@link ITmfEventAspect} in advance.
99d7adc6 34 *
b04903a2
AM
35 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
36 * with the CustomTraceDefinition of the the particular trace to display.
99d7adc6
AM
37 *
38 * @author Alexandre Montplaisir
a0a88f65 39 */
b04903a2 40public class CustomEventAspects {
be222f56 41
a0a88f65 42 /**
b04903a2 43 * Build a set of event aspects for a given trace definition
a0a88f65 44 *
b04903a2
AM
45 * @param definition
46 * The {@link CustomTraceDefinition} of the trace for which you
47 * want the aspects
48 * @return The set of event aspects for the given trace
a0a88f65 49 */
ec48d248 50 public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
efeeb733 51 List<String> fieldNames = new ArrayList<>();
ec48d248 52 ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
0fa1aec2 53 for (OutputColumn output : definition.outputs) {
efeeb733 54
4d12b563
PT
55 if (output.tag.equals(Tag.TIMESTAMP) &&
56 (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) {
0fa1aec2 57 builder.add(TmfBaseAspects.getTimestampAspect());
efeeb733 58 fieldNames.add(output.name);
0fa1aec2
PT
59 } else if (output.tag.equals(Tag.EVENT_TYPE)) {
60 builder.add(TmfBaseAspects.getEventTypeAspect());
efeeb733
GB
61 fieldNames.add(output.name);
62 } else if (output.tag.equals(Tag.EXTRA_FIELD_NAME) || output.tag.equals(Tag.EXTRA_FIELD_VALUE)) {
63 // These tags should have been substituted with Tag.EXTRA_FIELDS
64 continue;
65 } else if (output.tag.equals(Tag.EXTRA_FIELDS)) {
66 builder.add(new CustomExtraFieldsAspect());
0fa1aec2
PT
67 } else {
68 builder.add(new TmfContentFieldAspect(output.name, output.name));
efeeb733 69 fieldNames.add(output.name);
0fa1aec2 70 }
be222f56 71 }
0e4f957e 72 return builder.build();
be222f56
PT
73 }
74}
This page took 0.089489 seconds and 5 git commands to generate.