1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
;
15 import java
.io
.ByteArrayInputStream
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
21 import org
.xml
.sax
.EntityResolver
;
22 import org
.xml
.sax
.ErrorHandler
;
23 import org
.xml
.sax
.InputSource
;
24 import org
.xml
.sax
.SAXException
;
25 import org
.xml
.sax
.SAXParseException
;
28 * Base class for custom trace definitions.
30 * @author Patrick Tassé
32 public abstract class CustomTraceDefinition
{
35 public static final int ACTION_SET
= 0;
37 /** "append" action */
38 public static final int ACTION_APPEND
= 1;
40 /** "append with separator" action */
41 public static final int ACTION_APPEND_WITH_SEPARATOR
= 2;
44 public static final String TAG_TIMESTAMP
= Messages
.CustomTraceDefinition_timestampTag
;
47 public static final String TAG_MESSAGE
= Messages
.CustomTraceDefinition_messageTag
;
50 public static final String TAG_OTHER
= Messages
.CustomTraceDefinition_otherTag
;
54 public static final String TAG_EVENT_TYPE
= Messages
.CustomTraceDefinition_eventTypeTag
;
56 /** Category of this trace definition */
57 public String categoryName
;
59 /** Name of this trace definition */
60 public String definitionName
;
62 /** List of output columns */
63 public List
<OutputColumn
> outputs
;
65 /** Timestamp format */
66 public String timeStampOutputFormat
;
69 * Definition of an output column
71 public static class OutputColumn
{
73 /** Name of this column */
74 public @NonNull String name
;
77 * Default constructor (empty)
79 public OutputColumn() {
80 this(""); //$NON-NLS-1$
86 * @param name Name of this output column
88 public OutputColumn(@NonNull String name
) {
93 public String
toString() {
99 * Format a timestamp in this trace's current time stamp format.
102 * The timestamp to format
103 * @return The same timestamp as a formatted string
105 public String
formatTimeStamp(TmfTimestamp timestamp
) {
106 SimpleDateFormat simpleDateFormat
= new SimpleDateFormat(timeStampOutputFormat
);
107 return simpleDateFormat
.format(timestamp
.getValue());
111 * Save this custom trace in the default path.
113 public abstract void save();
116 * Save this custom trace in the supplied path.
119 * The path to save to
121 public abstract void save(String path
);
124 * Creates a new empty entity resolver
126 * @return a new entity resolver
128 protected static EntityResolver
createEmptyEntityResolver() {
129 return new EntityResolver() {
131 public InputSource
resolveEntity(String publicId
, String systemId
) {
132 String empty
= ""; //$NON-NLS-1$
133 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
134 return new InputSource(bais
);
140 * Creates an error handler for parse exceptions
142 * @return a new error handler
144 protected static ErrorHandler
createErrorHandler() {
145 return new ErrorHandler() {
147 public void error(SAXParseException saxparseexception
) throws SAXException
{
151 public void warning(SAXParseException saxparseexception
) throws SAXException
{
155 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
156 throw saxparseexception
;