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

COVERAGE SUMMARY FOR SOURCE FILE [DescribeAvailabilityZonesResponseHandler.java]

nameclass, %method, %block, %line, %
DescribeAvailabilityZonesResponseHandler.java100% (1/1)100% (5/5)88%  (137/156)90%  (32.3/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DescribeAvailabilityZonesResponseHandler100% (1/1)100% (5/5)88%  (137/156)90%  (32.3/36)
endElement (String, String, String): void 100% (1/1)83%  (95/114)83%  (18.3/22)
DescribeAvailabilityZonesResponseHandler (String): void 100% (1/1)100% (23/23)100% (8/8)
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)
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.collect.Sets;
33 
34/**
35 * 
36 * @author Adrian Cole
37 */
38public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> {
39   private StringBuilder currentText = new StringBuilder();
40   private final String defaultRegion;
41 
42   private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet();
43   private String zone;
44   @Resource
45   protected Logger logger = Logger.NULL;
46   private String region;
47   private String zoneState;
48   private boolean inMessageSet;
49   private Set<String> messages = Sets.newHashSet();
50 
51   /**
52    * Eucalyptus 1.6 doesn't return region in the XML output
53    */
54   @Inject
55   DescribeAvailabilityZonesResponseHandler(@Region String defaultRegion) {
56      this.defaultRegion = defaultRegion;
57      region = defaultRegion;
58   }
59 
60   public Set<AvailabilityZoneInfo> getResult() {
61      return availablilityZones;
62   }
63 
64   public void startElement(String uri, String name, String qName, Attributes attrs) {
65      if (qName.equals("messageSet")) {
66         inMessageSet = true;
67      }
68   }
69 
70   public void endElement(String uri, String name, String qName) {
71      if (qName.equals("zoneName")) {
72         zone = currentText.toString().trim();
73      } else if (qName.equals("regionName")) {
74         try {
75            region = currentText.toString().trim();
76         } catch (IllegalArgumentException e) {
77            logger.warn(e, "unsupported region: %s", currentText.toString().trim());
78            region = "UNKNOWN";
79         }
80      } else if (qName.equals("zoneState")) {
81         zoneState = currentText.toString().trim();
82      } else if (qName.equals("message")) {
83         messages.add(currentText.toString().trim());
84      } else if (qName.equals("messageSet")) {
85         inMessageSet = false;
86      } else if (qName.equals("item") && !inMessageSet) {
87         availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages));
88         this.zone = null;
89         this.region = defaultRegion;
90         this.zoneState = null;
91         this.messages = Sets.newHashSet();
92      }
93      currentText = new StringBuilder();
94   }
95 
96   public void characters(char ch[], int start, int length) {
97      currentText.append(ch, start, length);
98   }
99}

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