EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VCloudExpressVAppHandler.java]

nameclass, %method, %block, %line, %
VCloudExpressVAppHandler.java100% (1/1)100% (5/5)99%  (276/280)98%  (52/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudExpressVAppHandler100% (1/1)100% (5/5)99%  (276/280)98%  (52/53)
startElement (String, String, String, Attributes): void 100% (1/1)97%  (117/121)96%  (22/23)
VCloudExpressVAppHandler (String, VirtualSystemSettingDataHandler, ResourceAl... 100% (1/1)100% (26/26)100% (9/9)
characters (char [], int, int): void 100% (1/1)100% (20/20)100% (4/4)
endElement (String, String, String): void 100% (1/1)100% (89/89)100% (16/16)
getResult (): VCloudExpressVApp 100% (1/1)100% (24/24)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.xml;
20 
21import static org.jclouds.Constants.PROPERTY_API_VERSION;
22import static org.jclouds.vcloud.util.Utils.newReferenceType;
23 
24import java.net.URI;
25import java.util.Map;
26import java.util.Set;
27 
28import javax.annotation.Resource;
29import javax.inject.Inject;
30import javax.inject.Named;
31 
32import org.jclouds.cim.ResourceAllocationSettingData;
33import org.jclouds.cim.VirtualSystemSettingData;
34import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
35import org.jclouds.cim.xml.VirtualSystemSettingDataHandler;
36import org.jclouds.http.functions.ParseSax;
37import org.jclouds.logging.Logger;
38import org.jclouds.util.SaxUtils;
39import org.jclouds.vcloud.VCloudExpressMediaType;
40import org.jclouds.vcloud.domain.ReferenceType;
41import org.jclouds.vcloud.domain.Status;
42import org.jclouds.vcloud.domain.VCloudExpressVApp;
43import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl;
44import org.xml.sax.Attributes;
45import org.xml.sax.SAXException;
46 
47import com.google.common.collect.ArrayListMultimap;
48import com.google.common.collect.ListMultimap;
49import com.google.common.collect.Sets;
50 
51/**
52 * @author Adrian Cole
53 */
54public class VCloudExpressVAppHandler extends ParseSax.HandlerWithResult<VCloudExpressVApp> {
55   private final String apiVersion;
56   private final VirtualSystemSettingDataHandler systemHandler;
57   private final ResourceAllocationSettingDataHandler allocationHandler;
58   @Resource
59   protected Logger logger = Logger.NULL;
60 
61   @Inject
62   public VCloudExpressVAppHandler(@Named(PROPERTY_API_VERSION) String apiVersion,
63            VirtualSystemSettingDataHandler systemHandler, ResourceAllocationSettingDataHandler allocationHandler) {
64      this.apiVersion = apiVersion;
65      this.systemHandler = systemHandler;
66      this.allocationHandler = allocationHandler;
67   }
68 
69   protected VirtualSystemSettingData system;
70   protected Set<ResourceAllocationSettingData> allocations = Sets.newLinkedHashSet();
71   protected Status status;
72   protected final ListMultimap<String, String> networkToAddresses = ArrayListMultimap.create();
73   protected StringBuilder currentText = new StringBuilder();
74   protected String operatingSystemDescription;
75   protected boolean inOs;
76   protected String networkName;
77   protected String name;
78   protected Integer osType;
79   protected URI location;
80   protected Long size;
81   protected ReferenceType vDC;
82 
83   public VCloudExpressVApp getResult() {
84      return new VCloudExpressVAppImpl(name, location, status, size, vDC, networkToAddresses, osType,
85               operatingSystemDescription, system, allocations);
86   }
87 
88   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
89      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
90      if (qName.equals("VApp")) {
91         ReferenceType resource = newReferenceType(attributes);
92         name = resource.getName();
93         location = resource.getHref();
94         String statusString = attributes.get("status");
95         if (apiVersion.indexOf("0.8") != -1 && "2".equals(statusString))
96            status = Status.OFF;
97         else
98            status = Status.fromValue(statusString);
99         if (attributes.containsKey("size"))
100            size = new Long(attributes.get("size"));
101      } else if (qName.equals("Link")) { // type should never be missing
102         if (attributes.containsKey("type") && attributes.get("type").equals(VCloudExpressMediaType.VDC_XML)) {
103            vDC = newReferenceType(attributes);
104         }
105      } else if (qName.equals("OperatingSystemSection")) {
106         inOs = true;
107         if (attributes.containsKey("id"))
108            osType = Integer.parseInt(attributes.get("id"));
109      } else if (qName.endsWith("NetworkConnection")) {
110         networkName = attributes.get("Network");
111      } else {
112         systemHandler.startElement(uri, localName, qName, attrs);
113         allocationHandler.startElement(uri, localName, qName, attrs);
114      }
115 
116   }
117 
118   @Override
119   public void endElement(String uri, String localName, String qName) throws SAXException {
120      if (qName.equals("OperatingSystemSection")) {
121         inOs = false;
122      } else if (inOs && qName.equals("Description")) {
123         operatingSystemDescription = currentText.toString().trim();
124      } else if (qName.endsWith("IpAddress")) {
125         networkToAddresses.put(networkName, currentText.toString().trim());
126      } else if (qName.equals("System")) {
127         systemHandler.endElement(uri, localName, qName);
128         system = systemHandler.getResult();
129      } else if (qName.equals("Item")) {
130         allocationHandler.endElement(uri, localName, qName);
131         allocations.add(allocationHandler.getResult());
132      } else {
133         systemHandler.endElement(uri, localName, qName);
134         allocationHandler.endElement(uri, localName, qName);
135      }
136      currentText = new StringBuilder();
137   }
138 
139   @Override
140   public void characters(char ch[], int start, int length) {
141      currentText.append(ch, start, length);
142      systemHandler.characters(ch, start, length);
143      allocationHandler.characters(ch, start, length);
144   }
145 
146}

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