EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.trmk.vcloud_0_8.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VAppExtendedInfoHandler.java]

nameclass, %method, %block, %line, %
VAppExtendedInfoHandler.java0%   (0/1)0%   (0/6)0%   (0/209)0%   (0/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppExtendedInfoHandler0%   (0/1)0%   (0/6)0%   (0/209)0%   (0/48)
VAppExtendedInfoHandler (): void 0%   (0/1)0%   (0/14)0%   (0/4)
characters (char [], int, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
currentOrNull (): String 0%   (0/1)0%   (0/13)0%   (0/2)
endElement (String, String, String): void 0%   (0/1)0%   (0/142)0%   (0/34)
getResult (): VAppExtendedInfo 0%   (0/1)0%   (0/16)0%   (0/1)
startElement (String, String, String, Attributes): void 0%   (0/1)0%   (0/16)0%   (0/5)

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.trmk.vcloud_0_8.xml;
20 
21import java.net.URI;
22import java.util.Arrays;
23import java.util.List;
24 
25import javax.annotation.Resource;
26 
27import org.jclouds.http.functions.ParseSax.HandlerWithResult;
28import org.jclouds.logging.Logger;
29import org.jclouds.trmk.vcloud_0_8.domain.NetworkAdapter;
30import org.jclouds.trmk.vcloud_0_8.domain.Subnet;
31import org.jclouds.trmk.vcloud_0_8.domain.VAppExtendedInfo;
32import org.xml.sax.Attributes;
33import org.xml.sax.SAXException;
34 
35import com.google.common.collect.Lists;
36 
37/**
38 * @author Seshu Pasam
39 */
40public class VAppExtendedInfoHandler extends HandlerWithResult<VAppExtendedInfo> {
41 
42   @Resource
43   protected Logger logger = Logger.NULL;
44   private StringBuilder currentText = new StringBuilder();
45 
46   private String id;
47   private URI href;
48   private String name;
49   private String longName;
50   private List<String> tags;
51   private List<NetworkAdapter> networkAdapters = Lists.newArrayList();
52   private boolean inAdapters;
53   private String macAddress;
54   private String adapterName;
55   private boolean inSubnet;
56   private Subnet subnet;
57   private URI subnetLocation;
58   private String subnetName;
59 
60   protected String currentOrNull() {
61      String returnVal = currentText.toString().trim();
62      return returnVal.equals("") ? null : returnVal;
63   }
64 
65   @Override
66   public VAppExtendedInfo getResult() {
67      return new VAppExtendedInfo(id, href, name, tags, longName, networkAdapters);
68   }
69 
70   @Override
71   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
72      if (qName.equals("NetworkAdapters")) {
73         inAdapters = true;
74      } else if (qName.equals("Subnet")) {
75         inSubnet = true;
76      }
77   }
78 
79   public void endElement(String uri, String name, String qName) {
80      String current = currentOrNull();
81      if (current != null) {
82         if (qName.equals("Id")) {
83            this.id = current;
84         } else if (qName.equals("Tags")) {
85            this.tags = Arrays.asList(current.split(","));
86         } else if (qName.equals("LongName")) {
87            this.longName = current;
88         } else if (qName.equals("Href")) {
89            if (inSubnet) {
90               this.subnetLocation = URI.create(current);
91            } else {
92               this.href = URI.create(current);
93            }
94         } else if (qName.equals("Name")) {
95            if (inSubnet) {
96               this.subnetName = current;
97            } else if (inAdapters) {
98               this.adapterName = current;
99            } else {
100               this.name = current;
101            }
102         } else if (qName.equals("NetworkAdapters")) {
103             inAdapters = false;
104         } else if (qName.equals("NetworkAdapter")) {
105             networkAdapters.add(new NetworkAdapter(macAddress, adapterName, subnet));
106             macAddress = null;
107             adapterName = null;
108             subnet = null;
109         } else if (qName.equals("MacAddress")) {
110             macAddress = current;
111         } else if (qName.equals("Subnet")) {
112             subnet = new Subnet(subnetLocation, subnetName);
113             subnetLocation = null;
114             subnetName = null;
115             inSubnet = false;
116         }
117      }
118      currentText = new StringBuilder();
119   }
120 
121   public void characters(char ch[], int start, int length) {
122      currentText.append(ch, start, length);
123   }
124}

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