GroupNode.java

    1/*******************************************************************************
    2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
    3 * All rights reserved. This program and the accompanying materials
    4 * are made available under the terms of the Eclipse Public License v1.0
    5 * which accompanies this distribution, and is available at
    6 * http://www.eclipse.org/legal/epl-v10.html
    7 *
    8 * Contributors:
    9 *    Brock Janiczak -initial API and implementation
   10 *    
   11 * $Id: $
   12 *******************************************************************************/
   13package org.jacoco.report.xml;
   14
   15import java.io.IOException;
   16
   17import org.jacoco.core.analysis.ICoverageNode;
   18import org.jacoco.core.analysis.ICoverageNode.ElementType;
   19import org.jacoco.report.IReportVisitor;
   20
   21/**
   22 * Wrapper for an {@link XMLElement} that contains 'groups' of coverage data.
   23 * Group Nodes can represent either be Bundle or Group coverage data
   24 * 
   25 * @author Brock Janiczak
   26 * @version $Revision: $
   27 */
   28public class GroupNode extends NodeWithCoverage {
   29
   30    /**
   31     * Creates a new top level Group coverage element for the supplied session
   32     * coverage node
   33     * 
   34     * @param file
   35     *            Root element to attach to
   36     * @param coverageNode
   37     *            Coverage node
   38     * @throws IOException
   39     *             IO Error creating the element
   40     */
   41    public GroupNode(final XMLReportFile file, final ICoverageNode coverageNode)
   42            throws IOException {
   43        this((XMLElement) file, coverageNode);
   44    }
   45
   46    /**
   47     * Creates a new Group coverage element under an existing group element for
   48     * the supplied coverage node
   49     * 
   50     * @param parent
   51     *            Element to attach to
   52     * @param node
   53     *            Coverage node
   54     * @throws IOException
   55     *             IO Error creating the element
   56     */
   57    public GroupNode(final GroupNode parent, final ICoverageNode node)
   58            throws IOException {
   59        this((XMLElement) parent, node);
   60    }
   61
   62    private GroupNode(final XMLElement parent, final ICoverageNode node)
   63            throws IOException {
   64        super(parent, "group", node);
   65    }
   66
   67    public IReportVisitor visitChild(final ICoverageNode node)
   68            throws IOException {
   69
   70        if (node.getElementType() == ElementType.GROUP
   71                || node.getElementType() == ElementType.BUNDLE) {
   72            return new GroupNode(this, node);
   73        }
   74
   75        return new PackageNode(this, node);
   76    }
   77
   78}