c8e430c942af47da0eacdfa5dea9edaa1ca76da2
[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 * Bernd Hufmann - Handling of directory traces types
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.project.model;
15
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
18 import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
19
20 /**
21 * TraceTypeHelper, a helper that can link a few names to a configuration element
22 * and a trace
23 *
24 * @author Matthew Khouzam
25 * @since 3.0
26 */
27 public class TraceTypeHelper {
28
29 private final String fName;
30 private final String fCategoryName;
31 private final String fCanonicalName;
32 private final ITmfTrace fTrace;
33 private final boolean fIsDirectory;
34
35 /**
36 * Constructor for a trace type helper. It is a link between a canonical
37 * (hard to read) name, a category name, a name and a trace object. It is
38 * used for trace validation.
39 *
40 * @param canonicalName
41 * The "path" of the tracetype
42 * @param categoryName
43 * the category of the trace type
44 * @param name
45 * the name of the trace
46 * @param trace
47 * an object of the trace type
48 * @param isDir
49 * flag indicating whether the trace type is for a directory or file trace
50 */
51 public TraceTypeHelper(String canonicalName, String categoryName, String name, ITmfTrace trace, boolean isDir) {
52 fName = name;
53 fCategoryName = categoryName;
54 fCanonicalName = canonicalName;
55 fTrace = trace;
56 fIsDirectory = isDir;
57 }
58
59 /**
60 * Get the name
61 *
62 * @return the name
63 */
64 public String getName() {
65 return fName;
66 }
67
68 /**
69 * Get the category name
70 *
71 * @return the category name
72 */
73 public String getCategoryName() {
74 return fCategoryName;
75 }
76
77 /**
78 * Get the canonical name
79 *
80 * @return the canonical Name
81 */
82 public String getCanonicalName() {
83 return fCanonicalName;
84 }
85
86 /**
87 * Is the trace of this type?
88 *
89 * @param path
90 * the trace to validate
91 * @return whether it passes the validation
92 */
93 public boolean validate(String path) {
94 boolean valid = false;
95 if (fTrace != null) {
96 valid = standardValidate(path);
97 }
98 return valid;
99 }
100
101 /**
102 * Validate a trace against this trace type with confidence level
103 *
104 * @param path
105 * the trace to validate
106 * @return the confidence level (0 is lowest) or -1 if validation fails
107 * @since 3.0
108 */
109 public int validateWithConfidence(String path) {
110 int result = -1;
111 if (fTrace != null) {
112 IStatus status = fTrace.validate(null, path);
113 if (status.isOK()) {
114 result = 0;
115 if (status instanceof TraceValidationStatus) {
116 result = ((TraceValidationStatus) status).getConfidence();
117 }
118 }
119 }
120 return result;
121 }
122
123 /**
124 * Get an object of the trace type
125 * @return an object of the trace type
126 * @since 2.1
127 */
128 public ITmfTrace getTrace() {
129 return fTrace;
130 }
131
132 private boolean standardValidate(String path) {
133 final boolean valid = fTrace.validate(null, path).isOK();
134 return valid;
135 }
136
137 /**
138 * Get the class associated with this trace type
139 *
140 * @return The trace class
141 * @since 3.0
142 */
143 public Class<? extends ITmfTrace> getTraceClass() {
144 return fTrace.getClass();
145 }
146
147 /**
148 * Returns whether trace type is for a directory trace or a single file trace
149 * @return <code>true</code> if trace type is for a directory trace else <code>false</code>
150 */
151 public boolean isDirectoryTraceType() {
152 return fIsDirectory;
153 }
154
155
156 @Override
157 public String toString() {
158 return fName;
159 }
160
161 }
This page took 0.034724 seconds and 5 git commands to generate.