Search in sources :

Example 1 with ITmfFilterWithValue

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue in project tracecompass by tracecompass.

the class TmfFilterContentHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    ITmfFilterTreeNode node = null;
    if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
        node = new TmfFilterRootNode();
    } else if (localName.equals(TmfFilterNode.NODE_NAME)) {
        node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
        ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
        TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
        if (helper != null) {
            ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
        }
        ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
        node = new TmfFilterAndNode(null);
    } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
        node = new TmfFilterOrNode(null);
    } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
        node = new TmfFilterContainsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterContainsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
        node = new TmfFilterEqualsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterEqualsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
        node = new TmfFilterMatchesNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
    } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
        node = new TmfFilterCompareNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
        if (value != null) {
            ((TmfFilterCompareNode) node).setType(Type.valueOf(value));
        }
        value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
        if (value != null) {
            if (value.equals(Integer.toString(-1))) {
                ((TmfFilterCompareNode) node).setResult(-1);
            } else if (value.equals(Integer.toString(1))) {
                ((TmfFilterCompareNode) node).setResult(1);
            } else {
                ((TmfFilterCompareNode) node).setResult(0);
            }
        }
    // Backward compatibility with event type filter node
    } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String label = atts.getValue(NAME_ATTR);
        if (label != null) {
            // Backward compatibility with renamed LTTng Kernel Trace
            if (label.equals(LTTNG_KERNEL_TRACE)) {
                label = LINUX_KERNEL_TRACE;
            }
            String traceTypeId = TmfTraceType.getTraceTypeId(label);
            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
            if (helper == null) {
                // Backward compatibility with category-less custom trace types
                for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
                    if (h.getName().equals(label)) {
                        label = h.getLabel();
                        helper = h;
                        break;
                    }
                }
            }
            if (helper != null) {
                ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
                ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
            }
            ((TmfFilterTraceTypeNode) node).setName(label);
        }
    }
    String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
    if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
        ((ITmfFilterWithNot) node).setNot(true);
    }
    if (node instanceof ITmfFilterWithValue) {
        ((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
    }
    fFilterTreeStack.addFirst(node);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) ITmfFilterWithValue(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAspectNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)

Example 2 with ITmfFilterWithValue

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue in project tracecompass by tracecompass.

the class TmfFilterXMLWriter method buildXMLTree.

/**
 * The Tree to XML parser
 *
 * @param document The XML document
 * @param treenode The node to write
 * @param parentElement The XML element of the parent
 */
public static void buildXMLTree(final Document document, final ITmfFilterTreeNode treenode, Element parentElement) {
    Element element = document.createElement(treenode.getNodeName());
    if (treenode instanceof ITmfFilterWithNot && ((ITmfFilterWithNot) treenode).isNot()) {
        element.setAttribute(ITmfFilterWithNot.NOT_ATTRIBUTE, Boolean.TRUE.toString());
    }
    if (treenode instanceof ITmfFilterWithValue) {
        ITmfFilterWithValue node = (ITmfFilterWithValue) treenode;
        element.setAttribute(ITmfFilterWithValue.VALUE_ATTRIBUTE, node.getValue());
    }
    if (treenode instanceof TmfFilterNode) {
        TmfFilterNode node = (TmfFilterNode) treenode;
        element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName());
    } else if (treenode instanceof TmfFilterTraceTypeNode) {
        TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) treenode;
        element.setAttribute(TmfFilterTraceTypeNode.TYPE_ATTR, node.getTraceTypeId());
        element.setAttribute(TmfFilterTraceTypeNode.NAME_ATTR, node.getName());
    } else if (treenode instanceof TmfFilterContainsNode) {
        TmfFilterContainsNode node = (TmfFilterContainsNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterContainsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));
    } else if (treenode instanceof TmfFilterEqualsNode) {
        TmfFilterEqualsNode node = (TmfFilterEqualsNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterEqualsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));
    } else if (treenode instanceof TmfFilterMatchesNode) {
        TmfFilterMatchesNode node = (TmfFilterMatchesNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterMatchesNode.REGEX_ATTR, node.getRegex());
    } else if (treenode instanceof TmfFilterCompareNode) {
        TmfFilterCompareNode node = (TmfFilterCompareNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterCompareNode.RESULT_ATTR, Integer.toString(node.getResult()));
        element.setAttribute(TmfFilterCompareNode.TYPE_ATTR, node.getType().toString());
    }
    parentElement.appendChild(element);
    for (int i = 0; i < treenode.getChildrenCount(); i++) {
        buildXMLTree(document, treenode.getChild(i), element);
    }
}
Also used : TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) Element(org.w3c.dom.Element) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) ITmfFilterWithValue(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Aggregations

ITmfFilterWithNot (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)2 ITmfFilterWithValue (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue)2 TmfFilterCompareNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)2 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)2 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)2 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)2 TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)2 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)2 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)1 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)1 TmfFilterAspectNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode)1 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)1 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)1 TraceTypeHelper (org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper)1 Element (org.w3c.dom.Element)1