EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.ovf.xml]

COVERAGE SUMMARY FOR SOURCE FILE [DiskSectionHandler.java]

nameclass, %method, %block, %line, %
DiskSectionHandler.java100% (1/1)100% (4/4)96%  (159/165)99%  (29.7/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DiskSectionHandler100% (1/1)100% (4/4)96%  (159/165)99%  (29.7/30)
endElement (String, String, String): void 100% (1/1)85%  (35/41)96%  (7.7/8)
DiskSectionHandler (Provider): void 100% (1/1)100% (10/10)100% (4/4)
attemptToParse (String, String, String): Long 100% (1/1)100% (31/31)100% (7/7)
startElement (String, String, String, Attributes): void 100% (1/1)100% (83/83)100% (11/11)

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.ovf.xml;
20 
21import static org.jclouds.util.SaxUtils.currentOrNull;
22import static org.jclouds.util.SaxUtils.equalsOrSuffix;
23 
24import java.net.URI;
25import java.util.Map;
26 
27import javax.annotation.Resource;
28import javax.inject.Inject;
29import javax.inject.Provider;
30 
31import org.jclouds.logging.Logger;
32import org.jclouds.ovf.Disk;
33import org.jclouds.ovf.DiskSection;
34import org.jclouds.util.SaxUtils;
35import org.xml.sax.Attributes;
36 
37/**
38 * @author Adrian Cole
39 */
40public class DiskSectionHandler extends SectionHandler<DiskSection, DiskSection.Builder> {
41 
42   @Resource
43   protected Logger logger = Logger.NULL;
44   protected Disk.Builder diskBuilder = Disk.builder();
45 
46   @Inject
47   public DiskSectionHandler(Provider<DiskSection.Builder> builderProvider) {
48      super(builderProvider);
49   }
50 
51   public void startElement(String uri, String localName, String qName, Attributes attrs) {
52      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
53      if (equalsOrSuffix(qName, "Disk")) {
54         diskBuilder.id(attributes.get("diskId"));
55         diskBuilder.capacity(attemptToParse(attributes.get("capacity"), "capacity", attributes.get("diskId")));
56         diskBuilder.parentRef(attributes.get("parentRef"));
57         diskBuilder.fileRef(attributes.get("fileRef"));
58         if (attributes.containsKey("format"))
59            diskBuilder.format(URI.create(attributes.get("format")));
60         diskBuilder.populatedSize(attemptToParse(attributes.get("populatedSize"), "populatedSize", attributes
61                  .get("diskId")));
62         diskBuilder.capacityAllocationUnits(attributes.get("capacityAllocationUnits"));
63      }
64   }
65 
66   private Long attemptToParse(String toParse, String key, String diskId) {
67      Long val = null;
68      if (toParse != null) {
69         try {
70            val = new Long(toParse);
71         } catch (NumberFormatException e) {
72            logger.warn("%s for disk %s not a number [%s]", key, diskId, toParse);
73         }
74      }
75      return val;
76   }
77 
78   @Override
79   public void endElement(String uri, String localName, String qName) {
80      if (equalsOrSuffix(qName, "Info")) {
81         builder.info(currentOrNull(currentText));
82      } else if (equalsOrSuffix(qName, "Disk")) {
83         try {
84            builder.disk(diskBuilder.build());
85         } finally {
86            diskBuilder = Disk.builder();
87         }
88      }
89      super.endElement(uri, localName, qName);
90   }
91 
92}

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