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

COVERAGE SUMMARY FOR SOURCE FILE [VirtualHardwareSectionHandler.java]

nameclass, %method, %block, %line, %
VirtualHardwareSectionHandler.java100% (1/1)100% (4/4)92%  (156/169)97%  (36/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VirtualHardwareSectionHandler100% (1/1)100% (4/4)92%  (156/169)97%  (36/37)
startElement (String, String, String, Attributes): void 100% (1/1)80%  (51/64)92%  (12/13)
VirtualHardwareSectionHandler (Provider, VirtualSystemSettingDataHandler, Res... 100% (1/1)100% (10/10)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (26/26)100% (6/6)
endElement (String, String, String): void 100% (1/1)100% (69/69)100% (14/14)

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.cleanseAttributes;
22import static org.jclouds.util.SaxUtils.currentOrNull;
23import static org.jclouds.util.SaxUtils.equalsOrSuffix;
24 
25import java.util.Map;
26 
27import javax.inject.Inject;
28import javax.inject.Provider;
29 
30import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
31import org.jclouds.cim.xml.VirtualSystemSettingDataHandler;
32import org.jclouds.ovf.VirtualHardwareSection;
33import org.xml.sax.Attributes;
34 
35import com.google.common.base.Splitter;
36 
37/**
38 * @author Adrian Cole
39 */
40public class VirtualHardwareSectionHandler extends
41         SectionHandler<VirtualHardwareSection, VirtualHardwareSection.Builder> {
42 
43   private final VirtualSystemSettingDataHandler systemHandler;
44   private final ResourceAllocationSettingDataHandler allocationHandler;
45 
46   @Inject
47   public VirtualHardwareSectionHandler(Provider<VirtualHardwareSection.Builder> builderProvider,
48            VirtualSystemSettingDataHandler systemHandler, ResourceAllocationSettingDataHandler allocationHandler) {
49      super(builderProvider);
50      this.systemHandler = systemHandler;
51      this.allocationHandler = allocationHandler;
52   }
53 
54   private boolean inItem;
55   private boolean inSystem;
56 
57   public void startElement(String uri, String localName, String qName, Attributes attrs) {
58      Map<String, String> attributes = cleanseAttributes(attrs);
59      if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
60         if (attributes.containsKey("transport"))
61            builder.transports(Splitter.on(' ').split(attributes.get("transport")));
62      } else if (equalsOrSuffix(qName, "System")) {
63         inSystem = true;
64      } else if (!inSystem && equalsOrSuffix(qName, "Item")) {
65         inItem = true;
66      }
67      if (inSystem) {
68         systemHandler.startElement(uri, localName, qName, attrs);
69      } else if (inItem) {
70         allocationHandler.startElement(uri, localName, qName, attrs);
71      }
72   }
73 
74   @Override
75   public void endElement(String uri, String localName, String qName) {
76      if (equalsOrSuffix(qName, "System")) {
77         inSystem = false;
78         builder.system(systemHandler.getResult());
79      } else if (equalsOrSuffix(qName, "Item")) {
80         inItem = false;
81         builder.item(allocationHandler.getResult());
82      }
83      if (inSystem) {
84         systemHandler.endElement(uri, localName, qName);
85      } else if (inItem) {
86         allocationHandler.endElement(uri, localName, qName);
87      } else {
88         if (equalsOrSuffix(qName, "Info"))
89            builder.info(currentOrNull(currentText));
90         super.endElement(uri, localName, qName);
91      }
92   }
93 
94   @Override
95   public void characters(char ch[], int start, int length) {
96      if (inSystem) {
97         systemHandler.characters(ch, start, length);
98      } else if (inItem) {
99         allocationHandler.characters(ch, start, length);
100      } else {
101         super.characters(ch, start, length);
102      }
103   }
104 
105}

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