EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.terremark.xml]

COVERAGE SUMMARY FOR SOURCE FILE [InternetServiceHandler.java]

nameclass, %method, %block, %line, %
InternetServiceHandler.java100% (1/1)100% (6/6)100% (169/169)100% (38/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InternetServiceHandler100% (1/1)100% (6/6)100% (169/169)100% (38/38)
InternetServiceHandler (): void 100% (1/1)100% (11/11)100% (3/3)
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% (109/109)100% (27/27)
getResult (): InternetService 100% (1/1)100% (20/20)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (8/8)100% (3/3)

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.vcloud.terremark.xml;
20 
21import java.net.URI;
22 
23import javax.annotation.Resource;
24 
25import org.jclouds.http.functions.ParseSax.HandlerWithResult;
26import org.jclouds.logging.Logger;
27import org.jclouds.vcloud.terremark.domain.InternetService;
28import org.jclouds.vcloud.terremark.domain.Protocol;
29import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
30import org.xml.sax.Attributes;
31import org.xml.sax.SAXException;
32 
33/**
34 * @author Adrian Cole
35 */
36public class InternetServiceHandler extends HandlerWithResult<InternetService> {
37 
38   @Resource
39   protected Logger logger = Logger.NULL;
40   private StringBuilder currentText = new StringBuilder();
41 
42   private boolean inPublicIpAddress;
43   private URI location;
44   private URI addressLocation;
45   private String serviceName;
46   private String address;
47   private PublicIpAddress publicIpAddress;
48   private int port;
49   private String description;
50   private int timeout;
51   private boolean enabled;
52   private Protocol protocol;
53 
54   protected String currentOrNull() {
55      String returnVal = currentText.toString().trim();
56      return returnVal.equals("") ? null : returnVal;
57   }
58 
59   @Override
60   public InternetService getResult() {
61      return new InternetService(serviceName, location, publicIpAddress, port, protocol, enabled, timeout, description);
62   }
63 
64   @Override
65   public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
66      if (qName.equals("PublicIpAddress")) {
67         inPublicIpAddress = true;
68      }
69   }
70 
71   public void endElement(String uri, String name, String qName) {
72      String current = currentOrNull();
73      if (qName.equals("PublicIpAddress")) {
74         publicIpAddress = new PublicIpAddress(address, addressLocation);
75         address = null;
76         addressLocation = null;
77         inPublicIpAddress = false;
78      } else if (current != null) {
79         if (qName.equals("Href")) {
80            if (inPublicIpAddress)
81               addressLocation = URI.create(current);
82            else
83               location = URI.create(current);
84         } else if (qName.equals("Name")) {
85            if (inPublicIpAddress)
86               address = current;
87            else
88               serviceName = current;
89         } else if (qName.equals("Port")) {
90            port = Integer.parseInt(current);
91         } else if (qName.equals("Protocol")) {
92            protocol = Protocol.valueOf(current);
93         } else if (qName.equals("Enabled")) {
94            enabled = Boolean.parseBoolean(current);
95         } else if (qName.equals("Timeout")) {
96            timeout = Integer.parseInt(current);
97         } else if (qName.equals("Description")) {
98            description = current;
99         }
100      }
101      currentText = new StringBuilder();
102   }
103 
104   public void characters(char ch[], int start, int length) {
105      currentText.append(ch, start, length);
106   }
107 
108}

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