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

COVERAGE SUMMARY FOR SOURCE FILE [VAppTemplateHandler.java]

nameclass, %method, %block, %line, %
VAppTemplateHandler.java100% (1/1)100% (6/6)96%  (301/312)97%  (62.9/65)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppTemplateHandler100% (1/1)100% (6/6)96%  (301/312)97%  (62.9/65)
endElement (String, String, String): void 100% (1/1)91%  (101/111)92%  (23/25)
currentOrNull (): String 100% (1/1)92%  (12/13)96%  (1.9/2)
VAppTemplateHandler (TaskHandler, VmHandler, VCloudNetworkSectionHandler): void 100% (1/1)100% (26/26)100% (9/9)
characters (char [], int, int): void 100% (1/1)100% (38/38)100% (8/8)
getResult (): VAppTemplate 100% (1/1)100% (29/29)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (95/95)100% (20/20)

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.vcloud.util.Utils.newReferenceType;
22 
23import java.util.List;
24import java.util.Map;
25import java.util.Set;
26 
27import javax.inject.Inject;
28 
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.util.SaxUtils;
31import org.jclouds.vcloud.domain.ReferenceType;
32import org.jclouds.vcloud.domain.Status;
33import org.jclouds.vcloud.domain.Task;
34import org.jclouds.vcloud.domain.VAppTemplate;
35import org.jclouds.vcloud.domain.Vm;
36import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
37import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
38import org.jclouds.vcloud.xml.ovf.VCloudNetworkSectionHandler;
39import org.xml.sax.Attributes;
40import org.xml.sax.SAXException;
41 
42import com.google.common.collect.Lists;
43import com.google.common.collect.Sets;
44 
45/**
46 * @author Adrian Cole
47 */
48public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate> {
49 
50   protected final TaskHandler taskHandler;
51   protected final VmHandler vmHandler;
52   protected final VCloudNetworkSectionHandler networkSectionHandler;
53 
54   @Inject
55   public VAppTemplateHandler(TaskHandler taskHandler, VmHandler vmHandler,
56            VCloudNetworkSectionHandler networkSectionHandler) {
57      this.taskHandler = taskHandler;
58      this.vmHandler = vmHandler;
59      this.networkSectionHandler = networkSectionHandler;
60   }
61 
62   protected StringBuilder currentText = new StringBuilder();
63 
64   protected ReferenceType template;
65   protected Status status;
66   protected ReferenceType vdc;
67   protected String description;
68   protected List<Task> tasks = Lists.newArrayList();
69   protected boolean ovfDescriptorUploaded = true;
70   protected String vAppScopedLocalId;
71 
72   private boolean inChildren;
73   private boolean inTasks;
74   private boolean inNetworkSection;
75   protected Set<Vm> children = Sets.newLinkedHashSet();
76   private VCloudNetworkSection networkSection;
77 
78   public VAppTemplate getResult() {
79      return new VAppTemplateImpl(template.getName(), template.getType(), template.getHref(), status, vdc, description,
80               tasks, ovfDescriptorUploaded, vAppScopedLocalId, children, networkSection);
81   }
82 
83   @Override
84   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
85      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
86      if (qName.endsWith("Children")) {
87         inChildren = true;
88      } else if (qName.endsWith("Tasks")) {
89         inTasks = true;
90      } else if (qName.endsWith("NetworkSection")) {
91         inNetworkSection = true;
92      }
93      if (inChildren) {
94         vmHandler.startElement(uri, localName, qName, attrs);
95      } else if (inTasks) {
96         taskHandler.startElement(uri, localName, qName, attrs);
97      } else if (inNetworkSection) {
98         networkSectionHandler.startElement(uri, localName, qName, attrs);
99      } else if (qName.equals("VAppTemplate")) {
100         template = newReferenceType(attributes);
101         if (attributes.containsKey("status"))
102            this.status = Status.fromValue(Integer.parseInt(attributes.get("status")));
103      } else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
104         vdc = newReferenceType(attributes);
105      }
106 
107   }
108 
109   public void endElement(String uri, String name, String qName) {
110      if (qName.endsWith("Children")) {
111         inChildren = false;
112         Vm vm = vmHandler.getResult();
113         if (vm != null)
114            this.children.add(vmHandler.getResult());
115      } else if (qName.endsWith("Tasks")) {
116         inTasks = false;
117         this.tasks.add(taskHandler.getResult());
118      } else if (qName.endsWith("NetworkSection")) {
119         inNetworkSection = false;
120         this.networkSection = networkSectionHandler.getResult();
121      }
122      if (inChildren) {
123         vmHandler.endElement(uri, name, qName);
124      } else if (inTasks) {
125         taskHandler.endElement(uri, name, qName);
126      } else if (inNetworkSection) {
127         networkSectionHandler.endElement(uri, name, qName);
128      } else if (qName.equals("Description")) {
129         description = currentOrNull();
130      } else if (qName.equals("VAppScopedLocalId")) {
131         vAppScopedLocalId = currentOrNull();
132      } else if (qName.equals("ovfDescriptorUploaded")) {
133         ovfDescriptorUploaded = Boolean.parseBoolean(currentOrNull());
134      }
135      currentText = new StringBuilder();
136   }
137 
138   public void characters(char ch[], int start, int length) {
139      if (inTasks)
140         taskHandler.characters(ch, start, length);
141      else if (inChildren)
142         vmHandler.characters(ch, start, length);
143      else if (inNetworkSection)
144         networkSectionHandler.characters(ch, start, length);
145      else
146         currentText.append(ch, start, length);
147   }
148 
149   protected String currentOrNull() {
150      String returnVal = currentText.toString().trim();
151      return returnVal.equals("") ? null : returnVal;
152   }
153}

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