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

COVERAGE SUMMARY FOR SOURCE FILE [VAppHandler.java]

nameclass, %method, %block, %line, %
VAppHandler.java100% (1/1)100% (5/5)100% (275/275)100% (53/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppHandler100% (1/1)100% (5/5)100% (275/275)100% (53/53)
VAppHandler (VirtualSystemSettingDataHandler, ResourceAllocationSettingDataHa... 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 (): VApp 100% (1/1)100% (26/26)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (114/114)100% (23/23)

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.trmk.vcloud_0_8.xml;
20 
21import static org.jclouds.trmk.vcloud_0_8.util.Utils.newReferenceType;
22 
23import java.net.URI;
24import java.util.Map;
25import java.util.Set;
26 
27import javax.annotation.Resource;
28import javax.inject.Inject;
29 
30import org.jclouds.cim.ResourceAllocationSettingData;
31import org.jclouds.cim.VirtualSystemSettingData;
32import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
33import org.jclouds.cim.xml.VirtualSystemSettingDataHandler;
34import org.jclouds.http.functions.ParseSax;
35import org.jclouds.logging.Logger;
36import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
37import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
38import org.jclouds.trmk.vcloud_0_8.domain.Status;
39import org.jclouds.trmk.vcloud_0_8.domain.VApp;
40import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
41import org.jclouds.util.SaxUtils;
42import org.xml.sax.Attributes;
43import org.xml.sax.SAXException;
44 
45import com.google.common.collect.ArrayListMultimap;
46import com.google.common.collect.ListMultimap;
47import com.google.common.collect.Sets;
48 
49/**
50 * @author Adrian Cole
51 */
52public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
53   private final VirtualSystemSettingDataHandler systemHandler;
54   private final ResourceAllocationSettingDataHandler allocationHandler;
55   @Resource
56   protected Logger logger = Logger.NULL;
57 
58   @Inject
59   public VAppHandler(VirtualSystemSettingDataHandler systemHandler,
60         ResourceAllocationSettingDataHandler allocationHandler) {
61      this.systemHandler = systemHandler;
62      this.allocationHandler = allocationHandler;
63   }
64 
65   protected VirtualSystemSettingData system;
66   protected Set<ResourceAllocationSettingData> allocations = Sets.newLinkedHashSet();
67   protected Status status;
68   protected final ListMultimap<String, String> networkToAddresses = ArrayListMultimap.create();
69   protected StringBuilder currentText = new StringBuilder();
70   protected String operatingSystemDescription;
71   protected boolean inOs;
72   protected String networkName;
73   protected String name;
74   protected Integer osType;
75   protected URI location;
76   protected Long size;
77   protected ReferenceType vDC;
78   protected Set<ReferenceType> extendedInfo = Sets.newLinkedHashSet();
79 
80   public VApp getResult() {
81      return new VAppImpl(name, location, status, size, vDC, networkToAddresses, osType, operatingSystemDescription,
82            system, allocations, extendedInfo);
83   }
84 
85   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
86      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
87      if (qName.equals("VApp")) {
88         ReferenceType resource = newReferenceType(attributes);
89         name = resource.getName();
90         location = resource.getHref();
91         String statusString = attributes.get("status");
92         status = Status.fromValue(statusString);
93         if (attributes.containsKey("size"))
94            size = new Long(attributes.get("size"));
95      } else if (qName.equals("Link")) { // type should never be missing
96         if (attributes.containsKey("type")) {
97            if (attributes.get("type").equals(TerremarkVCloudMediaType.VDC_XML)) {
98               vDC = newReferenceType(attributes);
99            } else {
100               extendedInfo.add(newReferenceType(attributes));
101            }
102         }
103      } else if (qName.equals("OperatingSystemSection")) {
104         inOs = true;
105         if (attributes.containsKey("id"))
106            osType = Integer.parseInt(attributes.get("id"));
107      } else if (qName.endsWith("NetworkConnection")) {
108         networkName = attributes.get("Network");
109      } else {
110         systemHandler.startElement(uri, localName, qName, attrs);
111         allocationHandler.startElement(uri, localName, qName, attrs);
112      }
113 
114   }
115 
116   @Override
117   public void endElement(String uri, String localName, String qName) throws SAXException {
118      if (qName.equals("OperatingSystemSection")) {
119         inOs = false;
120      } else if (inOs && qName.equals("Description")) {
121         operatingSystemDescription = currentText.toString().trim();
122      } else if (qName.endsWith("IpAddress")) {
123         networkToAddresses.put(networkName, currentText.toString().trim());
124      } else if (qName.equals("System")) {
125         systemHandler.endElement(uri, localName, qName);
126         system = systemHandler.getResult();
127      } else if (qName.equals("Item")) {
128         allocationHandler.endElement(uri, localName, qName);
129         allocations.add(allocationHandler.getResult());
130      } else {
131         systemHandler.endElement(uri, localName, qName);
132         allocationHandler.endElement(uri, localName, qName);
133      }
134      currentText = new StringBuilder();
135   }
136 
137   @Override
138   public void characters(char ch[], int start, int length) {
139      currentText.append(ch, start, length);
140      systemHandler.characters(ch, start, length);
141      allocationHandler.characters(ch, start, length);
142   }
143 
144}

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