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

COVERAGE SUMMARY FOR SOURCE FILE [DescribeKeyPairsResponseHandler.java]

nameclass, %method, %block, %line, %
DescribeKeyPairsResponseHandler.java100% (1/1)100% (4/4)86%  (84/98)94%  (20.6/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DescribeKeyPairsResponseHandler100% (1/1)100% (4/4)86%  (84/98)94%  (20.6/22)
endElement (String, String, String): void 100% (1/1)79%  (54/68)89%  (11.6/13)
DescribeKeyPairsResponseHandler (String): void 100% (1/1)100% (19/19)100% (6/6)
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)

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 static org.jclouds.util.SaxUtils.currentOrNull;
22 
23import java.util.Set;
24 
25import javax.inject.Inject;
26 
27import org.jclouds.aws.util.AWSUtils;
28import org.jclouds.ec2.domain.KeyPair;
29import org.jclouds.ec2.domain.KeyPair.Builder;
30import org.jclouds.http.functions.ParseSax;
31import org.jclouds.location.Region;
32 
33import com.google.common.collect.Sets;
34 
35/**
36 * Parses: DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/"
37 * 
38 * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeKeyPairs.html"
39 *      />
40 * @author Adrian Cole
41 */
42public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<KeyPair>> {
43   private final String defaultRegion;
44   private Builder builder;
45 
46   @Inject
47   public DescribeKeyPairsResponseHandler(@Region String defaultRegion) {
48      this.defaultRegion = defaultRegion;
49      builder = KeyPair.builder().region(defaultRegion);
50   }
51 
52   private StringBuilder currentText = new StringBuilder();
53   private Set<KeyPair> keyPairs = Sets.newLinkedHashSet();
54 
55   public Set<KeyPair> getResult() {
56      return keyPairs;
57   }
58 
59   public void endElement(String uri, String name, String qName) {
60 
61      if (qName.equals("keyFingerprint")) {
62         builder.sha1OfPrivateKey(currentOrNull(currentText));
63      } else if (qName.equals("item")) {
64         String region = AWSUtils.findRegionInArgsOrNull(getRequest());
65         if (region != null)
66            builder.region(region);
67         try {
68            keyPairs.add(builder.build());
69         } finally {
70            builder = KeyPair.builder().region(defaultRegion);
71         }
72      } else if (qName.equals("keyName")) {
73         builder.keyName(currentOrNull(currentText));
74      }
75      currentText = new StringBuilder();
76   }
77 
78   public void characters(char ch[], int start, int length) {
79      currentText.append(ch, start, length);
80   }
81}

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