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