1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
.linuxtools
.tmf
.core
.parsers
.custom
;
15 import java
.io
.ByteArrayInputStream
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.List
;
19 import org
.eclipse
.linuxtools
.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
;
27 * Base class for custom trace definitions.
29 * @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
;
52 /** Name of this trace definition */
53 public String definitionName
;
55 /** List of output columns */
56 public List
<OutputColumn
> outputs
;
58 /** Timestamp format */
59 public String timeStampOutputFormat
;
62 * Definition of an output column
64 public static class OutputColumn
{
66 /** Name of this column */
70 * Default constructor (empty)
72 public OutputColumn() {}
77 * @param name Name of this output column
79 public OutputColumn(String name
) {
84 public String
toString() {
90 * Format a timestamp in this trace's current time stamp format.
93 * The timestamp to format
94 * @return The same timestamp as a formatted string
96 public String
formatTimeStamp(TmfTimestamp timestamp
) {
97 SimpleDateFormat simpleDateFormat
= new SimpleDateFormat(timeStampOutputFormat
);
98 return simpleDateFormat
.format(timestamp
.getValue());
102 * Save this custom trace in the default path.
104 public abstract void save();
107 * Save this custom trace in the supplied path.
110 * The path to save to
112 public abstract void save(String path
);
115 * Creates a new empty entity resolver
117 * @return a new entity resolver
120 protected static EntityResolver
createEmptyEntityResolver() {
121 return new EntityResolver() {
123 public InputSource
resolveEntity(String publicId
, String systemId
) {
124 String empty
= ""; //$NON-NLS-1$
125 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
126 return new InputSource(bais
);
132 * Creates an error handler for parse exceptions
134 * @return a new error handler
137 protected static ErrorHandler
createErrorHandler() {
138 return new ErrorHandler() {
140 public void error(SAXParseException saxparseexception
) throws SAXException
{
144 public void warning(SAXParseException saxparseexception
) throws SAXException
{
148 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
149 throw saxparseexception
;