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

COVERAGE SUMMARY FOR SOURCE FILE [VCloudResourceAllocationSettingDataHandler.java]

nameclass, %method, %block, %line, %
VCloudResourceAllocationSettingDataHandler.java100% (1/1)100% (3/3)90%  (218/242)96%  (27.9/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudResourceAllocationSettingDataHandler100% (1/1)100% (3/3)90%  (218/242)96%  (27.9/29)
getResult (): ResourceAllocationSettingData 100% (1/1)86%  (142/166)93%  (13.9/15)
VCloudResourceAllocationSettingDataHandler (): void 100% (1/1)100% (3/3)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (73/73)100% (13/13)

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.ovf;
20 
21import java.util.Map;
22 
23import org.jclouds.cim.ResourceAllocationSettingData;
24import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
25import org.jclouds.util.SaxUtils;
26import org.jclouds.vcloud.domain.ReferenceType;
27import org.jclouds.vcloud.domain.ovf.EditableResourceAllocationSettingData;
28import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
29import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
30import org.jclouds.vcloud.util.Utils;
31import org.xml.sax.Attributes;
32 
33/**
34 * @author Adrian Cole
35 */
36public class VCloudResourceAllocationSettingDataHandler extends ResourceAllocationSettingDataHandler {
37 
38   private ReferenceType edit;
39 
40   private long capacity;
41   private int busType;
42   private String busSubType;
43 
44   private String ipAddress;
45   private boolean primaryNetworkConnection;
46   private String ipAddressingMode;
47 
48   public ResourceAllocationSettingData getResult() {
49      try {
50         ResourceAllocationSettingData from = super.getResult();
51         if (edit != null) {
52            return EditableResourceAllocationSettingData.builder().fromResourceAllocationSettingData(from).edit(edit)
53                     .build();
54         } else if (busSubType != null) {
55            return VCloudHardDisk.builder().fromResourceAllocationSettingData(from).capacity(capacity).busType(busType)
56                     .busSubType(busSubType).build();
57         } else if (ipAddress != null) {
58            return VCloudNetworkAdapter.builder().fromResourceAllocationSettingData(from).ipAddress(ipAddress)
59                     .primaryNetworkConnection(primaryNetworkConnection).ipAddressingMode(ipAddressingMode).build();
60         } else {
61            return from;
62         }
63      } finally {
64         ipAddress = null;
65         primaryNetworkConnection = false;
66         ipAddressingMode = null;
67         capacity = -1;
68         busType = -1;
69         busSubType = null;
70         edit = null;
71      }
72   }
73 
74   @Override
75   public void startElement(String uri, String localName, String qName, Attributes attrs) {
76      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
77      if (qName.endsWith("Link")) {
78         this.edit = Utils.newReferenceType(attributes);
79      } else if (qName.endsWith("HostResource") && attributes.size() > 0) {
80         capacity = Long.parseLong(attributes.get("capacity"));
81         busType = Integer.parseInt(attributes.get("busType"));
82         busSubType = attributes.get("busSubType");
83      } else if (qName.endsWith("Connection") && attributes.size() > 0) {
84         ipAddress = attributes.get("ipAddress");
85         primaryNetworkConnection = Boolean.parseBoolean(attributes.get("primaryNetworkConnection"));
86         ipAddressingMode = attributes.get("ipAddressingMode");
87      }
88      super.startElement(uri, localName, qName, attrs);
89   }
90 
91}

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