EMMA Coverage Report (generated Fri Apr 27 15:03:37 EDT 2012)
[all classes][org.jclouds.ec2.xml]

COVERAGE SUMMARY FOR SOURCE FILE [DescribeAvailabilityZonesResponseHandler.java]

nameclass, %method, %block, %line, %
DescribeAvailabilityZonesResponseHandler.java100% (1/1)100% (6/6)88%  (143/162)90%  (33.3/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DescribeAvailabilityZonesResponseHandler100% (1/1)100% (6/6)88%  (143/162)90%  (33.3/37)
endElement (String, String, String): void 100% (1/1)84%  (97/116)83%  (18.3/22)
DescribeAvailabilityZonesResponseHandler (Supplier): void 100% (1/1)100% (20/20)100% (7/7)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Set 100% (1/1)100% (3/3)100% (1/1)
startDocument (): void 100% (1/1)100% (7/7)100% (2/2)
startElement (String, String, String, Attributes): void 100% (1/1)100% (8/8)100% (3/3)

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.ec2.xml;
20 
21import java.util.Set;
22 
23import javax.annotation.Resource;
24import javax.inject.Inject;
25 
26import org.jclouds.ec2.domain.AvailabilityZoneInfo;
27import org.jclouds.http.functions.ParseSax;
28import org.jclouds.location.Region;
29import org.jclouds.logging.Logger;
30import org.xml.sax.Attributes;
31 
32import com.google.common.base.Supplier;
33import com.google.common.collect.Sets;
34 
35/**
36 * 
37 * @author Adrian Cole
38 */
39public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> {
40   private StringBuilder currentText = new StringBuilder();
41   private final Supplier<String> defaultRegion;
42 
43   private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet();
44   private String zone;
45   @Resource
46   protected Logger logger = Logger.NULL;
47   private String region;
48   private String zoneState;
49   private boolean inMessageSet;
50   private Set<String> messages = Sets.newHashSet();
51 
52   /**
53    * Eucalyptus 1.6 doesn't return region in the XML output
54    */
55   @Inject
56   DescribeAvailabilityZonesResponseHandler(@Region Supplier<String> defaultRegion) {
57      this.defaultRegion = defaultRegion;
58   }
59 
60   @Override
61   public void startDocument() {
62      region = defaultRegion.get();
63   }
64 
65   public Set<AvailabilityZoneInfo> getResult() {
66      return availablilityZones;
67   }
68 
69   public void startElement(String uri, String name, String qName, Attributes attrs) {
70      if (qName.equals("messageSet")) {
71         inMessageSet = true;
72      }
73   }
74 
75   public void endElement(String uri, String name, String qName) {
76      if (qName.equals("zoneName")) {
77         zone = currentText.toString().trim();
78      } else if (qName.equals("regionName")) {
79         try {
80            region = currentText.toString().trim();
81         } catch (IllegalArgumentException e) {
82            logger.warn(e, "unsupported region: %s", currentText.toString().trim());
83            region = "UNKNOWN";
84         }
85      } else if (qName.equals("zoneState")) {
86         zoneState = currentText.toString().trim();
87      } else if (qName.equals("message")) {
88         messages.add(currentText.toString().trim());
89      } else if (qName.equals("messageSet")) {
90         inMessageSet = false;
91      } else if (qName.equals("item") && !inMessageSet) {
92         availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages));
93         this.zone = null;
94         this.region = defaultRegion.get();
95         this.zoneState = null;
96         this.messages = Sets.newHashSet();
97      }
98      currentText = new StringBuilder();
99   }
100 
101   public void characters(char ch[], int start, int length) {
102      currentText.append(ch, start, length);
103   }
104 
105}

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