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

COVERAGE SUMMARY FOR SOURCE FILE [AWSDescribeInstancesResponseHandler.java]

nameclass, %method, %block, %line, %
AWSDescribeInstancesResponseHandler.java100% (1/1)100% (7/7)100% (112/112)100% (27/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSDescribeInstancesResponseHandler100% (1/1)100% (7/7)100% (112/112)100% (27/27)
AWSDescribeInstancesResponseHandler (DateService, String, Provider, TagSetHan... 100% (1/1)100% (9/9)100% (3/3)
endElement (String, String, String): void 100% (1/1)100% (36/36)100% (9/9)
endOfInstanceItem (): boolean 100% (1/1)100% (11/11)100% (1/1)
endOfReservationItem (): boolean 100% (1/1)100% (8/8)100% (1/1)
getResult (): Set 100% (1/1)100% (3/3)100% (1/1)
inItem (): void 100% (1/1)100% (31/31)100% (8/8)
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.aws.ec2.xml;
20 
21import static org.jclouds.util.SaxUtils.currentOrNull;
22import static org.jclouds.util.SaxUtils.equalsOrSuffix;
23 
24import java.util.Set;
25 
26import javax.inject.Inject;
27 
28import org.jclouds.aws.ec2.domain.AWSRunningInstance;
29import org.jclouds.date.DateService;
30import org.jclouds.ec2.domain.Reservation;
31import org.jclouds.ec2.domain.RunningInstance;
32import org.jclouds.location.Region;
33import org.xml.sax.Attributes;
34import org.xml.sax.SAXException;
35 
36import com.google.common.collect.Sets;
37import com.google.inject.Provider;
38 
39/**
40 * Parses the following XML document:
41 * <p/>
42 * DescribeImagesResponse xmlns="http:
43 * 
44 * @author Adrian Cole
45 * @see <a href="http: />
46 */
47public class AWSDescribeInstancesResponseHandler extends
48      BaseAWSReservationHandler<Set<Reservation<? extends RunningInstance>>> {
49   private Set<Reservation<? extends RunningInstance>> reservations = Sets.newLinkedHashSet();
50   private boolean inTagSet;
51   private String key;
52   private String value;
53 
54   @Inject
55   AWSDescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion,
56         Provider<AWSRunningInstance.Builder> builderProvider, TagSetHandler tagSetHandler) {
57      super(dateService, defaultRegion, builderProvider);
58   }
59 
60   @Override
61   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
62      super.startElement(uri, localName, qName, attrs);
63      if (equalsOrSuffix(qName, "tagSet")) {
64         inTagSet = true;
65      }
66   }
67 
68   @Override
69   public void endElement(String uri, String name, String qName) {
70      if (equalsOrSuffix(qName, "tagSet")) {
71         inTagSet = false;
72      } else if (inTagSet) {
73         if (equalsOrSuffix(qName, "key")) {
74            key = currentOrNull(currentText);
75         } else if (equalsOrSuffix(qName, "value")) {
76            value = currentOrNull(currentText);
77         }
78      }
79      super.endElement(uri, name, qName);
80   }
81 
82   @Override
83   public Set<Reservation<? extends RunningInstance>> getResult() {
84      return reservations;
85   }
86 
87   protected boolean endOfReservationItem() {
88      return itemDepth == 1;
89   }
90 
91   @Override
92   protected void inItem() {
93      if (endOfReservationItem()) {
94         reservations.add(super.newReservation());
95      } else if (inTagSet) {
96         builder.tag(key, value);
97         key = null;
98         value = null;
99      } else {
100         super.inItem();
101      }
102   }
103 
104   protected boolean endOfInstanceItem() {
105      return itemDepth == 2 && inInstancesSet;
106   }
107}

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