EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.savvis.vpdc.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VMHandler.java]

nameclass, %method, %block, %line, %
VMHandler.java100% (1/1)100% (3/3)83%  (103/124)88%  (17.6/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VMHandler100% (1/1)100% (3/3)83%  (103/124)88%  (17.6/20)
startElement (String, String, String, Attributes): void 100% (1/1)77%  (47/61)84%  (7.6/9)
addAdditionalSection (String, Section): void 100% (1/1)85%  (40/47)88%  (7/8)
VMHandler (Provider, OperatingSystemSectionHandler, VirtualHardwareSectionHan... 100% (1/1)100% (16/16)100% (3/3)

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.savvis.vpdc.xml;
20 
21import static org.jclouds.savvis.vpdc.util.Utils.newResource;
22import static org.jclouds.util.SaxUtils.equalsOrSuffix;
23 
24import java.util.Map;
25 
26import javax.inject.Inject;
27import javax.inject.Provider;
28 
29import org.jclouds.ovf.NetworkSection;
30import org.jclouds.ovf.Section;
31import org.jclouds.ovf.xml.NetworkSectionHandler;
32import org.jclouds.ovf.xml.OperatingSystemSectionHandler;
33import org.jclouds.ovf.xml.ProductSectionHandler;
34import org.jclouds.ovf.xml.SectionHandler;
35import org.jclouds.ovf.xml.VirtualHardwareSectionHandler;
36import org.jclouds.ovf.xml.internal.BaseVirtualSystemHandler;
37import org.jclouds.savvis.vpdc.domain.NetworkConfigSection;
38import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection;
39import org.jclouds.savvis.vpdc.domain.Resource;
40import org.jclouds.savvis.vpdc.domain.VM;
41import org.jclouds.savvis.vpdc.util.Utils;
42import org.xml.sax.Attributes;
43import org.xml.sax.SAXException;
44 
45import com.google.common.collect.ImmutableMap;
46 
47/**
48 * @author Kedar Dave
49 */
50public class VMHandler extends BaseVirtualSystemHandler<VM, VM.Builder> {
51 
52   @SuppressWarnings("unchecked")
53   @Inject
54   public VMHandler(Provider<VM.Builder> builderProvider, OperatingSystemSectionHandler osHandler,
55            VirtualHardwareSectionHandler hardwareHandler, ProductSectionHandler productHandler,
56            Provider<NetworkSectionHandler> networkSectionHandler,
57            Provider<NetworkConfigSectionHandler> networkConfigSectionHandler,
58            Provider<NetworkConnectionSectionHandler> networkConnectionSectionHandler) {
59      super(builderProvider, osHandler, hardwareHandler, productHandler);
60      this.extensionHandlers = ImmutableMap.<String, Provider<? extends SectionHandler>> of("ovf:NetworkSection",
61               networkSectionHandler, "vApp:NetworkConfigSectionType", networkConfigSectionHandler,
62               "vApp:NetworkConnectionType", networkConnectionSectionHandler);
63   }
64 
65   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
66      Map<String, String> attributes = Utils.cleanseAttributes(attrs);
67      if (equalsOrSuffix(qName, "VApp")) {
68         // savvis doesn't add href in the header for some reason
69         if (!attributes.containsKey("href") && getRequest() != null)
70            attributes = ImmutableMap.<String, String> builder().putAll(attributes).put("href",
71                     getRequest().getEndpoint().toASCIIString()).build();
72         Resource vApp = newResource(attributes);
73         builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref());
74         builder.status(VM.Status.fromValue(attributes.get("status")));
75      }
76      super.startElement(uri, localName, qName, attrs);
77   }
78 
79   @Override
80   @SuppressWarnings("unchecked")
81   protected void addAdditionalSection(String qName, Section additionalSection) {
82      if (additionalSection instanceof NetworkSection) {
83         builder.networkSection(NetworkSection.class.cast(additionalSection));
84      } else if (additionalSection instanceof NetworkConfigSection) {
85         builder.networkConfigSection(NetworkConfigSection.class.cast(additionalSection));
86      } else if (additionalSection instanceof NetworkConnectionSection) {
87         builder.networkConnectionSection(NetworkConnectionSection.class.cast(additionalSection));
88      } else {
89         builder.additionalSection(qName, additionalSection);
90      }
91   }
92 
93}

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