| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014 École Polytechnique de Montréal |
| 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 | * Geneviève Bastien - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite; |
| 14 | |
| 15 | import org.eclipse.jdt.annotation.Nullable; |
| 16 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
| 17 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
| 18 | import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateAttribute; |
| 19 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer; |
| 20 | import org.w3c.dom.Element; |
| 21 | |
| 22 | /** |
| 23 | * Implements a state attribute in a read write mode. See |
| 24 | * {@link TmfXmlStateAttribute} for the syntax of this attribute. |
| 25 | * |
| 26 | * In read-write mode, attributes that are requested but do not exist are added |
| 27 | * to the state system. |
| 28 | * |
| 29 | * @author Geneviève Bastien |
| 30 | */ |
| 31 | public class TmfXmlReadWriteStateAttribute extends TmfXmlStateAttribute { |
| 32 | |
| 33 | /** |
| 34 | * Constructor |
| 35 | * |
| 36 | * @param modelFactory |
| 37 | * The factory used to create XML model elements |
| 38 | * @param attribute |
| 39 | * The XML element corresponding to this attribute |
| 40 | * @param container |
| 41 | * The state system container this state value belongs to |
| 42 | */ |
| 43 | public TmfXmlReadWriteStateAttribute(TmfXmlReadWriteModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) { |
| 44 | super(modelFactory, attribute, container); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected @Nullable ITmfStateSystemBuilder getStateSystem() { |
| 49 | return (ITmfStateSystemBuilder) super.getStateSystem(); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException { |
| 54 | ITmfStateSystemBuilder ss = getStateSystem(); |
| 55 | if (ss == null) { |
| 56 | throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$ |
| 57 | } |
| 58 | return ss.getQuarkAbsoluteAndAdd(path); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException { |
| 63 | ITmfStateSystemBuilder ss = getStateSystem(); |
| 64 | if (ss == null) { |
| 65 | throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$ |
| 66 | } |
| 67 | return ss.getQuarkRelativeAndAdd(startNodeQuark, path); |
| 68 | } |
| 69 | |
| 70 | } |