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