TMF: Introduce a framework to hook trace analysis modules/plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TraceTypeHelper.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.project.model;
14
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
17
18 /**
19 * TraceTypeHelper, a helper that can link a few names to a configuation element
20 * and a trace
21 *
22 * @author Matthew Khouzam
23 * @since 2.0
24 */
25 public class TraceTypeHelper {
26
27 private final String fName;
28 private final String fCategoryName;
29 private final String fCanonicalName;
30 private final ITmfTrace fTrace;
31
32 /**
33 * Constructor for a trace type helper. It is a link between a canonical
34 * (hard to read) name, a category name, a name and a trace object. It is
35 * used for trace validation.
36 *
37 * @param canonicalName
38 * The "path" of the tracetype
39 * @param categoryName
40 * the category of the trace type
41 * @param name
42 * the name of the trace
43 * @param trace
44 * an object of the trace type
45 */
46 public TraceTypeHelper(String canonicalName, String categoryName, String name, ITmfTrace trace) {
47 fName = name;
48 fCategoryName = categoryName;
49 fCanonicalName = canonicalName;
50 fTrace = trace;
51 }
52
53 /**
54 * Get the name
55 *
56 * @return the name
57 */
58 public String getName() {
59 return fName;
60 }
61
62 /**
63 * Get the category name
64 *
65 * @return the category name
66 */
67 public String getCategoryName() {
68 return fCategoryName;
69 }
70
71 /**
72 * Get the canonical name
73 *
74 * @return the canonical Name
75 */
76 public String getCanonicalName() {
77 return fCanonicalName;
78 }
79
80 /**
81 * Is the trace of this type?
82 *
83 * @param path
84 * the trace to validate
85 * @return whether it passes the validation
86 */
87 public boolean validate(String path) {
88 boolean valid = false;
89 if (fTrace != null) {
90 valid = standardValidate(path);
91 }
92 return valid;
93 }
94
95 /**
96 * Get an object of the trace type
97 * @return an object of the trace type
98 * @since 2.1
99 */
100 public ITmfTrace getTrace() {
101 return fTrace;
102 }
103
104 private boolean standardValidate(String path) {
105 final boolean valid = fTrace.validate(null, path).equals(Status.OK_STATUS);
106 return valid;
107 }
108
109 /**
110 * Get the class associated with this trace type
111 *
112 * @return The trace class
113 * @since 3.0
114 */
115 public Class<? extends ITmfTrace> getTraceClass() {
116 return fTrace.getClass();
117 }
118
119 @Override
120 public String toString() {
121 return fName;
122 }
123
124 }
This page took 0.036363 seconds and 5 git commands to generate.