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
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 * Alexandre Montplaisir - Update for TmfEventTableColumn
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
21 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
22 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
23 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
24 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
25 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
26
27 import com.google.common.collect.ImmutableList;
28
29 /**
30 * Event aspects for Custom {Text|XML} traces.
31 *
32 * Since this definition will be different for every single custom trace, we
33 * cannot define specific {@link ITmfEventAspect} in advance.
34 *
35 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
36 * with the CustomTraceDefinition of the the particular trace to display.
37 *
38 * @author Alexandre Montplaisir
39 */
40 public class CustomEventAspects {
41
42 /**
43 * Build a set of event aspects for a given trace definition
44 *
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
49 */
50 public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
51 List<String> fieldNames = new ArrayList<>();
52 ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
53 for (OutputColumn output : definition.outputs) {
54
55 if (output.tag.equals(Tag.TIMESTAMP) &&
56 (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) {
57 builder.add(TmfBaseAspects.getTimestampAspect());
58 fieldNames.add(output.name);
59 } else if (output.tag.equals(Tag.EVENT_TYPE)) {
60 builder.add(TmfBaseAspects.getEventTypeAspect());
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());
67 } else {
68 builder.add(new TmfContentFieldAspect(output.name, output.name));
69 fieldNames.add(output.name);
70 }
71 }
72 return builder.build();
73 }
74 }
This page took 0.035725 seconds and 5 git commands to generate.