1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
20 import org
.w3c
.dom
.Element
;
21 import org
.w3c
.dom
.Node
;
22 import org
.w3c
.dom
.NodeList
;
25 * Class to store and interpret the header information of XML-defined components
27 * @author Geneviève Bastien
29 public class XmlHeadInfo
{
31 private final Node fHeadInfo
;
37 * The XML node corresponding to this header
39 public XmlHeadInfo(Node item
) {
44 * Get a list of child elements with the requested name
47 * The name of the nodes to get
48 * @return List of child elements
50 public List
<Element
> getElements(String nodeName
) {
51 List
<Element
> list
= new ArrayList
<>();
52 NodeList nodes
= fHeadInfo
.getChildNodes();
53 for (int i
= 0; i
< nodes
.getLength(); i
++) {
54 Node node
= nodes
.item(i
);
55 if (node
instanceof Element
) {
56 Element element
= (Element
) node
;
57 if (element
.getNodeName().equals(nodeName
)) {
66 * Check whether, if this header information has trace types defined, this
67 * component applies to a given trace type.
70 * The trace type to check for
71 * @return True if there is no trace type information in header or if the
74 public boolean checkTraceType(Class
<?
extends ITmfTrace
> traceClass
) {
76 * By default this returns true, child implementation who have access to
77 * trace types will override this
79 * TODO: actually check the trace type here when trace types are moved
80 * to o.e.l.tmf.core instead of o.e.l.tmf.ui
86 * Get the name of this component from the header information
88 * @return The name of the component
90 public String
getName() {
91 List
<Element
> elements
= getElements(TmfXmlStrings
.LABEL
);
92 if (elements
.isEmpty()) {
96 Element element
= elements
.get(0);
97 return element
.getAttribute(TmfXmlStrings
.VALUE
);
This page took 0.032769 seconds and 5 git commands to generate.