tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTraceDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 java.io.ByteArrayInputStream;
16 import java.text.SimpleDateFormat;
17 import java.util.List;
18
19 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
20 import org.xml.sax.EntityResolver;
21 import org.xml.sax.ErrorHandler;
22 import org.xml.sax.InputSource;
23 import org.xml.sax.SAXException;
24 import org.xml.sax.SAXParseException;
25
26 /**
27 * Base class for custom trace definitions.
28 *
29 * @author Patrick Tassé
30 */
31 public abstract class CustomTraceDefinition {
32
33 /** "set" action */
34 public static final int ACTION_SET = 0;
35
36 /** "append" action */
37 public static final int ACTION_APPEND = 1;
38
39 /** "append with separator" action */
40 public static final int ACTION_APPEND_WITH_SEPARATOR = 2;
41
42 /** Timestamp tag */
43 public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;
44
45 /** Message tag */
46 public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;
47
48 /** "Other" tag */
49 public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
50
51 /** Category of this trace definition */
52 public String categoryName;
53
54 /** Name of this trace definition */
55 public String definitionName;
56
57 /** List of output columns */
58 public List<OutputColumn> outputs;
59
60 /** Timestamp format */
61 public String timeStampOutputFormat;
62
63 /**
64 * Definition of an output column
65 */
66 public static class OutputColumn {
67
68 /** Name of this column */
69 public String name;
70
71 /**
72 * Default constructor (empty)
73 */
74 public OutputColumn() {}
75
76 /**
77 * Constructor
78 *
79 * @param name Name of this output column
80 */
81 public OutputColumn(String name) {
82 this.name = name;
83 }
84
85 @Override
86 public String toString() {
87 return name;
88 }
89 }
90
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 */
98 public String formatTimeStamp(TmfTimestamp timestamp) {
99 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeStampOutputFormat);
100 return simpleDateFormat.format(timestamp.getValue());
101 }
102
103 /**
104 * Save this custom trace in the default path.
105 */
106 public abstract void save();
107
108 /**
109 * Save this custom trace in the supplied path.
110 *
111 * @param path
112 * The path to save to
113 */
114 public abstract void save(String path);
115
116 /**
117 * Creates a new empty entity resolver
118 *
119 * @return a new entity resolver
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
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 }
153 }
This page took 0.048171 seconds and 6 git commands to generate.