KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > junit > viewer > server > TrialXml


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * Hydrates a benchmark Trial from an XML Element.
28  *
29  */

30 class TrialXml {
31
32   public static Trial fromXml(Element JavaDoc element) {
33     Trial trial = new Trial();
34
35     String JavaDoc timing = element.getAttribute("timing");
36
37     if (timing != null) {
38       trial.setRunTimeMillis(Double.parseDouble(timing));
39     }
40
41     Element JavaDoc exception = ReportXml.getElementChild(element, "exception");
42     if (exception != null) {
43       trial.setException(ReportXml.getText(exception));
44     }
45
46     List JavaDoc elements = ReportXml.getElementChildren(element, "variable");
47
48     Map JavaDoc variables = trial.getVariables();
49
50     for (Iterator JavaDoc it = elements.iterator(); it.hasNext();) {
51       Element JavaDoc e = (Element JavaDoc) it.next();
52       String JavaDoc name = e.getAttribute("name");
53       String JavaDoc value = e.getAttribute("value");
54       variables.put(name, value);
55     }
56
57     return trial;
58   }
59 }
60
Popular Tags