a43a451dd02a5154a1dd795c1f06e2b71afa3afb
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfStateSystemAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.event.aspect;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
21 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
22 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
23 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
24 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
25
26 /**
27 * Aspect representing a query in a given state system, at the timestamp of the
28 * event.
29 *
30 * This is a good example of how aspects can be "indirect" with regards to their
31 * events.
32 *
33 * @author Alexandre Montplaisir
34 */
35 public class TmfStateSystemAspect implements ITmfEventAspect {
36
37 private final @Nullable String fName;
38 private final ITmfStateSystem fSS;
39 private final int fAttribute;
40
41 /**
42 * Constructor
43 *
44 * @param name
45 * The name of this aspect. You can use 'null' to use the
46 * default name, which is the (base) name of the attribute.
47 * @param ss
48 * The state system in which we want to query
49 * @param attributeQuark
50 * The quark of the attribute in the state system to look for
51 */
52 public TmfStateSystemAspect(@Nullable String name, ITmfStateSystem ss, int attributeQuark) {
53 fName = name;
54 fSS = ss;
55 fAttribute = attributeQuark;
56 }
57
58 @Override
59 public String getName() {
60 String name = fName;
61 if (name != null) {
62 return name;
63 }
64
65 name = fSS.getFullAttributePath(fAttribute);
66 return name;
67 }
68
69 @Override
70 public @NonNull String getHelpText() {
71 return Messages.getMessage(NLS.bind(Messages.AspectHelpText_Statesystem,
72 fSS.getSSID(), fSS.getFullAttributePath(fAttribute)));
73 }
74
75 @Override
76 public @Nullable String resolve(ITmfEvent event) {
77 try {
78 ITmfStateValue value = fSS.querySingleState(event.getTimestamp().getValue(), fAttribute).getStateValue();
79 return checkNotNull(value.toString());
80 } catch (AttributeNotFoundException | StateSystemDisposedException e) {
81 return null;
82 }
83 }
84 }
This page took 0.042141 seconds and 4 git commands to generate.