Tmf: Batch Trace Import
[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 java.io.File;
16
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
19
20 /**
21 * TraceTypeHelper, a helper that can link a few names to a configuation element
22 * and a trace
23 *
24 * @author Matthew Khouzam
25 * @since 2.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
34 /**
35 * Constructor for a trace type helper. It is a link between a canonical
36 * (hard to read) name, a category name, a name and a trace object. It is
37 * used for trace validation.
38 *
39 * @param canonicalName
40 * The "path" of the tracetype
41 * @param categoryName
42 * the category of the trace type
43 * @param name
44 * the name of the trace
45 * @param trace
46 * an object of the trace type
47 */
48 public TraceTypeHelper(String canonicalName, String categoryName, String name, ITmfTrace trace) {
49 fName = name;
50 fCategoryName = categoryName;
51 fCanonicalName = canonicalName;
52 fTrace = trace;
53 }
54
55 /**
56 * Get the name
57 *
58 * @return the name
59 */
60 public String getName() {
61 return fName;
62 }
63
64 /**
65 * Get the category name
66 *
67 * @return the category name
68 */
69 public String getCategoryName() {
70 return fCategoryName;
71 }
72
73 /**
74 * Get the canonical name
75 *
76 * @return the canonical Name
77 */
78 public String getCanonicalName() {
79 return fCanonicalName;
80 }
81
82 /**
83 * Is the trace of this type?
84 *
85 * @param path
86 * the trace to validate
87 * @return whether it passes the validation
88 */
89 public boolean validate(String path) {
90 boolean valid = false;
91 if (fTrace != null) {
92 valid = standardValidate(path);
93 } else if (fCategoryName.equals(TmfTraceType.CUSTOM_TXT_CATEGORY) || fCategoryName.equals(TmfTraceType.CUSTOM_XML_CATEGORY)) {
94 valid = customValidate(path);
95 }
96 return valid;
97 }
98
99 private boolean standardValidate(String path) {
100 final boolean valid = fTrace.validate(null, path).equals(Status.OK_STATUS);
101 return valid;
102 }
103
104 private static boolean customValidate(String path) {
105 File f = new File(path);
106 return f.exists() && f.isFile();
107 }
108
109 @Override
110 public String toString() {
111 return fName;
112 }
113
114 }
This page took 0.032772 seconds and 5 git commands to generate.