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

COVERAGE SUMMARY FOR SOURCE FILE [IpAddressesHandler.java]

nameclass, %method, %block, %line, %
IpAddressesHandler.java100% (1/1)100% (6/6)97%  (112/116)93%  (27/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IpAddressesHandler100% (1/1)100% (6/6)97%  (112/116)93%  (27/29)
startElement (String, String, String, Attributes): void 100% (1/1)69%  (9/13)60%  (3/5)
IpAddressesHandler (): void 100% (1/1)100% (14/14)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
currentOrNull (): String 100% (1/1)100% (13/13)100% (2/2)
endElement (String, String, String): void 100% (1/1)100% (65/65)100% (15/15)
getResult (): Set 100% (1/1)100% (3/3)100% (1/1)

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.trmk.vcloud_0_8.xml;
20 
21import java.util.Set;
22 
23import org.jclouds.javax.annotation.Nullable;
24import javax.annotation.Resource;
25 
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.logging.Logger;
28import org.jclouds.trmk.vcloud_0_8.domain.IpAddress;
29import org.jclouds.trmk.vcloud_0_8.domain.IpAddress.Status;
30import org.xml.sax.Attributes;
31import org.xml.sax.SAXException;
32 
33import com.google.common.collect.Sets;
34 
35/**
36 * @author Adrian Cole
37 */
38public class IpAddressesHandler extends ParseSax.HandlerWithResult<Set<IpAddress>> {
39   protected StringBuilder currentText = new StringBuilder();
40 
41   @Resource
42   protected Logger logger = Logger.NULL;
43 
44   private Set<IpAddress> addresses = Sets.newLinkedHashSet();
45   private String address;
46   private Status status;
47   @Nullable
48   private String server;
49   private boolean skip;
50 
51   public Set<IpAddress> getResult() {
52      return addresses;
53   }
54 
55   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
56      if (attributes.getIndex("xsi:nil") != -1) {
57         skip = true;
58         return;
59      } else {
60         skip = false;
61      }
62   }
63 
64   @Override
65   public void endElement(String uri, String localName, String qName) throws SAXException {
66      String current = currentOrNull();
67      if (current != null) {
68         if (qName.equals("Name")) {
69            address = current;
70         } else if (qName.equals("Status")) {
71            status = IpAddress.Status.fromValue(current);
72         } else if (!skip && qName.equals("Server")) {
73            server = current;
74         }
75      } else if (qName.equals("IpAddress")) {
76         addresses.add(new IpAddress(address, status, server));
77         address = null;
78         status = null;
79         server = null;
80      }
81      currentText = new StringBuilder();
82   }
83 
84   public void characters(char ch[], int start, int length) {
85      currentText.append(ch, start, length);
86   }
87 
88   protected String currentOrNull() {
89      String returnVal = currentText.toString().trim();
90      return returnVal.equals("") ? null : returnVal;
91   }
92 
93}

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