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

COVERAGE SUMMARY FOR SOURCE FILE [AttachmentHandler.java]

nameclass, %method, %block, %line, %
AttachmentHandler.java100% (1/1)100% (4/4)94%  (119/126)96%  (25/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AttachmentHandler100% (1/1)100% (4/4)94%  (119/126)96%  (25/26)
endElement (String, String, String): void 100% (1/1)91%  (68/75)93%  (13/14)
AttachmentHandler (DateService, Supplier): void 100% (1/1)100% (17/17)100% (6/6)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Attachment 100% (1/1)100% (26/26)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.ec2.xml;
20 
21import java.util.Date;
22 
23import javax.annotation.Resource;
24import javax.inject.Inject;
25 
26import org.jclouds.aws.util.AWSUtils;
27import org.jclouds.date.DateService;
28import org.jclouds.ec2.domain.Attachment;
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.location.Region;
31import org.jclouds.logging.Logger;
32 
33import com.google.common.base.Supplier;
34 
35/**
36 * 
37 * @author Adrian Cole
38 */
39public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> {
40 
41   @Resource
42   protected Logger logger = Logger.NULL;
43 
44   protected final DateService dateService;
45   protected final Supplier<String> defaultRegion;
46 
47   @Inject
48   AttachmentHandler(DateService dateService, @Region Supplier<String> defaultRegion) {
49      this.dateService = dateService;
50      this.defaultRegion = defaultRegion;
51   }
52 
53   private StringBuilder currentText = new StringBuilder();
54   private String volumeId;
55   private String instanceId;
56   private String device;
57   private Attachment.Status attachmentStatus;
58   private Date attachTime;
59 
60   public Attachment getResult() {
61      String region = AWSUtils.findRegionInArgsOrNull(getRequest());
62      if (region == null)
63         region = defaultRegion.get();
64      return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime);
65   }
66 
67   public void endElement(String uri, String name, String qName) {
68      if (qName.equals("volumeId")) {
69         volumeId = currentText.toString().trim();
70      } else if (qName.equals("volumeId")) {
71         volumeId = currentText.toString().trim();
72      } else if (qName.equals("status")) {
73         attachmentStatus = Attachment.Status.fromValue(currentText.toString().trim());
74      } else if (qName.equals("instanceId")) {
75         instanceId = currentText.toString().trim();
76      } else if (qName.equals("device")) {
77         device = currentText.toString().trim();
78      } else if (qName.equals("attachTime")) {
79         attachTime = dateService.iso8601DateParse(currentText.toString().trim());
80      }
81      currentText = new StringBuilder();
82   }
83 
84   public void characters(char ch[], int start, int length) {
85      currentText.append(ch, start, length);
86   }
87}

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