/*******************************************************************************
- * Copyright (c) 2010 Ericsson
+ * Copyright (c) 2010, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
+/**
+ * Trace object for custom XML trace parsers.
+ *
+ * @author Patrick Tassé
+ */
public class CustomXmlTrace extends TmfTrace implements ITmfEventParser {
private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);
private final InputElement fRecordInputElement;
private BufferedRandomAccessFile fFile;
+ /**
+ * Basic constructor
+ *
+ * @param definition Trace definition
+ */
public CustomXmlTrace(final CustomXmlTraceDefinition definition) {
fDefinition = definition;
fEventType = new CustomXmlEventType(fDefinition);
setCacheSize(DEFAULT_CACHE_SIZE);
}
- public CustomXmlTrace(final IResource resource, final CustomXmlTraceDefinition definition, final String path, final int pageSize) throws TmfTraceException {
+ /**
+ * Full constructor
+ *
+ * @param resource
+ * Trace resource
+ * @param definition
+ * Trace definition
+ * @param path
+ * Path to the trace/log file
+ * @param pageSize
+ * Page size to use
+ * @throws TmfTraceException
+ * If the trace/log couldn't be opened
+ */
+ public CustomXmlTrace(final IResource resource,
+ final CustomXmlTraceDefinition definition, final String path,
+ final int pageSize) throws TmfTraceException {
this(definition);
setCacheSize((pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);
initTrace(resource, path, CustomXmlEvent.class);
} catch (IOException e) {
throw new TmfTraceException(e.getMessage(), e);
}
- indexTrace(false);
}
@Override
}
}
+ @Override
+ public ITmfTraceIndexer getIndexer() {
+ return super.getIndexer();
+ }
+
@Override
public synchronized TmfContext seekEvent(final ITmfLocation location) {
final CustomXmlTraceContext context = new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
}
final CustomXmlTraceContext context = (CustomXmlTraceContext) tmfContext;
- if (!(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {
+ if (context.getLocation() == null || !(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {
return null;
}
}
}
+ /**
+ * Parse an XML element.
+ *
+ * @param parentElement
+ * The parent element
+ * @param buffer
+ * The contents to parse
+ * @return The parsed content
+ */
public static StringBuffer parseElement(final Element parentElement, final StringBuffer buffer) {
final NodeList nodeList = parentElement.getChildNodes();
String separator = null;
return buffer;
}
+ /**
+ * Get an input element if it is a valid record input. If not, we will look
+ * into its children for valid inputs.
+ *
+ * @param inputElement
+ * The main element to check for.
+ * @return The record element
+ */
public InputElement getRecordInputElement(final InputElement inputElement) {
if (inputElement.logEntry) {
return inputElement;
return null;
}
+ /**
+ * Extract a trace event from an XML element.
+ *
+ * @param element
+ * The element
+ * @param inputElement
+ * The input element
+ * @return The extracted event
+ */
public CustomXmlEvent extractEvent(final Element element, final InputElement inputElement) {
final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType,""); //$NON-NLS-1$ //$NON-NLS-2$
event.setContent(new CustomEventContent(event, new StringBuffer()));
return;
}
+ /**
+ * Retrieve the trace definition.
+ *
+ * @return The trace definition
+ */
public CustomTraceDefinition getDefinition() {
return fDefinition;
}