Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / parsers / custom / CustomXmlTrace.java
index eb9dc0603bb003796eb1f7dfcbc4ae67c08a9da6..9f8f2931a982463e299b9dc22a033e11d99fe645 100644 (file)
@@ -22,17 +22,17 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;\r
 import javax.xml.parsers.ParserConfigurationException;\r
 \r
-import org.eclipse.linuxtools.tmf.event.TmfEvent;\r
-import org.eclipse.linuxtools.tmf.event.TmfEventReference;\r
-import org.eclipse.linuxtools.tmf.event.TmfEventSource;\r
-import org.eclipse.linuxtools.tmf.event.TmfTimestamp;\r
-import org.eclipse.linuxtools.tmf.io.BufferedRandomAccessFile;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfContext;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfLocation;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.trace.TmfContext;\r
-import org.eclipse.linuxtools.tmf.trace.TmfLocation;\r
-import org.eclipse.linuxtools.tmf.trace.TmfTrace;\r
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
+import org.eclipse.linuxtools.tmf.core.event.TmfEventReference;\r
+import org.eclipse.linuxtools.tmf.core.event.TmfEventSource;\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.ITmfTrace;\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
 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r
 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r
 import org.w3c.dom.Document;\r
@@ -53,6 +53,12 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
     private CustomXmlEventType fEventType;\r
     private InputElement fRecordInputElement;\r
     \r
+    public CustomXmlTrace(CustomXmlTraceDefinition definition) {\r
+        fDefinition = definition;\r
+        fEventType = new CustomXmlEventType(fDefinition);\r
+        fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);\r
+    }\r
+\r
     public CustomXmlTrace(String name, CustomXmlTraceDefinition definition, String path, int cacheSize) throws FileNotFoundException {\r
         super(name, CustomXmlEvent.class, path, cacheSize);\r
         fDefinition = definition;\r
@@ -100,8 +106,14 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
     @Override\r
     public TmfContext seekLocation(double ratio) {\r
         try {\r
-            RandomAccessFile raFile = new RandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
-            ITmfLocation<?> location = new TmfLocation<Long>(new Long((long) (ratio * raFile.length())));\r
+            BufferedRandomAccessFile 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') break;\r
+                pos--;\r
+            }\r
+            ITmfLocation<?> location = new TmfLocation<Long>(new Long(pos));\r
             TmfContext context = seekLocation(location);\r
             context.setRank(ITmfContext.UNKNOWN_RANK);\r
             return context;\r
@@ -130,14 +142,16 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
     }\r
 \r
     @Override\r
-       public ITmfTrace createTraceCopy() {\r
+    @SuppressWarnings({ "rawtypes", "unchecked" })\r
+       public ITmfTrace copy() {\r
         // TODO Auto-generated method stub\r
         return null;\r
     }\r
     \r
     @Override\r
     public ITmfLocation<?> getCurrentLocation() {\r
-        return new TmfLocation<Object>(null);\r
+        // TODO Auto-generated method stub\r
+        return null;\r
     }\r
 \r
     @Override\r
@@ -350,7 +364,7 @@ public class CustomXmlTrace extends TmfTrace<CustomXmlEvent> {
     }\r
     \r
     public CustomXmlEvent extractEvent(Element element, InputElement inputElement) {\r
-        CustomXmlEvent event = new CustomXmlEvent(fDefinition, TmfTimestamp.Zero, new TmfEventSource(""), fEventType, new TmfEventReference("")); //$NON-NLS-1$ //$NON-NLS-2$\r
+        CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.Zero, new TmfEventSource(""), fEventType, new TmfEventReference("")); //$NON-NLS-1$ //$NON-NLS-2$\r
         event.setContent(new CustomEventContent(event, new StringBuffer()));\r
         parseElement(element, event, inputElement);\r
         return event;\r
This page took 0.025536 seconds and 5 git commands to generate.