01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.junit.viewer.server;
17:
18: import com.google.gwt.junit.viewer.client.Trial;
19:
20: import org.w3c.dom.Element;
21:
22: import java.util.Iterator;
23: import java.util.List;
24: import java.util.Map;
25:
26: /**
27: * Hydrates a benchmark Trial from an XML Element.
28: *
29: */
30: class TrialXml {
31:
32: public static Trial fromXml(Element element) {
33: Trial trial = new Trial();
34:
35: String timing = element.getAttribute("timing");
36:
37: if (timing != null) {
38: trial.setRunTimeMillis(Double.parseDouble(timing));
39: }
40:
41: Element exception = ReportXml.getElementChild(element,
42: "exception");
43: if (exception != null) {
44: trial.setException(ReportXml.getText(exception));
45: }
46:
47: List elements = ReportXml.getElementChildren(element,
48: "variable");
49:
50: Map variables = trial.getVariables();
51:
52: for (Iterator it = elements.iterator(); it.hasNext();) {
53: Element e = (Element) it.next();
54: String name = e.getAttribute("name");
55: String value = e.getAttribute("value");
56: variables.put(name, value);
57: }
58:
59: return trial;
60: }
61: }
|