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

COVERAGE SUMMARY FOR SOURCE FILE [DescribeKeyPairsResponseHandler.java]

nameclass, %method, %block, %line, %
DescribeKeyPairsResponseHandler.java100% (1/1)100% (5/5)85%  (90/106)94%  (21.6/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DescribeKeyPairsResponseHandler100% (1/1)100% (5/5)85%  (90/106)94%  (21.6/23)
endElement (String, String, String): void 100% (1/1)78%  (56/72)89%  (11.6/13)
DescribeKeyPairsResponseHandler (Supplier): void 100% (1/1)100% (14/14)100% (5/5)
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% (9/9)100% (2/2)

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

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