analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTraceDefinition.java
CommitLineData
be222f56 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2010, 2014 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
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.core.parsers.custom;
be222f56 14
cb1cf0e8 15import java.io.ByteArrayInputStream;
be222f56
PT
16import java.text.SimpleDateFormat;
17import java.util.List;
18
2bdf0193 19import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
cb1cf0e8
MK
20import org.xml.sax.EntityResolver;
21import org.xml.sax.ErrorHandler;
22import org.xml.sax.InputSource;
23import org.xml.sax.SAXException;
24import org.xml.sax.SAXParseException;
be222f56 25
a0a88f65
AM
26/**
27 * Base class for custom trace definitions.
28 *
29 * @author Patrick Tassé
30 */
be222f56
PT
31public abstract class CustomTraceDefinition {
32
a0a88f65 33 /** "set" action */
be222f56 34 public static final int ACTION_SET = 0;
a0a88f65
AM
35
36 /** "append" action */
be222f56 37 public static final int ACTION_APPEND = 1;
a0a88f65
AM
38
39 /** "append with separator" action */
be222f56
PT
40 public static final int ACTION_APPEND_WITH_SEPARATOR = 2;
41
a0a88f65 42 /** Timestamp tag */
be222f56 43 public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;
a0a88f65
AM
44
45 /** Message tag */
be222f56 46 public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;
a0a88f65
AM
47
48 /** "Other" tag */
be222f56
PT
49 public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
50
ae09c4ad 51 /** Category of this trace definition */
332527a4
PT
52 public String categoryName;
53
a0a88f65 54 /** Name of this trace definition */
be222f56 55 public String definitionName;
a0a88f65
AM
56
57 /** List of output columns */
be222f56 58 public List<OutputColumn> outputs;
a0a88f65
AM
59
60 /** Timestamp format */
be222f56
PT
61 public String timeStampOutputFormat;
62
a0a88f65
AM
63 /**
64 * Definition of an output column
65 */
be222f56 66 public static class OutputColumn {
a0a88f65
AM
67
68 /** Name of this column */
be222f56
PT
69 public String name;
70
a0a88f65
AM
71 /**
72 * Default constructor (empty)
73 */
be222f56
PT
74 public OutputColumn() {}
75
a0a88f65
AM
76 /**
77 * Constructor
78 *
79 * @param name Name of this output column
80 */
be222f56
PT
81 public OutputColumn(String name) {
82 this.name = name;
83 }
84
85 @Override
86 public String toString() {
87 return name;
88 }
89 }
90
a0a88f65
AM
91 /**
92 * Format a timestamp in this trace's current time stamp format.
93 *
94 * @param timestamp
95 * The timestamp to format
96 * @return The same timestamp as a formatted string
97 */
be222f56
PT
98 public String formatTimeStamp(TmfTimestamp timestamp) {
99 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeStampOutputFormat);
100 return simpleDateFormat.format(timestamp.getValue());
101 }
102
a0a88f65
AM
103 /**
104 * Save this custom trace in the default path.
105 */
be222f56 106 public abstract void save();
a0a88f65
AM
107
108 /**
109 * Save this custom trace in the supplied path.
110 *
111 * @param path
112 * The path to save to
113 */
be222f56 114 public abstract void save(String path);
cb1cf0e8
MK
115
116 /**
117 * Creates a new empty entity resolver
118 *
119 * @return a new entity resolver
cb1cf0e8
MK
120 */
121 protected static EntityResolver createEmptyEntityResolver() {
122 return new EntityResolver() {
123 @Override
124 public InputSource resolveEntity(String publicId, String systemId) {
125 String empty = ""; //$NON-NLS-1$
126 ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
127 return new InputSource(bais);
128 }
129 };
130 }
131
132 /**
133 * Creates an error handler for parse exceptions
134 *
135 * @return a new error handler
cb1cf0e8
MK
136 */
137 protected static ErrorHandler createErrorHandler() {
138 return new ErrorHandler() {
139 @Override
140 public void error(SAXParseException saxparseexception) throws SAXException {
141 }
142
143 @Override
144 public void warning(SAXParseException saxparseexception) throws SAXException {
145 }
146
147 @Override
148 public void fatalError(SAXParseException saxparseexception) throws SAXException {
149 throw saxparseexception;
150 }
151 };
152 }
be222f56 153}
This page took 0.071959 seconds and 5 git commands to generate.