buildframework/helium/sf/java/internaldata/src/com/nokia/helium/internaldata/ant/listener/XMLRenderer.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
* All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
* This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
* which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
* Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
* Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
* Description: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
*/
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.internaldata.ant.listener;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    20
import java.io.ByteArrayOutputStream;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
import java.io.IOException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import java.io.UnsupportedEncodingException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import java.util.Enumeration;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    24
import java.util.Hashtable;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import java.util.Iterator;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import java.util.Vector;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    28
import org.apache.tools.ant.BuildEvent;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import org.dom4j.Document;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import org.dom4j.DocumentHelper;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import org.dom4j.Element;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    32
import org.dom4j.io.OutputFormat;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import org.dom4j.io.XMLWriter;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
 * This xml render object does the following - 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
 * Generates target only for TargetNode type of node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
 * Creates the targets section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
 * Generates task only for TargetNode type of node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
 * Creates the task section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
 * Creates execution tree recursively, visiting the DataNodes.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
 * Creates the execution tree section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
 * Creates the property section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
 * Renders the build node into XML string. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
public class XMLRenderer {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    // Dump of properties
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    private Hashtable<String, String> properties;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    // the toplevel node.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    private BuildNode root;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    // Helium content database. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    private Document database;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    // Deps hashes: helper to remove duplicates.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    private Vector<String> targetList = new Vector<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    private Vector<String> assertList = new Vector<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    public XMLRenderer(BuildNode root, Document database, Hashtable<String, String> properties, BuildEvent event) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        this.root = root; 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        this.database = database;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        this.properties = properties;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
     * Generating target only for TargetNode type of node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
     * @param node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
     * @param targets
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    protected void createTarget(DataNode node, Element targets) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        if (node instanceof TargetNode) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
            TargetNode targetNode = (TargetNode)node;            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
            if (!targetList.contains(targetNode.getName() + targetNode.getFilename())) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
                targetList.add(targetNode.getName() + targetNode.getFilename());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
                Element target = targets.addElement("target");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
                target.addAttribute("id", "target@" + targetList.indexOf(targetNode.getName() + targetNode.getFilename()));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
                target.addAttribute("name", targetNode.getName());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
                target.addAttribute("file", targetNode.getFilename());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
                target.addAttribute("line", "" + targetNode.getLine());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        for (Iterator<DataNode> i = node.iterator() ; i.hasNext() ; ) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
            createTarget(i.next(), targets);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
     * Creating the targets section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
     * @param statistics
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
    protected void createTargets(Element statistics) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        Element targets = statistics.addElement("targets");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        if (root != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
            createTarget(root, targets);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
     * Creating the assert section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
     * @param statistics
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    protected void createAsserts(Element statistics) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        Element asserts = statistics.addElement("asserts");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        if (root != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
            createAssert(root, asserts);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
     * Generating assert only for TargetNode type of node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
     * @param node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
     * @param targets
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
    protected void createAssert(DataNode node, Element targets) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        if (node instanceof AssertNode) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
            AssertNode assertNode = (AssertNode)node;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
            if (assertNode.getAssertName() != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
                assertList.add(assertNode.getAssertName());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
                Element target = targets.addElement("assert");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
                target.addAttribute("id", "assert@" + assertList.indexOf(assertNode.getAssertName()));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
                target.addAttribute("name", assertNode.getAssertName());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
                target.addAttribute("file", assertNode.getFilename());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
                target.addAttribute("line", "" + assertNode.getLine());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
                target.addAttribute("message", "" + assertNode.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        for (Iterator<DataNode> i = node.iterator() ; i.hasNext() ; ) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
            createAssert(i.next(), targets);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
     * Creating execution tree recursively, visiting the DataNodes.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
     * @param node
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
     * @param tree
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
    protected void createTree(DataNode node, Element tree) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        Element elt = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        if (node instanceof BuildNode) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
            BuildNode buildNode = (BuildNode)node;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
            elt = tree.addElement("build");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
            elt.addAttribute("name", buildNode.getName());            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
            elt.addAttribute("startTime", "" + buildNode.getStartTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
            elt.addAttribute("endTime", "" + buildNode.getEndTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
            elt.addAttribute("status", buildNode.getSuccessful() ? "successful" : "failed");            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
            elt.addAttribute("thread", "" + buildNode.getThreadId());            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        } else if (node instanceof TargetNode) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
            TargetNode targetNode = (TargetNode)node;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
            elt = tree.addElement("targetRef");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
            elt.addAttribute("reference", "target@" + targetList.indexOf(targetNode.getName() + targetNode.getFilename()));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
            elt.addAttribute("startTime", "" + targetNode.getStartTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
            elt.addAttribute("endTime", "" + targetNode.getEndTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
            elt.addAttribute("thread", "" + targetNode.getThreadId());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
            elt.addAttribute("startUsedHeap", "" + targetNode.getStartUsedHeap());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
            elt.addAttribute("startCommittedHeap", "" + targetNode.getStartCommittedHeap());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
            elt.addAttribute("endUsedHeap", "" + targetNode.getEndUsedHeap());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
            elt.addAttribute("endCommittedHeap", "" + targetNode.getEndCommittedHeap());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
        } else if (node instanceof AssertNode) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
            AssertNode assertNode = (AssertNode)node;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            if (assertNode.getAssertName() != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
                elt = tree.addElement("assertRef");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
                elt.addAttribute("reference", "assert@" + assertList.indexOf(assertNode.getAssertName()));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                elt.addAttribute("startTime", "" + assertNode.getStartTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
                elt.addAttribute("endTime", "" + assertNode.getEndTime().getTime());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
                elt.addAttribute("thread", "" + assertNode.getThreadId());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
        if (elt != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
            for (Iterator<DataNode> i = node.iterator() ; i.hasNext() ; ) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                createTree(i.next(), elt);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
     * Creating the execution tree section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
     * @param statistics
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
    protected void createExecutionTree(Element statistics) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
        Element executionTree = statistics.addElement("executionTree");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
        if (root != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
            createTree(root, executionTree);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
     * Creating the property section.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
     * @param statistics
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    protected void createProperties(Element statistics) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
        Element propertiesElt = statistics.addElement("properties");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
        if (properties != null) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   193
            for (Enumeration<String> propertyEnum = properties.keys(); propertyEnum.hasMoreElements() ; ) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   194
                String key = propertyEnum.nextElement();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
                Element propertyElt = propertiesElt.addElement("property");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
                propertyElt.addAttribute("name", key);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
                propertyElt.addAttribute("value", properties.get(key));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
    protected void insertDatabase(Element statistics) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        if (database != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
            Element databaseElt = statistics.addElement("database");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
            databaseElt.add(database.getRootElement().detach());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
     * Rendering the build node into XML string. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
    public String toString() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        // Creating the XML document
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        Document document = DocumentHelper.createDocument();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
        Element statistics = document.addElement( "statistics" );
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        statistics.addAttribute("version", "1.1");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
        // Creating the document content.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        insertDatabase(statistics);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        createTargets(statistics);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        createAsserts(statistics);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        createExecutionTree(statistics);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
        createProperties(statistics);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
            ByteArrayOutputStream output = new ByteArrayOutputStream(); 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
            XMLWriter out = new XMLWriter(output, OutputFormat.createPrettyPrint());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
            out.write(document);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
            return output.toString();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        } catch (UnsupportedEncodingException exc) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
            return document.asXML();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        } catch (IOException exc) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
            return document.asXML();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
}