2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / component / TmfDataProviderStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.component;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
20 import org.eclipse.core.runtime.FileLocator;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.linuxtools.tmf.event.TmfData;
23 import org.eclipse.linuxtools.tmf.request.ITmfDataRequest;
24 import org.eclipse.linuxtools.tmf.request.ITmfEventRequest;
25 import org.eclipse.linuxtools.tmf.tests.TmfCoreTestPlugin;
26 import org.eclipse.linuxtools.tmf.trace.ITmfContext;
27 import org.eclipse.linuxtools.tmf.trace.TmfTraceStub;
28
29 /**
30 * <b><u>TmfDataProviderStub</u></b>
31 * <p>
32 * TODO: Implement me. Please.
33 */
34 @SuppressWarnings("nls")
35 public class TmfDataProviderStub extends TmfDataProvider<TmfData> {
36
37 private static final String DIRECTORY = "testfiles";
38 private static final String TEST_STREAM = "M-Test-10K";
39
40 private TmfTraceStub fTrace;
41
42 public TmfDataProviderStub(String path) throws IOException {
43 super("TmfDataProviderStub", TmfData.class);
44 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
45 try {
46 File test = new File(FileLocator.toFileURL(location).toURI());
47 fTrace = new TmfTraceStub(test.getPath(), true);
48 } catch (URISyntaxException e) {
49 e.printStackTrace();
50 }
51 }
52
53 public TmfDataProviderStub() throws IOException {
54 this(DIRECTORY + File.separator + TEST_STREAM);
55 }
56
57 // ------------------------------------------------------------------------
58 // TmfProvider
59 // ------------------------------------------------------------------------
60
61 @Override
62 public ITmfContext armRequest(ITmfDataRequest<TmfData> request) {
63 if (request instanceof ITmfEventRequest<?>) {
64 ITmfContext context = fTrace.seekEvent(((ITmfEventRequest<?>) request).getRange().getStartTime());
65 return context;
66 }
67 return null;
68 }
69
70 @Override
71 public TmfData getNext(ITmfContext context) {
72 return fTrace.getNext(context);
73 }
74
75 @Override
76 public boolean isCompleted(ITmfDataRequest<TmfData> request, TmfData data, int nbRead) {
77 return false;
78 }
79
80 }
This page took 0.032788 seconds and 5 git commands to generate.