From b1ebf44e721ba947dbe984d84b403eede99ec9b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Mon, 10 Mar 2014 15:38:44 -0400 Subject: [PATCH] TMF: Add an XML model factory and classes for read-only state system components MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Factory for XML model element used in a read-only context. The state attributes will not be added to the state system. Change-Id: Ibfb5a35ecbc723ecc12c47c6461a389d5290e918 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/23160 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir --- .../META-INF/MANIFEST.MF | 1 + .../readonly/TmfXmlReadOnlyModelFactory.java | 88 +++++++++++++++++++ .../TmfXmlReadOnlyStateAttribute.java | 55 ++++++++++++ .../readonly/TmfXmlReadOnlyStateValue.java | 69 +++++++++++++++ ....java => TmfXmlReadWriteModelFactory.java} | 12 +-- ...ava => TmfXmlReadWriteStateAttribute.java} | 4 +- ...te.java => TmfXmlReadWriteStateValue.java} | 8 +- .../core/stateprovider/XmlStateProvider.java | 4 +- 8 files changed, 227 insertions(+), 14 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java create mode 100644 org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java create mode 100644 org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java rename org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/{TmfXmlModelFactoryReadWrite.java => TmfXmlReadWriteModelFactory.java} (88%) rename org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/{TmfXmlStateAttributeReadWrite.java => TmfXmlReadWriteStateAttribute.java} (91%) rename org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/{TmfXmlStateValueReadWrite.java => TmfXmlReadWriteStateValue.java} (98%) diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF index 6b572c9866..28fcef1d44 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF @@ -12,6 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.linuxtools.tmf.core Export-Package: org.eclipse.linuxtools.internal.tmf.analysis.xml.core;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.core.tests", org.eclipse.linuxtools.tmf.analysis.xml.core.model, + org.eclipse.linuxtools.tmf.analysis.xml.core.model.readonly, org.eclipse.linuxtools.tmf.analysis.xml.core.model.readwrite, org.eclipse.linuxtools.tmf.analysis.xml.core.module, org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java new file mode 100644 index 0000000000..df6be51284 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.core.model.readonly; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.ITmfXmlModelFactory; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.ITmfXmlStateAttribute; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.ITmfXmlStateValue; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlCondition; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlEventHandler; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlLocation; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlStateChange; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory; +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlStateSystemContainer; +import org.w3c.dom.Element; + +/** + * Concrete factory for XML model elements in read only mode + * + * @author Geneviève Bastien + */ +public class TmfXmlReadOnlyModelFactory implements ITmfXmlModelFactory { + + private static ITmfXmlModelFactory fInstance = null; + + /** + * Get the instance of this model creator + * + * @return The {@link TmfXmlReadWriteModelFactory} instance + */ + @NonNull + public static synchronized ITmfXmlModelFactory getInstance() { + ITmfXmlModelFactory instance = fInstance; + if (instance == null) { + instance = new TmfXmlReadOnlyModelFactory(); + fInstance = instance; + } + return instance; + } + + @Override + public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) { + return new TmfXmlReadOnlyStateAttribute(this, attribute, container); + } + + @Override + public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List attributes) { + return new TmfXmlReadOnlyStateValue(this, node, container, attributes); + } + + @Override + public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) { + return new TmfXmlReadOnlyStateValue(this, node, container, eventField); + } + + @Override + public TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container) { + return new TmfXmlCondition(this, node, container); + } + + @Override + public TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container) { + return new TmfXmlEventHandler(this, node, container); + } + + @Override + public TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container) { + return new TmfXmlStateChange(this, node, container); + } + + @Override + public TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container) { + return new TmfXmlLocation(this, node, container); + } + +} diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java new file mode 100644 index 0000000000..d06bbeaad2 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.core.model.readonly; + +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlStateAttribute; +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlStateSystemContainer; +import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; +import org.w3c.dom.Element; + +/** + * Implements a state attribute in a read only mode. See + * {@link TmfXmlStateAttribute} for the syntax of this attribute. + * + * In read-only mode, attributes that are requested but do not exist in the + * state system will not be added. + * + * @author Geneviève Bastien + */ +public class TmfXmlReadOnlyStateAttribute extends TmfXmlStateAttribute { + + /** + * Constructor + * + * @param modelFactory + * The factory used to create XML model elements + * @param attribute + * The XML element corresponding to this attribute + * @param container + * The state system container this state value belongs to + */ + public TmfXmlReadOnlyStateAttribute(TmfXmlReadOnlyModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) { + super(modelFactory, attribute, container); + } + + @Override + protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException { + return getStateSystem().getQuarkAbsolute(path); + } + + @Override + protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException { + return getStateSystem().getQuarkRelative(startNodeQuark, path); + } + +} diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java new file mode 100644 index 0000000000..99f3f8d041 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.core.model.readonly; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.ITmfXmlStateAttribute; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlStateValue; +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlStateSystemContainer; +import org.w3c.dom.Element; + +/** + * Implements a state value is a read only mode. See {@link TmfXmlStateValue} + * for the syntax of the state value. + * + * In read mode, a state value will typically be used to find a path to a value, + * so the value is known and there is a path of attributes that should lead to + * it. + * + * @author Geneviève Bastien + */ +public class TmfXmlReadOnlyStateValue extends TmfXmlStateValue { + + /** + * Constructor where the path to the value is a list of state attributes + * + * @param modelFactory + * The factory used to create XML model elements + * @param node + * The state value XML element + * @param container + * The state system container this state value belongs to + * @param attributes + * The attributes representing the path to this value + */ + public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node, + IXmlStateSystemContainer container, List attributes) { + super(modelFactory, node, container, attributes, null); + } + + /** + * Constructor where the path to the value is an event field + * + * @param modelFactory + * The factory used to create XML model elements + * @param node + * The state value XML element + * @param container + * The state system container this state value belongs to + * @param eventField + * The event field where to get the value + */ + public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node, + IXmlStateSystemContainer container, String eventField) { + super(modelFactory, node, container, Collections.EMPTY_LIST, eventField); + } + +} diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlModelFactoryReadWrite.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java similarity index 88% rename from org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlModelFactoryReadWrite.java rename to org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java index fe815798d3..1380bf08f2 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlModelFactoryReadWrite.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java @@ -30,20 +30,20 @@ import org.w3c.dom.Element; * * @author Geneviève Bastien */ -public class TmfXmlModelFactoryReadWrite implements ITmfXmlModelFactory { +public class TmfXmlReadWriteModelFactory implements ITmfXmlModelFactory { private static ITmfXmlModelFactory fInstance = null; /** * Get the instance of this model creator * - * @return The {@link TmfXmlModelFactoryReadWrite} instance + * @return The {@link TmfXmlReadWriteModelFactory} instance */ @NonNull public static synchronized ITmfXmlModelFactory getInstance() { ITmfXmlModelFactory instance = fInstance; if (instance == null) { - instance = new TmfXmlModelFactoryReadWrite(); + instance = new TmfXmlReadWriteModelFactory(); fInstance = instance; } return instance; @@ -51,17 +51,17 @@ public class TmfXmlModelFactoryReadWrite implements ITmfXmlModelFactory { @Override public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) { - return new TmfXmlStateAttributeReadWrite(this, attribute, container); + return new TmfXmlReadWriteStateAttribute(this, attribute, container); } @Override public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List attributes) { - return new TmfXmlStateValueReadWrite(this, node, container, attributes); + return new TmfXmlReadWriteStateValue(this, node, container, attributes); } @Override public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) { - return new TmfXmlStateValueReadWrite(this, node, container, eventField); + return new TmfXmlReadWriteStateValue(this, node, container, eventField); } @Override diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateAttributeReadWrite.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java similarity index 91% rename from org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateAttributeReadWrite.java rename to org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java index 86db85c119..33b383709e 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateAttributeReadWrite.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java @@ -27,7 +27,7 @@ import org.w3c.dom.Element; * * @author Geneviève Bastien */ -public class TmfXmlStateAttributeReadWrite extends TmfXmlStateAttribute { +public class TmfXmlReadWriteStateAttribute extends TmfXmlStateAttribute { /** * Constructor @@ -39,7 +39,7 @@ public class TmfXmlStateAttributeReadWrite extends TmfXmlStateAttribute { * @param container * The state system container this state value belongs to */ - public TmfXmlStateAttributeReadWrite(TmfXmlModelFactoryReadWrite modelFactory, Element attribute, IXmlStateSystemContainer container) { + public TmfXmlReadWriteStateAttribute(TmfXmlReadWriteModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) { super(modelFactory, attribute, container); } diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateValueReadWrite.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java similarity index 98% rename from org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateValueReadWrite.java rename to org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java index abe23b12da..1431122d54 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlStateValueReadWrite.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java @@ -41,7 +41,7 @@ import org.w3c.dom.Element; * * @author Geneviève Bastien */ -public class TmfXmlStateValueReadWrite extends TmfXmlStateValue { +public class TmfXmlReadWriteStateValue extends TmfXmlStateValue { /** * Constructor where the path to the value is a list of state attributes @@ -55,7 +55,7 @@ public class TmfXmlStateValueReadWrite extends TmfXmlStateValue { * @param attributes * The attributes representing the path to this value */ - public TmfXmlStateValueReadWrite(TmfXmlModelFactoryReadWrite modelFactory, Element node, IXmlStateSystemContainer container, List attributes) { + public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List attributes) { this(modelFactory, node, container, attributes, null); } @@ -71,11 +71,11 @@ public class TmfXmlStateValueReadWrite extends TmfXmlStateValue { * @param eventField * The event field where to get the value */ - public TmfXmlStateValueReadWrite(TmfXmlModelFactoryReadWrite modelFactory, Element node, IXmlStateSystemContainer container, String eventField) { + public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, String eventField) { this(modelFactory, node, container, new ArrayList(), eventField); } - private TmfXmlStateValueReadWrite(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List attributes, String eventField) { + private TmfXmlReadWriteStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List attributes, String eventField) { super(modelFactory, node, container, attributes, eventField); } diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java index bb98befdc7..2d4153443d 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.tmf.analysis.xml.core.model.ITmfXmlModelFactory; import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlEventHandler; import org.eclipse.linuxtools.tmf.analysis.xml.core.model.TmfXmlLocation; -import org.eclipse.linuxtools.tmf.analysis.xml.core.model.readwrite.TmfXmlModelFactoryReadWrite; +import org.eclipse.linuxtools.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory; import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlStateSystemContainer; import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; @@ -78,7 +78,7 @@ public class XmlStateProvider extends AbstractTmfStateProvider implements IXmlSt return; } - ITmfXmlModelFactory modelFactory = TmfXmlModelFactoryReadWrite.getInstance(); + ITmfXmlModelFactory modelFactory = TmfXmlReadWriteModelFactory.getInstance(); /* parser for defined Values */ NodeList definedStateNodes = doc.getElementsByTagName(TmfXmlStrings.DEFINED_VALUE); for (int i = 0; i < definedStateNodes.getLength(); i++) { -- 2.34.1