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

COVERAGE SUMMARY FOR SOURCE FILE [NetworkConnectionHandler.java]

nameclass, %method, %block, %line, %
NetworkConnectionHandler.java100% (1/1)100% (6/6)95%  (139/146)96%  (31.8/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NetworkConnectionHandler100% (1/1)100% (6/6)95%  (139/146)96%  (31.8/33)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
endElement (String, String, String): void 100% (1/1)92%  (57/62)93%  (13/14)
NetworkConnectionHandler (): void 100% (1/1)100% (8/8)100% (2/2)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): NetworkConnection 100% (1/1)100% (41/41)100% (9/9)
startElement (String, String, String, Attributes): void 100% (1/1)100% (14/14)100% (4/4)

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;
20 
21import java.util.Map;
22 
23import org.jclouds.http.functions.ParseSax;
24import org.jclouds.util.SaxUtils;
25import org.jclouds.vcloud.domain.NetworkConnection;
26import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
27import org.xml.sax.Attributes;
28 
29/**
30 * @author Adrian Cole
31 */
32public class NetworkConnectionHandler extends ParseSax.HandlerWithResult<NetworkConnection> {
33   protected StringBuilder currentText = new StringBuilder();
34 
35   protected String network;
36   protected int networkConnectionIndex;
37   protected String ipAddress;
38   protected String externalIpAddress;
39   protected boolean connected;
40   protected String MACAddress;
41   protected IpAddressAllocationMode ipAddressAllocationMode;
42 
43   public NetworkConnection getResult() {
44      NetworkConnection connection = new NetworkConnection(network, networkConnectionIndex, ipAddress,
45               externalIpAddress, connected, MACAddress, ipAddressAllocationMode);
46      this.network = null;
47      this.networkConnectionIndex = -1;
48      this.ipAddress = null;
49      this.externalIpAddress = null;
50      this.connected = false;
51      this.MACAddress = null;
52      this.ipAddressAllocationMode = null;
53      return connection;
54   }
55 
56   public void startElement(String uri, String localName, String qName, Attributes attrs) {
57      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
58      if (qName.endsWith("NetworkConnection")) {
59         network = attributes.get("network");
60      }
61   }
62 
63   @Override
64   public void endElement(String uri, String localName, String qName) {
65      if (qName.endsWith("NetworkConnectionIndex")) {
66         this.networkConnectionIndex = Integer.parseInt(currentOrNull());
67      } else if (qName.endsWith("IpAddress")) {
68         this.ipAddress = currentOrNull();
69      } else if (qName.endsWith("ExternalIpAddress")) {
70         this.externalIpAddress = currentOrNull();
71      } else if (qName.endsWith("IsConnected")) {
72         this.connected = Boolean.parseBoolean(currentOrNull());
73      } else if (qName.endsWith("MACAddress")) {
74         this.MACAddress = currentOrNull();
75      } else if (qName.endsWith("IpAddressAllocationMode")) {
76         this.ipAddressAllocationMode = IpAddressAllocationMode.valueOf(currentOrNull());
77      }
78      currentText = new StringBuilder();
79   }
80 
81   public void characters(char ch[], int start, int length) {
82      currentText.append(ch, start, length);
83   }
84 
85   protected String currentOrNull() {
86      String returnVal = currentText.toString().trim();
87      return returnVal.equals("") ? null : returnVal;
88   }
89}

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