Skip to main content
summaryrefslogtreecommitdiffstats
blob: 24b8a4aef2a51332c249dbe34f56042a9a4bd05b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.core.log.record;

import java.util.ArrayList;
import java.util.List;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable;
import org.eclipse.osee.framework.jdk.core.persistence.XmlizableStream;
import org.eclipse.osee.ote.core.ReturnFormatter;
import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironmentAccessor;
import org.eclipse.osee.ote.core.log.TestLevel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class TraceRecordEnd extends TestRecord implements Xmlizable {

   private static final long serialVersionUID = 8567378567805515775L;
   private final ReturnFormatter returnFormatter;
   private final ArrayList<Xmlizable> additionalElements;
   private final ArrayList<XmlizableStream> additionalStreamElements;

   private static final String additionalString = "AdditionalInfo";

   public TraceRecordEnd(ITestEnvironmentAccessor source, ReturnFormatter returnFormatter) {
      super(source, TestLevel.TRACE, "", true);
      this.returnFormatter = returnFormatter;
      this.additionalElements = new ArrayList<>();
      this.additionalStreamElements = new ArrayList<>();
   }

   public void addAdditionalElement(Xmlizable object) {
      if (object != null) {
         additionalElements.add(object);
      }
   }

   public void addAdditionalElement(XmlizableStream object) {
      if (object != null) {
         additionalStreamElements.add(object);
      }
   }

   /**
    * Converts element to XML formating.
    * 
    * @return Element XML formated element.
    */
   @Override
   public Element toXml(Document doc) {
      Element trElement = doc.createElement("TraceEnd");
      trElement.appendChild(returnFormatter.toXml(doc));
      if (!additionalElements.isEmpty()) {
         Element additional = doc.createElement(additionalString);
         trElement.appendChild(additional);
         for (Xmlizable object : additionalElements) {
            additional.appendChild(object.toXml(doc));
         }
      }
      return trElement;
   }

   @Override
   public void toXml(XMLStreamWriter writer) throws XMLStreamException {
      writer.writeStartElement("TraceEnd");
      returnFormatter.toXml(writer);
      if (!additionalElements.isEmpty()) {
         writer.writeStartElement(additionalString);
         for (XmlizableStream object : additionalStreamElements) {
            object.toXml(writer);
         }
      }
      writer.writeEndElement();
   }
   
   @JsonProperty
   public ReturnFormatter getReturnValue() {
    return returnFormatter;
}

@Override
@JsonIgnore
   public List<String> getLocation() {
	   return null;
   }
   
   @JsonProperty
   public List<?> getAdditionalInfo() {
       return nonEmptyList(additionalStreamElements);
   }
}

Back to the top