EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.vcloud.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VAppHandler.java]

nameclass, %method, %block, %line, %
VAppHandler.java100% (1/1)100% (5/5)83%  (207/248)87%  (45/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppHandler100% (1/1)100% (5/5)83%  (207/248)87%  (45/52)
endElement (String, String, String): void 100% (1/1)72%  (61/85)78%  (14/18)
characters (char [], int, int): void 100% (1/1)77%  (20/26)83%  (5/6)
startElement (String, String, String, Attributes): void 100% (1/1)87%  (75/86)89%  (16/18)
VAppHandler (TaskHandler, VmHandler): void 100% (1/1)100% (26/26)100% (9/9)
getResult (): VApp 100% (1/1)100% (25/25)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.vcloud.xml;
20 
21import static org.jclouds.util.SaxUtils.equalsOrSuffix;
22import static org.jclouds.vcloud.util.Utils.newReferenceType;
23 
24import java.util.List;
25import java.util.Map;
26import java.util.Set;
27 
28import javax.inject.Inject;
29 
30import org.jclouds.http.functions.ParseSax;
31import org.jclouds.util.SaxUtils;
32import org.jclouds.vcloud.domain.ReferenceType;
33import org.jclouds.vcloud.domain.Status;
34import org.jclouds.vcloud.domain.Task;
35import org.jclouds.vcloud.domain.VApp;
36import org.jclouds.vcloud.domain.Vm;
37import org.jclouds.vcloud.domain.internal.VAppImpl;
38import org.xml.sax.Attributes;
39import org.xml.sax.SAXException;
40 
41import com.google.common.collect.Lists;
42import com.google.common.collect.Sets;
43 
44/**
45 * @author Adrian Cole
46 */
47public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
48 
49   protected final TaskHandler taskHandler;
50   protected final VmHandler vmHandler;
51 
52   @Inject
53   public VAppHandler(TaskHandler taskHandler, VmHandler vmHandler) {
54      this.taskHandler = taskHandler;
55      this.vmHandler = vmHandler;
56   }
57 
58   protected StringBuilder currentText = new StringBuilder();
59 
60   protected ReferenceType template;
61   protected Status status;
62   protected ReferenceType vdc;
63   protected String description;
64   protected List<Task> tasks = Lists.newArrayList();
65   protected boolean ovfDescriptorUploaded = true;
66 
67   private boolean inChildren;
68   private boolean inTasks;
69   protected Set<Vm> children = Sets.newLinkedHashSet();
70 
71   public VApp getResult() {
72      return new VAppImpl(template.getName(), template.getType(), template.getHref(), status, vdc, description, tasks,
73            ovfDescriptorUploaded, children);
74   }
75 
76   protected int depth = 0;
77 
78   @Override
79   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
80      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
81      depth++;
82      if (depth == 2) {
83         if (equalsOrSuffix(qName, "Children")) {
84            inChildren = true;
85         } else if (equalsOrSuffix(qName, "Tasks")) {
86            inTasks = true;
87         }
88      }
89      if (inChildren) {
90         vmHandler.startElement(uri, localName, qName, attrs);
91      } else if (inTasks) {
92         taskHandler.startElement(uri, localName, qName, attrs);
93      } else if (equalsOrSuffix(qName, "VApp")) {
94         template = newReferenceType(attributes);
95         if (attributes.containsKey("status"))
96            this.status = Status.fromValue(Integer.parseInt(attributes.get("status")));
97      } else if (equalsOrSuffix(qName, "Link") && "up".equals(attributes.get("rel"))) {
98         vdc = newReferenceType(attributes);
99      }
100 
101   }
102 
103   public void endElement(String uri, String name, String qName) {
104      depth--;
105      if (depth == 1) {
106         if (equalsOrSuffix(qName, "Children")) {
107            inChildren = false;
108            this.children.add(vmHandler.getResult());
109         } else if (equalsOrSuffix(qName, "Tasks")) {
110            inTasks = false;
111            this.tasks.add(taskHandler.getResult());
112         } else if (equalsOrSuffix(qName, "Description")) {
113            description = SaxUtils.currentOrNull(currentText);
114         }
115      }
116      if (inChildren) {
117         vmHandler.endElement(uri, name, qName);
118      } else if (inTasks) {
119         taskHandler.endElement(uri, name, qName);
120      } else if (equalsOrSuffix(qName, "ovfDescriptorUploaded")) {
121         ovfDescriptorUploaded = Boolean.parseBoolean(SaxUtils.currentOrNull(currentText));
122      }
123      currentText = new StringBuilder();
124   }
125 
126   public void characters(char ch[], int start, int length) {
127      currentText.append(ch, start, length);
128      if (inTasks)
129         taskHandler.characters(ch, start, length);
130      if (inChildren)
131         vmHandler.characters(ch, start, length);
132   }
133 
134}

[all classes][org.jclouds.vcloud.xml]
EMMA 2.0.5312 (C) Vladimir Roubtsov