Commit | Line | Data |
---|---|---|
d04ec5a7 MK |
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 | ||
76fccfb0 MK |
99 | /** |
100 | * Get an object of the trace type | |
101 | * @return an object of the trace type | |
102 | * @since 2.1 | |
103 | */ | |
0a19e2d1 | 104 | public ITmfTrace getTrace() { |
76fccfb0 MK |
105 | return fTrace; |
106 | } | |
107 | ||
d04ec5a7 MK |
108 | private boolean standardValidate(String path) { |
109 | final boolean valid = fTrace.validate(null, path).equals(Status.OK_STATUS); | |
110 | return valid; | |
111 | } | |
112 | ||
113 | private static boolean customValidate(String path) { | |
114 | File f = new File(path); | |
115 | return f.exists() && f.isFile(); | |
116 | } | |
117 | ||
118 | @Override | |
119 | public String toString() { | |
120 | return fName; | |
121 | } | |
122 | ||
123 | } |