-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r
-\r
-import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map.Entry;\r
-import java.util.regex.Matcher;\r
-\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;\r
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;\r
-\r
-public class CustomTxtTrace extends TmfTrace<CustomTxtEvent> {\r
-\r
- private static final TmfLocation<Long> NULL_LOCATION = new TmfLocation<Long>((Long) null);\r
- private static final int DEFAULT_CACHE_SIZE = 100;\r
-\r
- private final CustomTxtTraceDefinition fDefinition;\r
- private final CustomTxtEventType fEventType;\r
-\r
- public CustomTxtTrace(final CustomTxtTraceDefinition definition) {\r
- fDefinition = definition;\r
- fEventType = new CustomTxtEventType(fDefinition);\r
- }\r
-\r
- public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int pageSize) throws FileNotFoundException {\r
- super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);\r
- fDefinition = definition;\r
- fEventType = new CustomTxtEventType(fDefinition);\r
- }\r
-\r
- @Override\r
- public void initTrace(final IResource resource, final String path, final Class<CustomTxtEvent> eventType) throws FileNotFoundException {\r
- super.initTrace(resource, path, eventType);\r
- }\r
-\r
- @Override\r
- public TmfContext seekLocation(final ITmfLocation<?> location) {\r
- final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
- if (NULL_LOCATION.equals(location) || !new File(getPath()).isFile())\r
- return context;\r
- BufferedRandomAccessFile raFile = null;\r
- try {\r
- raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- if (location != null && location.getLocation() instanceof Long) {\r
- raFile.seek((Long)location.getLocation());\r
- }\r
- String line;\r
- long rawPos = raFile.getFilePointer();\r
- while ((line = raFile.getNextLine()) != null) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLocation<Long>(rawPos));\r
- context.raFile = raFile;\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = raFile.getFilePointer();\r
- context.inputLine = input;\r
- return context;\r
- }\r
- }\r
- rawPos = raFile.getFilePointer();\r
- }\r
- return context;\r
- } catch (final FileNotFoundException e) {\r
- e.printStackTrace();\r
- return context;\r
- } catch (final IOException e) {\r
- e.printStackTrace();\r
- return context;\r
- } finally {\r
- if (raFile != null) {\r
- try {\r
- raFile.close();\r
- } catch (final IOException e) {\r
- }\r
- }\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public TmfContext seekLocation(final double ratio) {\r
- BufferedRandomAccessFile raFile = null;\r
- try {\r
- raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- long pos = (long) (ratio * raFile.length());\r
- while (pos > 0) {\r
- raFile.seek(pos - 1);\r
- if (raFile.read() == '\n') {\r
- break;\r
- }\r
- pos--;\r
- }\r
- final ITmfLocation<?> location = new TmfLocation<Long>(pos);\r
- final TmfContext context = seekLocation(location);\r
- context.setRank(ITmfContext.UNKNOWN_RANK);\r
- return context;\r
- } catch (final FileNotFoundException e) {\r
- e.printStackTrace();\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
- } catch (final IOException e) {\r
- e.printStackTrace();\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
- } finally {\r
- if (raFile != null) {\r
- try {\r
- raFile.close();\r
- } catch (final IOException e) {\r
- }\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public double getLocationRatio(final ITmfLocation<?> location) {\r
- BufferedRandomAccessFile raFile = null;\r
- try {\r
- if (location.getLocation() instanceof Long) {\r
- raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- return (double) ((Long) location.getLocation()) / raFile.length();\r
- }\r
- } catch (final FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (final IOException e) {\r
- e.printStackTrace();\r
- } finally {\r
- if (raFile != null) {\r
- try {\r
- raFile.close();\r
- } catch (final IOException e) {\r
- }\r
- }\r
- }\r
- return 0;\r
- }\r
-\r
- @Override\r
- public ITmfLocation<?> getCurrentLocation() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- public synchronized TmfEvent getNextEvent(final ITmfContext context) {\r
- final ITmfContext savedContext = context.clone();\r
- final TmfEvent event = parseEvent(context);\r
- if (event != null) {\r
- updateIndex(savedContext, savedContext.getRank(), event.getTimestamp());\r
- context.increaseRank();\r
- }\r
- return event;\r
- }\r
-\r
- @Override\r
- public TmfEvent parseEvent(final ITmfContext tmfContext) {\r
- if (!(tmfContext instanceof CustomTxtTraceContext))\r
- return null;\r
-\r
- final CustomTxtTraceContext context = (CustomTxtTraceContext) tmfContext;\r
- if (!(context.getLocation().getLocation() instanceof Long) || NULL_LOCATION.equals(context.getLocation()))\r
- return null;\r
-\r
- CustomTxtEvent event = parseFirstLine(context);\r
-\r
- final HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();\r
- InputLine currentInput = null;\r
- if (context.inputLine.childrenInputs != null && context.inputLine.childrenInputs.size() > 0) {\r
- currentInput = context.inputLine.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- }\r
-\r
- synchronized (context.raFile) {\r
- try {\r
- if (context.raFile.getFilePointer() != context.nextLineLocation) {\r
- context.raFile.seek(context.nextLineLocation);\r
- }\r
- String line;\r
- long rawPos = context.raFile.getFilePointer();\r
- while ((line = context.raFile.getNextLine()) != null) {\r
- boolean processed = false;\r
- if (currentInput == null) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLocation<Long>(rawPos));\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = context.raFile.getFilePointer();\r
- context.inputLine = input;\r
- return event;\r
- }\r
- }\r
- } else {\r
- if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r
- final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r
- if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r
- for (final InputLine input : getFirstLines()) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- context.setLocation(new TmfLocation<Long>(rawPos));\r
- context.firstLineMatcher = matcher;\r
- context.firstLine = line;\r
- context.nextLineLocation = context.raFile.getFilePointer();\r
- context.inputLine = input;\r
- return event;\r
- }\r
- }\r
- }\r
- for (final InputLine input : nextInputs) {\r
- final Matcher matcher = input.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- event.processGroups(input, matcher);\r
- currentInput = input;\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 1);\r
- } else {\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- }\r
- Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else if (countMap.get(currentInput) >= currentInput.getMaxCount())\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- processed = true;\r
- break;\r
- }\r
- }\r
- }\r
- if (! processed) {\r
- final Matcher matcher = currentInput.getPattern().matcher(line);\r
- if (matcher.find()) {\r
- event.processGroups(currentInput, matcher);\r
- countMap.put(currentInput, countMap.get(currentInput) + 1);\r
- if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
- currentInput = currentInput.childrenInputs.get(0);\r
- countMap.put(currentInput, 0);\r
- } else if (countMap.get(currentInput) >= currentInput.getMaxCount())\r
- if (currentInput.getNextInputs(countMap).size() > 0) {\r
- currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null) {\r
- countMap.put(currentInput, 0);\r
- }\r
- final Iterator<InputLine> iter = countMap.keySet().iterator();\r
- while (iter.hasNext()) {\r
- final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level) {\r
- iter.remove();\r
- }\r
- }\r
- } else {\r
- currentInput = null;\r
- }\r
- }\r
- ((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$\r
- }\r
- }\r
- rawPos = context.raFile.getFilePointer();\r
- }\r
- } catch (final IOException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- for(final Entry<InputLine, Integer> entry : countMap.entrySet())\r
- if (entry.getValue() < entry.getKey().getMinCount()) {\r
- event = null;\r
- }\r
- context.setLocation(NULL_LOCATION);\r
- return event;\r
- }\r
-\r
- public List<InputLine> getFirstLines() {\r
- return fDefinition.inputs;\r
- }\r
-\r
- public CustomTxtEvent parseFirstLine(final CustomTxtTraceContext context) {\r
- final CustomTxtEvent event = new CustomTxtEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType, ""); //$NON-NLS-1$ //$NON-NLS-2$\r
- event.processGroups(context.inputLine, context.firstLineMatcher);\r
- event.setContent(new CustomEventContent(event, context.firstLine));\r
- return event;\r
- }\r
-\r
- public CustomTraceDefinition getDefinition() {\r
- return fDefinition;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+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.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+
+/**
+ * Base class for custom plain text traces.
+ *
+ * @author Patrick Tassé
+ */
+public class CustomTxtTrace extends TmfTrace implements ITmfEventParser {
+
+ private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation((Long) null);
+ private static final int DEFAULT_CACHE_SIZE = 100;
+
+ private final CustomTxtTraceDefinition fDefinition;
+ private final CustomTxtEventType fEventType;
+ private BufferedRandomAccessFile fFile;
+
+ /**
+ * Basic constructor.
+ *
+ * @param definition
+ * Text trace definition
+ */
+ public CustomTxtTrace(final CustomTxtTraceDefinition definition) {
+ fDefinition = definition;
+ fEventType = new CustomTxtEventType(fDefinition);
+ setCacheSize(DEFAULT_CACHE_SIZE);
+ }
+
+ /**
+ * Full constructor.
+ *
+ * @param resource
+ * Trace's resource.
+ * @param definition
+ * Text trace definition
+ * @param path
+ * Path to the trace file
+ * @param cacheSize
+ * Cache size to use
+ * @throws TmfTraceException
+ * If we couldn't open the trace at 'path'
+ */
+ public CustomTxtTrace(final IResource resource,
+ final CustomTxtTraceDefinition definition, final String path,
+ final int cacheSize) throws TmfTraceException {
+ this(definition);
+ setCacheSize((cacheSize > 0) ? cacheSize : DEFAULT_CACHE_SIZE);
+ initTrace(resource, path, CustomTxtEvent.class);
+ }
+
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType) throws TmfTraceException {
+ super.initTrace(resource, path, eventType);
+ try {
+ fFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new TmfTraceException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ if (fFile != null) {
+ try {
+ fFile.close();
+ } catch (IOException e) {
+ } finally {
+ fFile = null;
+ }
+ }
+ }
+
+ @Override
+ public ITmfTraceIndexer getIndexer() {
+ return super.getIndexer();
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final ITmfLocation location) {
+ final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ if (NULL_LOCATION.equals(location) || fFile == null) {
+ return context;
+ }
+ try {
+ if (location == null) {
+ fFile.seek(0);
+ } else if (location.getLocationInfo() instanceof Long) {
+ fFile.seek((Long) location.getLocationInfo());
+ }
+ String line;
+ long rawPos = fFile.getFilePointer();
+ while ((line = fFile.getNextLine()) != null) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return context;
+ }
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ return context;
+ } catch (final FileNotFoundException e) {
+ Activator.getDefault().logError("Error seeking event. File not found: " + getPath(), e); //$NON-NLS-1$
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return context;
+ }
+
+ }
+
+ @Override
+ public synchronized TmfContext seekEvent(final double ratio) {
+ if (fFile == null) {
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ try {
+ long pos = Math.round(ratio * fFile.length());
+ while (pos > 0) {
+ fFile.seek(pos - 1);
+ if (fFile.read() == '\n') {
+ break;
+ }
+ pos--;
+ }
+ final ITmfLocation location = new TmfLongLocation(pos);
+ final TmfContext context = seekEvent(location);
+ context.setRank(ITmfContext.UNKNOWN_RANK);
+ return context;
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);
+ }
+ }
+
+ @Override
+ public synchronized double getLocationRatio(final ITmfLocation location) {
+ if (fFile == null) {
+ return 0;
+ }
+ try {
+ if (location.getLocationInfo() instanceof Long) {
+ return (double) ((Long) location.getLocationInfo()) / fFile.length();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ return 0;
+ }
+
+ @Override
+ public ITmfLocation getCurrentLocation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public synchronized CustomTxtEvent parseEvent(final ITmfContext tmfContext) {
+ ITmfContext context = seekEvent(tmfContext.getLocation());
+ return parse(context);
+ }
+
+ @Override
+ public synchronized CustomTxtEvent getNext(final ITmfContext context) {
+ final ITmfContext savedContext = new TmfContext(context.getLocation(), context.getRank());
+ final CustomTxtEvent event = parse(context);
+ if (event != null) {
+ updateAttributes(savedContext, event.getTimestamp());
+ context.increaseRank();
+ }
+ return event;
+ }
+
+ private synchronized CustomTxtEvent parse(final ITmfContext tmfContext) {
+ if (fFile == null) {
+ return null;
+ }
+ if (!(tmfContext instanceof CustomTxtTraceContext)) {
+ return null;
+ }
+
+ final CustomTxtTraceContext context = (CustomTxtTraceContext) tmfContext;
+ if (context.getLocation() == null || !(context.getLocation().getLocationInfo() instanceof Long) || NULL_LOCATION.equals(context.getLocation())) {
+ return null;
+ }
+
+ CustomTxtEvent event = parseFirstLine(context);
+
+ final HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();
+ InputLine currentInput = null;
+ if (context.inputLine.childrenInputs != null && context.inputLine.childrenInputs.size() > 0) {
+ currentInput = context.inputLine.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ }
+
+ try {
+ if (fFile.getFilePointer() != context.nextLineLocation) {
+ fFile.seek(context.nextLineLocation);
+ }
+ String line;
+ long rawPos = fFile.getFilePointer();
+ while ((line = fFile.getNextLine()) != null) {
+ boolean processed = false;
+ if (currentInput == null) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return event;
+ }
+ }
+ } else {
+ if (countMap.get(currentInput) >= currentInput.getMinCount()) {
+ final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);
+ if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {
+ for (final InputLine input : getFirstLines()) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ context.setLocation(new TmfLongLocation(rawPos));
+ context.firstLineMatcher = matcher;
+ context.firstLine = line;
+ context.nextLineLocation = fFile.getFilePointer();
+ context.inputLine = input;
+ return event;
+ }
+ }
+ }
+ for (final InputLine input : nextInputs) {
+ final Matcher matcher = input.getPattern().matcher(line);
+ if (matcher.find()) {
+ event.processGroups(input, matcher);
+ currentInput = input;
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 1);
+ } else {
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ }
+ Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ processed = true;
+ break;
+ }
+ }
+ }
+ if (!processed && currentInput != null) {
+ final Matcher matcher = currentInput.getPattern().matcher(line);
+ if (matcher.find()) {
+ event.processGroups(currentInput, matcher);
+ countMap.put(currentInput, countMap.get(currentInput) + 1);
+ if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {
+ currentInput = currentInput.childrenInputs.get(0);
+ countMap.put(currentInput, 0);
+ } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) {
+ if (currentInput.getNextInputs(countMap).size() > 0) {
+ currentInput = currentInput.getNextInputs(countMap).get(0);
+ if (countMap.get(currentInput) == null) {
+ countMap.put(currentInput, 0);
+ }
+ final Iterator<InputLine> iter = countMap.keySet().iterator();
+ while (iter.hasNext()) {
+ final InputLine inputLine = iter.next();
+ if (inputLine.level > currentInput.level) {
+ iter.remove();
+ }
+ }
+ } else {
+ currentInput = null;
+ }
+ }
+ }
+ ((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$
+ }
+ }
+ rawPos = fFile.getFilePointer();
+ }
+ } catch (final IOException e) {
+ Activator.getDefault().logError("Error seeking event. File: " + getPath(), e); //$NON-NLS-1$
+ }
+ for (final Entry<InputLine, Integer> entry : countMap.entrySet()) {
+ if (entry.getValue() < entry.getKey().getMinCount()) {
+ event = null;
+ }
+ }
+ context.setLocation(NULL_LOCATION);
+ return event;
+ }
+
+ /**
+ * @return The first few lines of the text file
+ */
+ public List<InputLine> getFirstLines() {
+ return fDefinition.inputs;
+ }
+
+ /**
+ * Parse the first line of the trace (to recognize the type).
+ *
+ * @param context
+ * Trace context
+ * @return The first event
+ */
+ public CustomTxtEvent parseFirstLine(final CustomTxtTraceContext context) {
+ final CustomTxtEvent event = new CustomTxtEvent(fDefinition, this, TmfTimestamp.ZERO, "", fEventType, ""); //$NON-NLS-1$ //$NON-NLS-2$
+ event.processGroups(context.inputLine, context.firstLineMatcher);
+ event.setContent(new CustomEventContent(event, new StringBuffer(context.firstLine)));
+ return event;
+ }
+
+ /**
+ * Get the trace definition.
+ *
+ * @return The trace definition
+ */
+ public CustomTraceDefinition getDefinition() {
+ return fDefinition;
+ }
+
+ @Override
+ public IStatus validate(IProject project, String path) {
+ if( fileExists(path)) {
+ return Status.OK_STATUS;
+ }
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID ,Messages.CustomTrace_FileNotFound + ": " + path); //$NON-NLS-1$
+ }
+}